Skip to content

kasan: Add KUnit config and fix missing instrumentation in load_unaligned_zeropad()

Bill Wendling linux-arch linux-arm-kernel linux-mm linux-riscv linux-s390 linux-security-module linuxppc-dev lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7kasan: Add .kunitconfig for KUnit testsmm/kasan/.kunitconfig+15 -00 replies
2/7x86/word-at-a-time: Instrument load_unaligned_zeropad()arch/x86/include/asm/word-at-a-time.h include/asm-generic/word-at-a-time-instrumented.h+28 -10 replies
3/7arm64/word-at-a-time: Instrument load_unaligned_zeropad()arch/arm64/include/asm/word-at-a-time.h+3 -10 replies
4/7arm/word-at-a-time: Instrument load_unaligned_zeropad()arch/arm/include/asm/word-at-a-time.h+3 -10 replies
5/7riscv/word-at-a-time: Instrument load_unaligned_zeropad()arch/riscv/include/asm/word-at-a-time.h+3 -10 replies
6/7s390/word-at-a-time: Instrument load_unaligned_zeropad()arch/s390/include/asm/word-at-a-time.h+3 -10 replies
7/7powerpc/word-at-a-time: Instrument load_unaligned_zeropad()arch/powerpc/include/asm/word-at-a-time.h+3 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/7] kasan: Add KUnit config and fix missing instrumentation in load_unaligned_zeropad()

This series makes the KASAN KUnit test suite easy to run via kunit.py and fixes a real detection gap it uncovered along the way.

Patch 1 adds mm/kasan/.kunitconfig so the suite can be run with:

    ./tools/testing/kunit/kunit.py run --arch=x86_64 --kunitconfig mm/kasan

Getting CONFIG_KASAN_KUNIT_TEST to actually build required pulling in CONFIG_SCHED_TRACER (CONFIG_FTRACE alone doesn't select the invisible TRACEPOINTS symbol it depends on), plus a larger CONFIG_LOG_BUF_SHIFT to stop KASAN's verbose reports from overflowing the printk buffer under QEMU.

The migration from read_word_at_a_time() to load_unaligned_zeropad() lost instrumentation, because the load_unaligned_zeropad() functions are implemented as inline asm with an exception table entry on every architecture, so the compiler never sees the memory access and can't instrument it for KASAN/KCSAN. This meant sized_strscpy() silently bypassed KASAN when reading its source buffer word-at-a-time, and the same gap turned out to be open at every other call site in the tree.

Rather than patching each call site individually, patch 2 renames x86's load_unaligned_zeropad() to arch_load_unaligned_zeropad() and adds a single common, always-inlined wrapper that instruments the read before calling through.

Patches 3-7 convert the remaining architectures (arm64, arm, riscv, s390, powerpc) that implement load_unaligned_zeropad() to the same pattern, so each can be reviewed independently by its arch maintainer.

Verified via objdump that the wrapper adds no calls or relocations when KASAN and KCSAN are both disabled.

Bill Wendling (7):
kasan: Add .kunitconfig for KUnit tests x86/word-at-a-time: Instrument load_unaligned_zeropad() arm64/word-at-a-time: Instrument load_unaligned_zeropad() arm/word-at-a-time: Instrument load_unaligned_zeropad() riscv/word-at-a-time: Instrument load_unaligned_zeropad() s390/word-at-a-time: Instrument load_unaligned_zeropad() powerpc/word-at-a-time: Instrument load_unaligned_zeropad()

 arch/arm/include/asm/word-at-a-time.h         |  4 ++-
 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 ++-
 .../asm-generic/word-at-a-time-instrumented.h | 25 +++++++++++++++++++
 mm/kasan/.kunitconfig                         | 15 +++++++++++
 8 files changed, 58 insertions(+), 6 deletions(-)
 create mode 100644 include/asm-generic/word-at-a-time-instrumented.h
 create mode 100644 mm/kasan/.kunitconfig
Signature · 1 line
2.47.3