summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm
diff options
context:
space:
mode:
authorRanjitsinh Rathod <ranjitsinh.rathod@kpit.com>2021-09-08 23:15:15 +0530
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-09-11 22:39:19 +0100
commit9886ef691aa117d67e4342c6a5e3f79f6a05f8d5 (patch)
tree27c9e76350400fd95c77ea44edbb2d6d151d68c4 /meta/recipes-devtools/rpm
parent74d7d84dcb06aedd040ac77fcb577259419f2a2a (diff)
downloadpoky-9886ef691aa117d67e4342c6a5e3f79f6a05f8d5.tar.gz
rpm: Handle proper return value to avoid major issues
0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch changed to avoid critical issues Handled return values of getrlimit() and lzma_cputhreads() functions to avoid unexpected behaviours like devide by zero and potential read of uninitialized variable 'virtual_memory' Upstream-Status: Pending [merge of multithreading patches to upstream] (From OE-Core rev: 5aae9c2cb464350bc443a0f60fd6602942e61f46) Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/rpm')
-rw-r--r--meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch25
1 files changed, 14 insertions, 11 deletions
diff --git a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch
index 6454785254..dc3f74fecd 100644
--- a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch
+++ b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch
@@ -11,36 +11,39 @@ CPU thread.
11Upstream-Status: Pending [merge of multithreading patches to upstream] 11Upstream-Status: Pending [merge of multithreading patches to upstream]
12 12
13Signed-off-by: Peter Bergin <peter@berginkonsult.se> 13Signed-off-by: Peter Bergin <peter@berginkonsult.se>
14Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com>
14--- 15---
15 rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ 16 rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++
16 1 file changed, 34 insertions(+) 17 1 file changed, 36 insertions(+)
17 18
18diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c 19diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
19index e051c98..b3c56b6 100644 20index e051c98..b3c56b6 100644
20--- a/rpmio/rpmio.c 21--- a/rpmio/rpmio.c
21+++ b/rpmio/rpmio.c 22+++ b/rpmio/rpmio.c
22@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) 23@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz)
23 } 24 }
24 #endif 25 #endif
25 26
26+ struct rlimit virtual_memory; 27+ struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY};
27+ getrlimit(RLIMIT_AS, &virtual_memory); 28+ int status = getrlimit(RLIMIT_AS, &virtual_memory);
28+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { 29+ if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) {
29+ const uint64_t virtual_memlimit = virtual_memory.rlim_cur; 30+ const uint64_t virtual_memlimit = virtual_memory.rlim_cur;
31+ uint32_t threads_max = lzma_cputhreads();
30+ const uint64_t virtual_memlimit_per_cpu_thread = 32+ const uint64_t virtual_memlimit_per_cpu_thread =
31+ virtual_memlimit / lzma_cputhreads(); 33+ virtual_memlimit / ((threads_max == 0) ? 1 : threads_max);
32+ uint64_t memory_usage_virt;
33+ rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " 34+ rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and "
34+ "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); 35+ "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread);
36+ uint64_t memory_usage_virt;
35+ /* keep reducing the number of compression threads until memory 37+ /* keep reducing the number of compression threads until memory
36+ usage falls below the limit per CPU thread*/ 38+ usage falls below the limit per CPU thread*/
37+ while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > 39+ while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) >
38+ virtual_memlimit_per_cpu_thread) { 40+ virtual_memlimit_per_cpu_thread) {
39+ /* If number of threads goes down to zero lzma_stream_encoder will 41+ /* If number of threads goes down to zero or in case of any other error
40+ * will return UINT64_MAX. We must check here to avoid an infinite loop. 42+ * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check
43+ * for both the cases here to avoid an infinite loop.
41+ * If we get into situation that one thread requires more virtual memory 44+ * If we get into situation that one thread requires more virtual memory
42+ * than available we set one thread, print error message and try anyway. */ 45+ * than available we set one thread, print error message and try anyway. */
43+ if (--mt_options.threads == 0) { 46+ if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) {
44+ mt_options.threads = 1; 47+ mt_options.threads = 1;
45+ rpmlog(RPMLOG_WARNING, 48+ rpmlog(RPMLOG_WARNING,
46+ "XZ: Could not adjust number of threads to get below " 49+ "XZ: Could not adjust number of threads to get below "