* + word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad.patch added to mm-new branch
@ 2026-10-30 3:57 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-10-30 3:57 UTC (permalink / raw)
To: mm-commits, will, vincenzo.frascino, tglx, svens, sshegde, shuah,
ryabinin.a.a, ritesh.list, pjw, peter, palmer, npiggin, mpe,
mingo, mark.rutland, maddy, linux, kees, hpa, hca, gor, glider,
elver, dvyukov, dave.hansen, chleroy, catalin.marinas, bp,
borntraeger, aou, andreyknvl, alex, agordeev, odys.yuan, akpm
The patch titled
Subject: word-at-a-time: check the first byte in load_unaligned_zeropad()
has been added to the -mm mm-new branch. Its filename is
word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Qiliang Yuan <odys.yuan@gmail.com>
Subject: word-at-a-time: check the first byte in load_unaligned_zeropad()
Date: Fri, 23 Oct 2026 09:49:48 +0800
Patch series "word-at-a-time: let KASAN see load_unaligned_zeropad()", v2.
load_unaligned_zeropad() is inline assembly, so KASAN and KCSAN never see
the word loads that sized_strscpy(), the dcache name compare, path name
hashing and x86 csum_partial() do through it. While reviewing a strscpy()
KASAN fix, Peter Collingbourne suggested checking the first byte inside
load_unaligned_zeropad() itself, as read_word_at_a_time() does [1].
Patch 1 adds that check on the six architectures that implement
load_unaligned_zeropad(). Patch 2 adds a KASAN KUnit case for it.
This patch (of 2):
load_unaligned_zeropad() reads a word that may run into an unmapped page
and recovers through an exception fixup. It does the word loads of
sized_strscpy() and of the name compare in dentry_string_cmp(), path
components in hash_name() and hashlen_string(), and the trailing bytes in
x86's csum_partial().
It is inline assembly on every architecture that implements it, so KASAN
and KCSAN never see these loads, while read_word_at_a_time() at least
checks the first byte of each word. A use-after-free or out-of-bounds
read of a name handed to path lookup goes unreported, and so does
strscpy() reading from a bad source, which the kasan_strings KUnit case
expects to be reported. On x86_64 with generic KASAN:
KASAN and string KUnit suites failures
before after
CONFIG_FORTIFY_SOURCE=n 1 0
CONFIG_FORTIFY_SOURCE=y 1 0
Check the first byte with instrument_read() at the start of
load_unaligned_zeropad() on every architecture, as read_word_at_a_time()
does. All callers only load a word whose first byte belongs to the string
or buffer they read, so the check does not flag their intended reads past
the end. Add a no-op instrument_read() for the powerpc selftest that
builds the header in user space.
Link: https://lore.kernel.org/r/CAPQLkRhXZwozmfhNd_PEx1ihwdH1_5qthP6PANYJ_m-v9vfQTw@mail.gmail.com [1]
Link: https://lore.kernel.org/20261023-bug-word-at-a-time-zeropad-kasan-v2-0-be0ecfbae847@gmail.com
Link: https://lore.kernel.org/20261023-bug-word-at-a-time-zeropad-kasan-v2-1-be0ecfbae847@gmail.com
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Peter Collingbourne <peter@pcc.me.uk>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <chleroy@kernel.org>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shrikanth Hegde <sshegde@linux.ibm.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: AlexandreGhiti <alex@ghiti.fr>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Kees Cook <kees@kernel.org>
---
arch/arm/include/asm/word-at-a-time.h | 5 +++++
arch/arm64/include/asm/word-at-a-time.h | 4 ++++
arch/powerpc/include/asm/word-at-a-time.h | 4 ++++
arch/riscv/include/asm/word-at-a-time.h | 4 ++++
arch/s390/include/asm/word-at-a-time.h | 4 ++++
arch/x86/include/asm/word-at-a-time.h | 4 ++++
tools/testing/selftests/powerpc/primitives/linux/instrumented.h | 3 +++
7 files changed, 28 insertions(+)
--- a/arch/arm64/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/arm64/include/asm/word-at-a-time.h
@@ -8,6 +8,7 @@
#include <linux/uaccess.h>
#include <linux/bitops.h>
+#include <linux/instrumented.h>
#include <linux/wordpart.h>
struct word_at_a_time {
@@ -45,6 +46,9 @@ static inline unsigned long load_unalign
{
unsigned long ret;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
__mte_enable_tco_async();
/* Load word from unaligned pointer addr */
--- a/arch/arm/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/arm/include/asm/word-at-a-time.h
@@ -56,6 +56,8 @@ static inline unsigned long find_zero(un
#include <asm-generic/word-at-a-time.h>
#endif
+#include <linux/instrumented.h>
+
#ifdef CONFIG_DCACHE_WORD_ACCESS
/*
@@ -69,6 +71,9 @@ static inline unsigned long load_unalign
{
unsigned long ret, tmp;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
/* Load word from unaligned pointer addr */
asm(
"1: ldr %0, [%2]\n"
--- a/arch/powerpc/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/powerpc/include/asm/word-at-a-time.h
@@ -5,6 +5,7 @@
* Word-at-a-time interfaces for PowerPC.
*/
#include <linux/bitops.h>
+#include <linux/instrumented.h>
#include <linux/wordpart.h>
#include <asm/asm-compat.h>
#include <asm/extable.h>
@@ -168,6 +169,9 @@ static inline unsigned long load_unalign
{
unsigned long ret, offset, tmp;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
asm(
"1: " PPC_LL "%[ret], 0(%[addr])\n"
"2:\n"
--- a/arch/riscv/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/riscv/include/asm/word-at-a-time.h
@@ -11,6 +11,7 @@
#include <asm/asm-extable.h>
#include <linux/bitops.h>
+#include <linux/instrumented.h>
#include <linux/wordpart.h>
struct word_at_a_time {
@@ -60,6 +61,9 @@ static inline unsigned long load_unalign
{
unsigned long ret;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
/* Load word from unaligned pointer addr */
asm(
"1: " REG_L " %0, %2\n"
--- a/arch/s390/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/s390/include/asm/word-at-a-time.h
@@ -3,6 +3,7 @@
#define _ASM_WORD_AT_A_TIME_H
#include <linux/bitops.h>
+#include <linux/instrumented.h>
#include <linux/wordpart.h>
#include <asm/asm-extable.h>
#include <asm/bitsperlong.h>
@@ -52,6 +53,9 @@ static inline unsigned long load_unalign
{
unsigned long data;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
asm_inline volatile(
"0: lg %[data],0(%[addr])\n"
"1:\n"
--- a/arch/x86/include/asm/word-at-a-time.h~word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad
+++ a/arch/x86/include/asm/word-at-a-time.h
@@ -3,6 +3,7 @@
#define _ASM_WORD_AT_A_TIME_H
#include <linux/bitops.h>
+#include <linux/instrumented.h>
#include <linux/wordpart.h>
struct word_at_a_time {
@@ -71,6 +72,9 @@ static inline unsigned long load_unalign
{
unsigned long ret;
+ /* Check only the first byte, the rest may lie past the object */
+ instrument_read(addr, 1);
+
asm volatile(
"1: mov %[mem], %[ret]\n"
"2:\n"
diff --git a/tools/testing/selftests/powerpc/primitives/linux/instrumented.h a/tools/testing/selftests/powerpc/primitives/linux/instrumented.h
new file mode 100644
--- /dev/null
+++ a/tools/testing/selftests/powerpc/primitives/linux/instrumented.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* There is nothing for KASAN or KCSAN to check in user space. */
+#define instrument_read(p, size) ((void)(p), (void)(size))
_
Patches currently in -mm which might be from odys.yuan@gmail.com are
selftests-mm-track-the-modules-run_vmtestssh-loads.patch
selftests-mm-load-xfs-before-checking-for-it-in-run_vmtestssh.patch
word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad.patch
kasan-test-cover-load_unaligned_zeropad.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-30 3:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 3:57 + word-at-a-time-check-the-first-byte-in-load_unaligned_zeropad.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.