From: Karl Mehltretter <kmehltretter@gmail.com>
To: Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Catalin Marinas <catalin.marinas@arm.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH v2 0/3] slab: ZERO_SIZE_PTR alignment and exact matching
Date: Tue, 11 Aug 2026 16:12:37 +0200 [thread overview]
Message-ID: <20260811141240.62519-1-kmehltretter@gmail.com> (raw)
The kmalloc entry points promise ARCH_KMALLOC_MINALIGN alignment but
return (void *)16 for zero-size requests. Patch 1 aligns the sentinel
to that promise. Patch 2 makes ZERO_OR_NULL_PTR() match only NULL and
the sentinel, so increasing the sentinel does not widen the set it
matches. Patch 3 adds KUnit coverage.
In hardened usercopy, patch 2 changes check_bogus_address() so nonzero
addresses below ZERO_SIZE_PTR no longer cause its null-address abort.
v1 -> v2:
- express the poison-pointer bound as 0x100 instead of 128 (Catalin)
- make ZERO_OR_NULL_PTR() use exact matches
- add KUnit coverage
Tested on bcc44b6785f21 with the series applied:
- GCC 15.2 QEMU boots on ten configurations spanning sentinel values
16, 32, 64 and 128, all passing the zero-size allocation selftest
- the x86_64 test also passes with GCC 8.1, the minimum supported
compiler
- the new KUnit test passes on UML
- Clang UBSAN_ALIGNMENT is clean on armv5 and the generated code
retains the exact sentinel comparison
- Clang builds the macro for 21 targets at -O2 and -Os, with single
evaluation confirmed in the generated IR
- patch 2 changes vmlinux text by -2 bytes on x86_64 and -72 bytes
on armv5, and arm64 gains 44 symbol bytes
v1: https://lore.kernel.org/r/20260808105622.62026-1-kmehltretter@gmail.com
RFC: https://lore.kernel.org/r/20260712120728.96628-1-kmehltretter@gmail.com
Karl Mehltretter (3):
slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN
slab: check for ZERO_SIZE_PTR by exact match
slab: test zero-size allocations in slub_kunit
include/linux/slab.h | 20 +++++++++++++++++---
lib/tests/slub_kunit.c | 43 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 3 deletions(-)
base-commit: bcc44b6785f216eb939226ade6e3910baa30516b
--
2.53.0
next reply other threads:[~2026-08-11 14:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 14:12 Karl Mehltretter [this message]
2026-08-11 14:12 ` [PATCH v2 1/3] slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN Karl Mehltretter
2026-08-11 14:12 ` [PATCH v2 2/3] slab: check for ZERO_SIZE_PTR by exact match Karl Mehltretter
2026-08-12 0:17 ` Kees Cook
2026-08-11 14:12 ` [PATCH v2 3/3] slab: test zero-size allocations in slub_kunit Karl Mehltretter
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=20260811141240.62519-1-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=gustavoars@kernel.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@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