diff --git a/meta/recipes-devtools/nasm/nasm/CVE-2025-8842.patch b/meta/recipes-devtools/nasm/nasm/CVE-2025-8842.patch
new file mode 100644
index 0000000000..504feff1ea
--- /dev/null
+++ b/meta/recipes-devtools/nasm/nasm/CVE-2025-8842.patch
@@ -0,0 +1,43 @@
+From b5235c49f09eeed65cdf0dfccf7f261d629c4878 Mon Sep 17 00:00:00 2001
+From: Yongjie2017 <sheng.yongjie@outlook.com>
+Date: Fri, 17 Apr 2026 06:35:57 +0800
+Subject: [PATCH] asm/preproc.c: fix
+ https://nvd.nist.gov/vuln/detail/CVE-2025-8842 When there is an ill formed
+ assembly (e.g. a macro without a correct ending), the assembly processing
+ will end with a defining->refcnt in non-zero value that further causes a
+ nasm_assert in free_mmacro, the nasm_assert causes a panic.
+
+Force the defining->refcnt to zero in pp_clean_pass as a bailout.
+
+Signed-off-by: Yongjie Sheng (Intel) <sheng.yongjie@outlook.com>
+
+CVE: CVE-2025-8842
+
+Upstream-Status: Backport [https://github.com/netwide-assembler/nasm/commit/b5235c49f0]
+
+Signed-off-by: Guocai He <guocai.he.cn@windriver.com>
+Signed-off-by: Josiah Metz <Josiah.Metz@windriver.com>
+---
+ asm/preproc.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/asm/preproc.c b/asm/preproc.c
+index e169d1a5..776a5223 100644
+--- a/asm/preproc.c
++++ b/asm/preproc.c
+@@ -8837,6 +8837,15 @@ void pp_cleanup_pass(void)
+             nasm_nonfatal("end of file while still in %%rep");
+         }
+ 
++        if (defining->refcnt != 0)
++        {
++            /* This can happen if a macro is ill formed without a correct ending
++             * and the macro is still referenced.
++             * In this case, we just set the refcnt to 0 to avoid a memory leak.
++             */
++            defining->refcnt = 0;
++        }
++
+         free_mmacro(defining);
+         defining = NULL;
+     }
diff --git a/meta/recipes-devtools/nasm/nasm_3.01.bb b/meta/recipes-devtools/nasm/nasm_3.01.bb
index 186ae57ce4..8448d48992 100644
--- a/meta/recipes-devtools/nasm/nasm_3.01.bb
+++ b/meta/recipes-devtools/nasm/nasm_3.01.bb
@@ -13,6 +13,7 @@ SRC_URI = "http://www.nasm.us/pub/nasm/releasebuilds/${PV}/nasm-${PV}.tar.bz2 \
            file://CVE-2026-6068-1.patch \
            file://CVE-2026-6068-2.patch \
            file://CVE-2026-6068-3.patch \
+           file://CVE-2025-8842.patch \
            "
 
 SRC_URI[sha256sum] = "7a7b1ff3b0eef3247862f2fbe4ca605ccef770545d7af7979eba84a9d045c0b1"
