rpm: Handle proper return value to avoid major issues and removing unnecessary code
PATCH 1/1 rpm: Handle proper return value to avoid major issues and removing unnecessary code
From: Ranjitsinh Rathod <[email protected]>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch 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]
2) CVE-2021-3421.patch
Removed RPMSIGTAG_FILESIGNATURES and RPMSIGTAG_FILESIGNATURELENGTH as
it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21]
--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +14 -11
@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) +@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) } #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY}; ++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) { + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; ++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ? 1 : threads_max); + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); ++ uint64_t memory_usage_virt; + /* keep reducing the number of compression threads until memory + usage falls below the limit per CPU thread*/ + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > + virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down to zero lzma_stream_encoder will -+ * will return UINT64_MAX. We must check here to avoid an infinite loop. ++ /* If number of threads goes down to zero or in case of any other error ++ * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check ++ * for both the cases here to avoid an infinite loop. + * If we get into situation that one thread requires more virtual memory + * than available we set one thread, print error message and try anyway. */ -+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) { + mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjust number of threads to get below "
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +5 -27
@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21] CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"
@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete, dont use */ + { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },
@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)
@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e { - RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internal Header+Payload size (64bit) in bytes. */ - RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internal uncompressed payload size (64bit) in bytes. */ - RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1
Signature · 1 line
2.17.1
Can someone please check this and confirm if this can go on dunfell?
Quoted 10 lines · Ranjitsinh Rathod
From: Ranjitsinh Rathod <[email protected]>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch Handled return values ofgetrlimit()andlzma_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]
Quoted 4 lines
2) CVE-2021-3421.patch
RemovedRPMSIGTAG_FILESIGNATURESandRPMSIGTAG_FILESIGNATURELENGTHas
it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21]
Minjae, can you review this since he is modifying your CVE patch?
Thanks!
Steve
Quoted 137 lines
Signed-off-by Ranjitsinh Rathod <[email protected]>--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +14
-11@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) +@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) } #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY}; ++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) { + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; ++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ? 1 : threads_max); + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); ++ uint64_t memory_usage_virt; + /* keep reducing the number of compression threads until memory + usage falls below the limit per CPU thread*/ + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > + virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down to zero lzma_stream_encoder will -+ * will return UINT64_MAX. We must check here to avoid an infinite loop. ++ /* If number of threads goes down to zero or in case of any other error ++ * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check ++ * for both the cases here to avoid an infinite loop. + * If we get into situation that one thread requires more virtual memory + * than available we set one thread, print error message and try anyway. */ -+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) { + mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjust number of threads to get below "meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +5
-28@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21] CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete, dont use */ + { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e { - RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internal Header+Payload size (64bit) in bytes. */ - RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internal uncompressed payload size (64bit) in bytes. */ - RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1 --2.17.1
Quoted 2 lines · Steve Sakoman
RPMSIGTAG_FILESIGNATURELENGTH
Hi, Steve and Ranjitsinh,
Sorry for the late response.
I know that the RPMSIGTAG_FILESIGNATURES and RPMSIGTAG_FILESIGNATURELENGTH are defined in the original commit, but are not used. I left it with the author`s intent. If the build goes well without those variables, it doesn't seem to matter.
Thanks,
Minjae Kim.
Quoted 9 lines · Ranjitsinh Rathod
From: Ranjitsinh Rathod <[email protected]>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch Handled return values ofgetrlimit()andlzma_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]
This does look like a good fix. Are these changes to the patch from upstream?
Once upstream has accepted the change we should change the status from "pending", but for now this is ok.
Quoted 4 lines
2) CVE-2021-3421.patch
RemovedRPMSIGTAG_FILESIGNATURESandRPMSIGTAG_FILESIGNATURELENGTHas
it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21]
Removing these unused definitions doesn't really seem like a critical issue. I'd prefer to leave the CVE patch in its original form.
Could you submit a V2 with this change?
Thanks!
Steve
Quoted 137 lines
Signed-off-by Ranjitsinh Rathod <[email protected]>--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +14
-11@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) +@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) } #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY}; ++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) { + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; ++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ? 1 : threads_max); + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); ++ uint64_t memory_usage_virt; + /* keep reducing the number of compression threads until memory + usage falls below the limit per CPU thread*/ + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > + virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down to zero lzma_stream_encoder will -+ * will return UINT64_MAX. We must check here to avoid an infinite loop. ++ /* If number of threads goes down to zero or in case of any other error ++ * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check ++ * for both the cases here to avoid an infinite loop. + * If we get into situation that one thread requires more virtual memory + * than available we set one thread, print error message and try anyway. */ -+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) { + mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjust number of threads to get below "meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +5
-28@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21] CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete, dont use */ + { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e { - RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internal Header+Payload size (64bit) in bytes. */ - RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internal uncompressed payload size (64bit) in bytes. */ - RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1 --2.17.1
At this point I have to note that I am removing the patch altogether with the upcoming upgrade of rpm to 4.17, as I'm also switching the compression format to zstd, and the patch is generally difficult to maintain and rebase. If you care about xz compression, please do work with upstream to get it merged there.
Alex
Quoted 204 lines · Steve Sakoman
Quoted 9 lines · Ranjitsinh Rathod
From: Ranjitsinh Rathod <[email protected]>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch Handled return values ofgetrlimit()andlzma_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]This does look like a good fix. Are these changes to the patch from upstream?
Once upstream has accepted the change we should change the status from "pending", but for now this is ok.
Quoted 4 lines
2) CVE-2021-3421.patch
RemovedRPMSIGTAG_FILESIGNATURESandRPMSIGTAG_FILESIGNATURELENGTHas it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21
]Removing these unused definitions doesn't really seem like a critical issue. I'd prefer to leave the CVE patch in its original form.
Could you submit a V2 with this change?
Thanks!
Steve
Quoted 7 lines
Signed-off-by Ranjitsinh Rathod <[email protected]>--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)diff --git
a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchb/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 2 lines
index 6454785254..dc3f74fecd 100644
---
a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 1 line
+++
b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 6 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +1
-0@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> ---meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread. · line 22
Quoted 10 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +2
-3- rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode,int fd, int xz)
Review CPU thread. · line 23
Quoted 1 line
(quoted diff) +1
-0+@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode,int fd, int xz)
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 7 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +1
-3} #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY ,
RLIM_INFINITY};Review CPU thread. · line 29
Quoted 2 lines
(quoted diff) +2
-0++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur !=
RLIM_INFINITY)) {Review CPU thread. · line 30
Quoted 1 line
(quoted diff) +0
-0+ const uint64_t virtual_memlimit =virtual_memory.rlim_cur;
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 5 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +2
-2++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ?1 :
threads_max);Review CPU thread. · line 34
Quoted 1 line
(quoted diff) +0
-0+ rpmlog(RPMLOG_NOTICE, "XZ: virtual memoryrestricted to %lu and "
Review CPU thread. · line 35
Quoted 1 line
(quoted diff) +0
-0+ "per CPU thread %lu\n", virtual_memlimit,
virtual_memlimit_per_cpu_thread);Review CPU thread. · line 37
Quoted 2 lines
(quoted diff) +1
-0++ uint64_t memory_usage_virt; + /* keep reducing the number of compressionthreads until memory
Review CPU thread. · line 39
Quoted 2 lines
(quoted diff) +0
-0+ usage falls below the limit per CPU thread*/ + while ((memory_usage_virt =
lzma_stream_encoder_mt_memusage(&mt_options)) >Review CPU thread. · line 39
Quoted 2 lines
(quoted diff) +0
-1+ virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down tozero
lzma_stream_encoderwillReview CPU thread. · line 40
Quoted 1 line
(quoted diff) +0
-1-+ * will return UINT64_MAX. We must checkhere to avoid an infinite loop.
Review CPU thread. · line 41
Quoted 1 line
(quoted diff) +1
-0++ /* If number of threads goes down tozero or in case of any other error
Review CPU thread. · line 42
Quoted 1 line
(quoted diff) +1
-0++ * lzma_stream_encoder_mt_memusage willreturn
UINT64_MAX. We must checkReview CPU thread. · line 43
Quoted 1 line
(quoted diff) +1
-0++ * for both the cases here to avoid aninfinite loop.
Review CPU thread. · line 44
Quoted 1 line
(quoted diff) +0
-0+ * If we get into situation that onethread requires more virtual memory
Review CPU thread. · line 45
Quoted 1 line
(quoted diff) +0
-0+ * than available we set one thread,print error message and try anyway. */
Review CPU thread. · line 46
Quoted 2 lines
(quoted diff) +1
-1-+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) ||(
memory_usage_virt==UINT64_MAX)) {meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 3 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +0
-0+ mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjustnumber of threads to get below "
Review
Quoted 1 line
(quoted diff) +0
-0
b/meta/recipes-devtools/rpm/files/CVE-2021-3421.patchmeta/recipes-devtools/rpm/files/CVE-2021-3421.patch Fixes: CVE-2021-3421, CVE-2021-20271 · line 22
Quoted 5 lines
index
b1a05b6863..d2ad5eabac100644meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-0@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21
]Quoted 20 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +4
-4CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 47
Quoted 2 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-0@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete,dont use */
Quoted 23 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +1
-7+ { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e {meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 187
Quoted 10 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-10- RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internalHeader+Payload size (64bit) in bytes. */
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 188
Quoted 1 line
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-1- RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internaluncompressed payload size (64bit) in bytes. */
Quoted 14 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-6- RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1 --2.17.1
Hi Steve,
If you wanted to take changes only for the 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch then you can cherry-pick it from master as I have submitted it for master and it is available on master branch now. Below is the link. poky - Poky Build Tool and Metadata (yoctoproject.org)<https://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=9886ef691aa117d67e4342c6a5e3f79f6a05f8d5>
Do you still want me to send v2 patch here?
Thanks,
Best Regards,
Ranjitsinh Rathod
Technical Leader | | KPIT Technologies Ltd.
Cellphone: +91-84606 92403
__________________________________________
KPIT<http://www.kpit.com/> | Follow us on LinkedIn<http://www.kpit.com/linkedin>
[cid:05fb0115-01bd-4421-ae2f-587c78415386]<https://www.kpit.com/TheNewBrand>
________________________________
From: [email protected] <[email protected]> on behalf of Alexander Kanavin via lists.openembedded.org <[email protected]>
Sent: Wednesday, September 15, 2021 8:36 PM
To: Steve Sakoman <[email protected]>
Cc: Ranjitsinh Rathod <[email protected]>; Patches and discussions about the oe-core layer <[email protected]>; Ranjitsinh Rathod <[email protected]>
Subject: Re: [OE-core] [meta][dunfell][PATCH] rpm: Handle proper return value to avoid major issues and removing unnecessary code
Caution: This email originated from outside of the KPIT. Do not click links or open attachments unless you recognize the sender and know the content is safe.
At this point I have to note that I am removing the patch altogether with the upcoming upgrade of rpm to 4.17, as I'm also switching the compression format to zstd, and the patch is generally difficult to maintain and rebase. If you care about xz compression, please do work with upstream to get it merged there.
Alex
On Wed, 15 Sept 2021 at 16:59, Steve Sakoman <[email protected]<mailto:[email protected]>> wrote:
Quoted 9 lines · On Wed, Sep 8, 2021 at 4:02 AM Ranjitsinh Rathod…
From: Ranjitsinh Rathod <[email protected]<mailto:[email protected]>>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch Handled return values ofgetrlimit()andlzma_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]
This does look like a good fix. Are these changes to the patch from upstream?
Once upstream has accepted the change we should change the status from "pending", but for now this is ok.
Quoted 4 lines
2) CVE-2021-3421.patch
RemovedRPMSIGTAG_FILESIGNATURESandRPMSIGTAG_FILESIGNATURELENGTHas
it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21<https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frpm-software-management%2Frpm%2Fcommit%2Fd6a86b5e69e46cc283b1e06c92343319beb42e21&data=04%7C01%7Cranjitsinh.rathod%40kpit.com%7Cdfd54731b1a240ea64ed08d9785a7618%7C3539451eb46e4a26a242ff61502855c7%7C0%7C0%7C637673152237746428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BFoFI3j9RjhqXQi1tSqfoVoS2strOChMcswosTH59Fs%3D&reserved=0>]
Removing these unused definitions doesn't really seem like a critical issue. I'd prefer to leave the CVE patch in its original form.
Could you submit a V2 with this change?
Thanks!
Steve
Quoted 132 lines
--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +14
-11@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]<mailto:[email protected]>> +Signed-off-by: Ranjitsinh Rathod <[email protected]<mailto:[email protected]>> --- - rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) +@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode, int fd, int xz) } #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY , RLIM_INFINITY}; ++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur != RLIM_INFINITY)) { + const uint64_t virtual_memlimit = virtual_memory.rlim_cur; ++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ? 1 : threads_max); + rpmlog(RPMLOG_NOTICE, "XZ: virtual memory restricted to %lu and " + "per CPU thread %lu\n", virtual_memlimit, virtual_memlimit_per_cpu_thread); ++ uint64_t memory_usage_virt; + /* keep reducing the number of compression threads until memory + usage falls below the limit per CPU thread*/ + while ((memory_usage_virt = lzma_stream_encoder_mt_memusage(&mt_options)) > + virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down to zero lzma_stream_encoder will -+ * will return UINT64_MAX. We must check here to avoid an infinite loop. ++ /* If number of threads goes down to zero or in case of any other error ++ * lzma_stream_encoder_mt_memusage will return UINT64_MAX. We must check ++ * for both the cases here to avoid an infinite loop. + * If we get into situation that one thread requires more virtual memory + * than available we set one thread, print error message and try anyway. */ -+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) || (memory_usage_virt == UINT64_MAX)) { + mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjust number of threads to get below "meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +5
-28@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21<https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frpm-software-management%2Frpm%2Fcommit%2Fd6a86b5e69e46cc283b1e06c92343319beb42e21&data=04%7C01%7Cranjitsinh.rathod%40kpit.com%7Cdfd54731b1a240ea64ed08d9785a7618%7C3539451eb46e4a26a242ff61502855c7%7C0%7C0%7C637673152237746428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BFoFI3j9RjhqXQi1tSqfoVoS2strOChMcswosTH59Fs%3D&reserved=0>] CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]<mailto:[email protected]>> +Signed-off-by: Ranjitsinh Rathod <[email protected]<mailto:[email protected]>> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete, dont use */ + { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e { - RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internal Header+Payload size (64bit) in bytes. */ - RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internal uncompressed payload size (64bit) in bytes. */ - RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1 --
Quoted 5 lines
2.17.1
This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.
Quoted 10 lines · Ranjitsinh Rathod
Hi Steve,
If you wanted to take changes only for the 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch then you can cherry-pick it from master as I have submitted it for master
and it is available on master branch now. Below is the link.
poky - Poky Build Tool and Metadata (yoctoproject.org)
<https://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=9886ef691aa117d67e4342c6a5e3f79f6a05f8d5>Do you still want me to send v2 patch here?
No need, I'll cherry-pick the patch from master.
Thanks!
Steve
Quoted 253 lines
Thanks,
Best Regards,
*Ranjitsinh Rathod*
Technical Leader | | KPIT Technologies Ltd.
Cellphone: +91-84606 92403*__________________________________________ *KPIT <http://www.kpit.com/> |
Follow us on LinkedIn <http://www.kpit.com/linkedin><https://www.kpit.com/TheNewBrand>
------------------------------
*From:* [email protected] < [email protected]> on behalf of Alexander Kanavin via lists.openembedded.org <[email protected]> *Sent:* Wednesday, September 15, 2021 8:36 PM
*To:* Steve Sakoman <[email protected]>
*Cc:* Ranjitsinh Rathod <[email protected]>; Patches and discussions about the oe-core layer < [email protected]>; Ranjitsinh Rathod < [email protected]>
*Subject:* Re: [OE-core] [meta][dunfell][PATCH] rpm: Handle proper return value to avoid major issues and removing unnecessary codeCaution: This email originated from outside of the KPIT. Do not click links or open attachments unless you recognize the sender and know the content is safe.
At this point I have to note that I am removing the patch altogether with the upcoming upgrade of rpm to 4.17, as I'm also switching the compression format to zstd, and the patch is generally difficult to maintain and rebase. If you care about xz compression, please do work with upstream to get it merged there.Alex
On Wed, 15 Sept 2021 at 16:59, Steve Sakoman <[email protected]> wrote:
Quoted 9 lines · Ranjitsinh Rathod
From: Ranjitsinh Rathod <[email protected]>
Change in 2 patch as below to avoid critical issues
1) 0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch Handled return values ofgetrlimit()andlzma_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]This does look like a good fix. Are these changes to the patch from upstream?
Once upstream has accepted the change we should change the status from "pending", but for now this is ok.
Quoted 4 lines
2) CVE-2021-3421.patch
RemovedRPMSIGTAG_FILESIGNATURESandRPMSIGTAG_FILESIGNATURELENGTHas it is not needed during backporting of original patch.
Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21
<https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frpm-software-management%2Frpm%2Fcommit%2Fd6a86b5e69e46cc283b1e06c92343319beb42e21&data=04%7C01%7Cranjitsinh.rathod%40kpit.com%7Cdfd54731b1a240ea64ed08d9785a7618%7C3539451eb46e4a26a242ff61502855c7%7C0%7C0%7C637673152237746428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BFoFI3j9RjhqXQi1tSqfoVoS2strOChMcswosTH59Fs%3D&reserved=0>
]Removing these unused definitions doesn't really seem like a critical issue. I'd prefer to leave the CVE patch in its original form.
Could you submit a V2 with this change?
Thanks!
Steve
Quoted 7 lines
Signed-off-by Ranjitsinh Rathod <[email protected]>--- ...rict-virtual-memory-usage-if-limit-s.patch | 25 ++++++++------- .../rpm/files/CVE-2021-3421.patch | 32 +++---------------- 2 files changed, 19 insertions(+), 38 deletions(-)diff --git
a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchb/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 2 lines
index 6454785254..dc3f74fecd 100644
---
a/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 1 line
+++
b/meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patchQuoted 6 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +1
-0@@ -11,36 +11,39 @@ CPU thread. Upstream-Status: Pending [merge of multithreading patches to upstream] Signed-off-by: Peter Bergin <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> ---meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread. · line 22
Quoted 10 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +2
-3- rpmio/rpmio.c | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) + rpmio/rpmio.c | 36 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index e051c98..b3c56b6 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c -@@ -845,6 +845,40 @@ static LZFILE *lzopen_internal(const char *mode,int fd, int xz)
Review CPU thread. · line 23
Quoted 1 line
(quoted diff) +1
-0+@@ -845,6 +845,42 @@ static LZFILE *lzopen_internal(const char *mode,int fd, int xz)
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 7 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +1
-3} #endif -+ struct rlimit virtual_memory; -+ getrlimit(RLIMIT_AS, &virtual_memory); -+ if (virtual_memory.rlim_cur != RLIM_INFINITY) { ++ struct rlimit virtual_memory = {RLIM_INFINITY ,
RLIM_INFINITY};Review CPU thread. · line 29
Quoted 2 lines
(quoted diff) +2
-0++ int status = getrlimit(RLIMIT_AS, &virtual_memory); ++ if ((status != -1) && (virtual_memory.rlim_cur !=
RLIM_INFINITY)) {Review CPU thread. · line 30
Quoted 1 line
(quoted diff) +0
-0+ const uint64_t virtual_memlimit =virtual_memory.rlim_cur;
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 5 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +2
-2++ uint32_t threads_max = lzma_cputhreads(); + const uint64_t virtual_memlimit_per_cpu_thread = -+ virtual_memlimit / lzma_cputhreads(); -+ uint64_t memory_usage_virt; ++ virtual_memlimit / ((threads_max == 0) ?1 :
threads_max);Review CPU thread. · line 34
Quoted 1 line
(quoted diff) +0
-0+ rpmlog(RPMLOG_NOTICE, "XZ: virtual memoryrestricted to %lu and "
Review CPU thread. · line 35
Quoted 1 line
(quoted diff) +0
-0+ "per CPU thread %lu\n", virtual_memlimit,
virtual_memlimit_per_cpu_thread);Review CPU thread. · line 37
Quoted 2 lines
(quoted diff) +1
-0++ uint64_t memory_usage_virt; + /* keep reducing the number of compressionthreads until memory
Review CPU thread. · line 39
Quoted 2 lines
(quoted diff) +0
-0+ usage falls below the limit per CPU thread*/ + while ((memory_usage_virt =
lzma_stream_encoder_mt_memusage(&mt_options)) >Review CPU thread. · line 39
Quoted 2 lines
(quoted diff) +0
-1+ virtual_memlimit_per_cpu_thread) { -+ /* If number of threads goes down tozero
lzma_stream_encoderwillReview CPU thread. · line 40
Quoted 1 line
(quoted diff) +0
-1-+ * will return UINT64_MAX. We must checkhere to avoid an infinite loop.
Review CPU thread. · line 41
Quoted 1 line
(quoted diff) +1
-0++ /* If number of threads goes down tozero or in case of any other error
Review CPU thread. · line 42
Quoted 1 line
(quoted diff) +1
-0++ * lzma_stream_encoder_mt_memusage willreturn
UINT64_MAX. We must checkReview CPU thread. · line 43
Quoted 1 line
(quoted diff) +1
-0++ * for both the cases here to avoid aninfinite loop.
Review CPU thread. · line 44
Quoted 1 line
(quoted diff) +0
-0+ * If we get into situation that onethread requires more virtual memory
Review CPU thread. · line 45
Quoted 1 line
(quoted diff) +0
-0+ * than available we set one thread,print error message and try anyway. */
Review CPU thread. · line 46
Quoted 2 lines
(quoted diff) +1
-1-+ if (--mt_options.threads == 0) { ++ if ((--mt_options.threads == 0) ||(
memory_usage_virt==UINT64_MAX)) {meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch CPU thread.
Quoted 3 lines
meta/recipes-devtools/rpm/files/0001-rpm-rpmio.c-restrict-virtual-memory-usage-if-limit-s.patch +0
-0+ mt_options.threads = 1; + rpmlog(RPMLOG_WARNING, + "XZ: Could not adjustnumber of threads to get below "
Review
Quoted 1 line
(quoted diff) +0
-0
b/meta/recipes-devtools/rpm/files/CVE-2021-3421.patchmeta/recipes-devtools/rpm/files/CVE-2021-3421.patch Fixes: CVE-2021-3421, CVE-2021-20271 · line 22
Quoted 5 lines
index
b1a05b6863..d2ad5eabac100644meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-0@@ -22,16 +22,16 @@ Fixes: CVE-2021-3421, CVE-2021-20271 Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/d6a86b5e69e46cc283b1e06c92343319beb42e21
<https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frpm-software-management%2Frpm%2Fcommit%2Fd6a86b5e69e46cc283b1e06c92343319beb42e21&data=04%7C01%7Cranjitsinh.rathod%40kpit.com%7Cdfd54731b1a240ea64ed08d9785a7618%7C3539451eb46e4a26a242ff61502855c7%7C0%7C0%7C637673152237746428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=BFoFI3j9RjhqXQi1tSqfoVoS2strOChMcswosTH59Fs%3D&reserved=0>
]Quoted 20 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +4
-4CVE: CVE-2021-3421 Signed-off-by: Minjae Kim <[email protected]> +Signed-off-by: Ranjitsinh Rathod <[email protected]> --- - lib/package.c | 115 ++++++++++++++++++++++++-------------------------- - lib/rpmtag.h | 4 ++ - 2 files changed, 58 insertions(+), 61 deletions(-) + lib/package.c | 113 ++++++++++++++++++++++++-------------------------- + 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/package.c b/lib/package.c index 081123d84e..7c26ea323f 100644 --- a/lib/package.c +++ b/lib/package.c -@@ -20,76 +20,68 @@ +@@ -20,76 +20,67 @@ #include "debug.h"meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 47
Quoted 2 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-0@@ -46,8 +46,6 @@ index 081123d84e..7c26ea323f 100644 + { RPMSIGTAG_GPG, RPMTAG_SIGGPG, 0 }, + /* { RPMSIGTAG_PGP5, RPMTAG_SIGPGP5, 0 }, */ /* long obsolete,dont use */
Quoted 23 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +1
-7+ { RPMSIGTAG_PAYLOADSIZE, RPMTAG_ARCHIVESIZE, 1 }, -+ { RPMSIGTAG_FILESIGNATURES, RPMTAG_FILESIGNATURES, 0 }, -+ { RPMSIGTAG_FILESIGNATURELENGTH, RPMTAG_FILESIGNATURELENGTH, 1 }, + { RPMSIGTAG_SHA1, RPMTAG_SHA1HEADER, 1 }, + { RPMSIGTAG_SHA256, RPMTAG_SHA256HEADER, 1 }, + { RPMSIGTAG_DSA, RPMTAG_DSAHEADER, 0 },@@ -61,6 +59,7 @@ index 081123d84e..7c26ea323f 100644 * Translate and merge legacy signature tags into header. * @param h header (dest) * @param sigh signature header (src) ++ * @return failing tag number, 0 on success */ static -void headerMergeLegacySigs(Header h, Header sigh)@@ -170,27 +169,6 @@ index 081123d84e..7c26ea323f 100644 applyRetrofits(h); /* Bump reference count for return. */ -diff --git a/lib/rpmtag.h b/lib/rpmtag.h -index 8c718b31b5..d562572c6f 100644 ---- a/lib/rpmtag.h -+++ b/lib/rpmtag.h -@@ -65,6 +65,8 @@ typedef enum rpmTag_e {meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 187
Quoted 10 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-10- RPMTAG_LONGARCHIVESIZE = RPMTAG_SIG_BASE+15, /* l */ - /* RPMTAG_SIG_BASE+16 reserved */ - RPMTAG_SHA256HEADER = RPMTAG_SIG_BASE+17, /* s */ -+ /* RPMTAG_SIG_BASE+18 reserved for RPMSIGTAG_FILESIGNATURES */ -+ /* RPMTAG_SIG_BASE+19 reserved for RPMSIGTAG_FILESIGNATURELENGTH */ - - RPMTAG_NAME = 1000, /* s */ - #define RPMTAG_N RPMTAG_NAME /* s */ -@@ -422,6 +424,8 @@ typedef enum rpmSigTag_e { - RPMSIGTAG_LONGSIZE = RPMTAG_LONGSIGSIZE, /*!< internalHeader+Payload size (64bit) in bytes. */
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch index 081123d84e..7c26ea323f 100644 · line 188
Quoted 1 line
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-1- RPMSIGTAG_LONGARCHIVESIZE = RPMTAG_LONGARCHIVESIZE, /*!< internaluncompressed payload size (64bit) in bytes. */
Quoted 9 lines
meta/recipes-devtools/rpm/files/CVE-2021-3421.patch +0
-6- RPMSIGTAG_SHA256 = RPMTAG_SHA256HEADER, -+ RPMSIGTAG_FILESIGNATURES = RPMTAG_SIG_BASE + 18, -+ RPMSIGTAG_FILESIGNATURELENGTH = RPMTAG_SIG_BASE + 19, - } rpmSigTag; - -- 2.17.1 --Quoted 5 lines
2.17.1
This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.