v3
2026-09-04
slab: ZERO_SIZE_PTR alignment and ERR_PTR hardening · v3
kmalloc 零尺寸返回值对齐到 ARCH_KMALLOC_MINALIGN,ZERO_OR_NULL_PTR 只管 NULL/ZERO_SIZE_PTR,kfree 显式处理 ERR_PTR 并加测试。
原始补丁链接
子 Patch(5)
1/5
slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN
The kmalloc entry points are annotated with __assume_kmalloc_alignment but return ZERO_SIZE_PTR, currently (void *)16, for zero-size requests. This violates the annotation when ARCH_KMALLOC_MINALIGN e
2/5
slab: check for ZERO_SIZE_PTR by exact match
ZERO_OR_NULL_PTR() returns true for every value less than or equal to ZERO_SIZE_PTR. With the sentinel raised to ARCH_KMALLOC_MINALIGN, up to 128 on some architectures, the helper matches additional v
3/5
slab: handle ERR_PTR values in kfree and hardened usercopy
Passing an ERR_PTR to kfree() currently reaches virt_to_page() and may fault. Warn and return instead, leaving the bad caller visible without using the pointer as allocator metadata. Also reject ERR_
4/5
slab: test zero-size allocations in slub_kunit
Add KUnit coverage for the zero-size allocation contract, including ZERO_SIZE_PTR alignment and exact ZERO_OR_NULL_PTR() matching. Assisted-by: LLM Signed-off-by: Karl Mehltretter <kmehltretter@gmail
5/5
slab: test ERR_PTR handling in kfree and hardened usercopy
Add KUnit coverage that kfree() warns and returns for ERR_PTR values while remaining silent for NULL and ZERO_SIZE_PTR. Add an LKDTM test that verifies hardened usercopy rejects an ERR_PTR before att