From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Junjie Cao <junjie.cao@intel.com>, Kees Cook <kees@kernel.org>,
Sasha Levin <sashal@kernel.org>,
keescook@chromium.org
Subject: [PATCH AUTOSEL 6.17-6.1] lkdtm: fortify: Fix potential NULL dereference on kmalloc failure
Date: Thu, 2 Oct 2025 11:30:06 -0400 [thread overview]
Message-ID: <20251002153025.2209281-19-sashal@kernel.org> (raw)
In-Reply-To: <20251002153025.2209281-1-sashal@kernel.org>
From: Junjie Cao <junjie.cao@intel.com>
[ Upstream commit 01c7344e21c2140e72282d9d16d79a61f840fc20 ]
Add missing NULL pointer checks after kmalloc() calls in
lkdtm_FORTIFY_STR_MEMBER() and lkdtm_FORTIFY_MEM_MEMBER() functions.
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
Link: https://lore.kernel.org/r/20250814060605.5264-1-junjie.cao@intel.com
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
Based on my comprehensive analysis of this commit and the lkdtm
subsystem, here is my assessment:
## **Backport Status: YES**
### Extensive Analysis:
#### 1. **Nature of the Bug**
The commit fixes potential NULL pointer dereferences in
`lkdtm_FORTIFY_STR_MEMBER()` and `lkdtm_FORTIFY_MEM_MEMBER()` functions
at **drivers/misc/lkdtm/fortify.c:46** and
**drivers/misc/lkdtm/fortify.c:111**.
Without this fix, if `kmalloc(size, GFP_KERNEL)` fails and returns NULL,
the code immediately calls:
- `strscpy(src, "over ten bytes", size)` - dereferencing NULL pointer
- `strlen(src)` - dereferencing NULL pointer again
This will cause a kernel crash when running these lkdtm tests under
memory pressure.
#### 2. **Code Changes Analysis**
The fix is minimal and defensive:
```c
src = kmalloc(size, GFP_KERNEL);
+if (!src)
+ return;
+
strscpy(src, "over ten bytes", size);
```
This pattern is consistent with existing code in the same file -
`lkdtm_FORTIFY_STRSCPY()` at line 151-154 already has this exact NULL
check pattern for `kstrdup()`.
#### 3. **Strong Historical Precedent**
I found compelling evidence that similar lkdtm NULL check fixes ARE
backported:
- **Commit 4a9800c81d2f3** ("lkdtm/bugs: Check for the NULL pointer
after calling kmalloc") from 2022 was backported to multiple stable
versions:
- linux-5.19.y
- linux-6.0.y
- linux-6.1.y
- linux-6.17.y
- **This exact commit (01c7344e21c21) has ALREADY been backported** as
commit 7309ca99f3b2a by Sasha Levin using the AUTOSEL system,
confirming automated tooling deemed it backport-worthy.
#### 4. **LKDTM Subsystem Context**
LKDTM (Linux Kernel Dump Test Module) is documented in
`Documentation/fault-injection/provoke-crashes.rst` as a critical
testing framework used to:
- Evaluate kernel exception handling reliability
- Test crash dumps from different dumping solutions
- Validate kernel hardening features (FORTIFY_SOURCE in this case)
While it's "test code," it's actively used by kernel developers and
testers on stable kernels to validate backported hardening features.
#### 5. **Backporting Criteria Assessment**
✅ **Small and contained**: Only 6 lines added across 2 functions
✅ **Fixes a real bug**: Prevents NULL dereference crashes
✅ **Minimal regression risk**: Pure defensive check, cannot break
existing functionality
✅ **Historical precedent**: Similar fixes backported
✅ **Already selected by AUTOSEL**: Strong automated signal
✅ **Consistency**: Matches existing patterns in same file
❌ **No explicit stable tag**: Commit message doesn't mention Cc: stable
⚠️ **Test code only**: Only affects developers running lkdtm tests
#### 6. **Impact and Risk**
**Impact**: Makes lkdtm fortify tests robust against memory allocation
failures, preventing test crashes that could interfere with kernel
testing and validation work on stable kernels.
**Risk**: Essentially zero - the change only adds early returns on
allocation failure, which is the correct behavior. No functional changes
to test logic when allocations succeed.
### Conclusion
This commit should be backported to stable trees. The evidence is
overwhelming:
1. Identical pattern to previously backported lkdtm NULL check fixes
2. Already selected by AUTOSEL automated backporting system
3. Fixes a clear bug with zero regression risk
4. Improves testing reliability on stable kernels
5. Small, obvious, and correct fix
The fact that this HAS already been backported by AUTOSEL (commit
7309ca99f3b2a) provides strong confirmation that this analysis aligns
with established backporting practices for the lkdtm subsystem.
drivers/misc/lkdtm/fortify.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/misc/lkdtm/fortify.c b/drivers/misc/lkdtm/fortify.c
index 0159276656780..00ed2147113e6 100644
--- a/drivers/misc/lkdtm/fortify.c
+++ b/drivers/misc/lkdtm/fortify.c
@@ -44,6 +44,9 @@ static void lkdtm_FORTIFY_STR_MEMBER(void)
char *src;
src = kmalloc(size, GFP_KERNEL);
+ if (!src)
+ return;
+
strscpy(src, "over ten bytes", size);
size = strlen(src) + 1;
@@ -109,6 +112,9 @@ static void lkdtm_FORTIFY_MEM_MEMBER(void)
char *src;
src = kmalloc(size, GFP_KERNEL);
+ if (!src)
+ return;
+
strscpy(src, "over ten bytes", size);
size = strlen(src) + 1;
--
2.51.0
next prev parent reply other threads:[~2025-10-02 15:30 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 15:29 [PATCH AUTOSEL 6.17-5.4] hfs: fix KMSAN uninit-value issue in hfs_find_set_zero_bits() Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.12] arm64: sysreg: Correct sign definitions for EIESB and DoubleLock Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-5.4] hfs: clear offset and space out of valid records in b-tree node Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-5.4] hfsplus: return EIO when type of hidden directory mismatch in hfsplus_fill_super() Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.1] powerpc/32: Remove PAGE_KERNEL_TEXT to fix startup failure Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-5.4] m68k: bitops: Fix find_*_bit() signatures Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17] smb: client: make use of ib_wc_status_msg() and skip IB_WC_WR_FLUSH_ERR logging Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.16] arm64: realm: ioremap: Allow mapping memory as encrypted Sasha Levin
2025-10-02 16:43 ` Suzuki K Poulose
2025-10-21 15:38 ` Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.12] gfs2: Fix unlikely race in gdlm_put_lock Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.1] smb: server: let smb_direct_flush_send_list() invalidate a remote key first Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-5.15] nios2: ensure that memblock.current_limit is set when setting pfn limits Sasha Levin
2025-10-02 15:29 ` [PATCH AUTOSEL 6.17-6.12] s390/mm: Use __GFP_ACCOUNT for user page table allocations Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] riscv: mm: Return intended SATP mode for noXlvl options Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] gfs2: Fix LM_FLAG_TRY* logic in add_to_queue Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] dlm: move to rinfo for all middle conversion cases Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] hfsplus: fix KMSAN uninit-value issue in hfsplus_delete_cat() Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] exec: Fix incorrect type for ret Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] hfsplus: fix KMSAN uninit-value issue in __hfsplus_ext_cache_extent() Sasha Levin
2025-10-02 15:30 ` Sasha Levin [this message]
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] riscv: mm: Use mmu-type from FDT to limit SATP mode Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.6] Unbreak 'make tools/*' for user-space targets Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] hfs: make proper initalization of struct hfs_find_data Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] hfsplus: fix slab-out-of-bounds read in hfsplus_strcasecmp() Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] riscv: cpufeature: add validation for zfa, zfh and zfhmin Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.12] PCI: Test for bit underflow in pcie_set_readrq() Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] s390/pkey: Forward keygenflags to ep11_unwrapkey Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.6] drivers/perf: hisi: Relax the event ID check in the framework Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] hfs: validate record offset in hfsplus_bmap_alloc Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17] smb: client: limit the range of info->receive_credit_target Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-5.4] dlm: check for defined force value in dlm_lockspace_release Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.12] binfmt_elf: preserve original ELF e_flags for core dumps Sasha Levin
2025-10-02 15:58 ` Kees Cook
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] arm64: errata: Apply workarounds for Neoverse-V3AE Sasha Levin
2025-10-02 15:30 ` [PATCH AUTOSEL 6.17-6.16] smb: client: queue post_recv_credits_work also if the peer raises the credit target Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251002153025.2209281-19-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=junjie.cao@intel.com \
--cc=kees@kernel.org \
--cc=keescook@chromium.org \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).