diff --git a/backport-preproc-fix-heap-memory-overflow-CVE-2023-31722.patch b/backport-preproc-fix-heap-memory-overflow-CVE-2023-31722.patch new file mode 100644 index 0000000000000000000000000000000000000000..1c3b63f27be02dd826e607026e87896328a2f96d --- /dev/null +++ b/backport-preproc-fix-heap-memory-overflow-CVE-2023-31722.patch @@ -0,0 +1,49 @@ +From e39b856bdeec852e9b078dd9b7cad74caee618b4 Mon Sep 17 00:00:00 2001 +From: hongjinghao +Date: Tue, 5 Sep 2023 20:28:26 +0800 +Subject: [PATCH] preproc: fix heap memory overflow CVE-2023-31722 + +paramlen has heap memory of length nparam+1. The value of variable i +may be greater than nparam+1, causing heap memory overflow. Therefore, +i and nparam+1 needs to be determined in the loop. + +Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392857#c1 +Fixes: https://github.com/netwide-assembler/nasm/pull/83 +Signed-off-by: H. Peter Anvin (Intel) +--- + asm/preproc.c | 2 +- + nasmlib/alloc.c | 4 +++- + 2 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/asm/preproc.c b/asm/preproc.c +index 22b7f72f..c82b570c 100644 +--- a/asm/preproc.c ++++ b/asm/preproc.c +@@ -7245,7 +7245,7 @@ static int expand_mmacro(Token * tline) + */ + nasm_newn(paramlen, nparam+1); + +- for (i = 1; (t = params[i]); i++) { ++ for (i = 1; i < nparam+1 && (t = params[i]); i++) { + bool braced = false; + int brace = 0; + int white = 0; +diff --git a/nasmlib/alloc.c b/nasmlib/alloc.c +index 32e181e7..b77d4821 100644 +--- a/nasmlib/alloc.c ++++ b/nasmlib/alloc.c +@@ -74,8 +74,10 @@ void *nasm_realloc(void *q, size_t size) + + void nasm_free(void *q) + { +- if (q) ++ if (q){ + free(q); ++ q = NULL; ++ } + } + + char *nasm_strdup(const char *s) +-- +2.43.0 + diff --git a/nasm.spec b/nasm.spec index 9d4c50142d1e0bb5f48d54e28dcf331e34b3a63b..2583ecd15982173e3b68a24871fd013fda121f53 100644 --- a/nasm.spec +++ b/nasm.spec @@ -8,7 +8,7 @@ Name: nasm Version: 2.15.05 -Release: 7 +Release: 8 Summary: The Netwide Assembler, a portable x86 assembler with Intel-like syntax License: BSD URL: http://www.nasm.us @@ -24,6 +24,8 @@ Patch6002: CVE-2022-44370.patch Patch6003: CVE-2020-21528.patch Patch6004: CVE-2023-38665.patch +Patch6005: backport-preproc-fix-heap-memory-overflow-CVE-2023-31722.patch + BuildRequires: perl(Env) autoconf asciidoc xmlto gcc make git Provides: %{name}-rdoff @@ -95,6 +97,9 @@ make test %{_mandir}/man1/ld* %changelog +* Wed Nov 05 2025 Linux_zhang - 2.15.05-8 +- Fix CVE-2023-31722 + * Sat Oct 26 2024 liningjie - 2.15.05-7 - Fix CVE-2023-38665