Skip to content

Conversation

@ethangraham2001
Copy link
Owner

Made some suggested changes, namely

  • Expose kasan_poison_range from <Linux/kasan.h> directly with
    implementation in mm/kasan/kasan.h.
  • 120 column limit instead of 80 for better readability.
  • Move example cases into /samples under new Kconfig option.
  • Use kerneldoc comments for annotations and constraints.
  • Add real example cases for some crypto parsing logic.
  • Move static assertions out of include/linux/kfuzztest.h

Ethan Graham and others added 18 commits August 8, 2025 15:28
Move the function declarations for kasan_poison and
kasan_poison_last_granule from the internal mm/kasan/kasan.h to
<linux/kasan.h>.

This refactoring makes these KASAN primitives available to other kernel
subsystems that may require fine-grained memory poisoning capabilities.

This is a preparatory patch for the upcoming KFuzzTest framework which
relies on these functions for detecting out-of-bounds memory accesses
from within the bounds of a single kmalloc'd buffer.

No functional change is introduced by this commit.

Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
Add the foundational user-facing components for the KFuzzTest framework.
This includes the main API header <linux/kfuzztest.h>, the KConfig
option to enable the feature, and the required linker script changes
which introduce three new ELF sections in vmlinux.

Note that KFuzzTest is intended strictly for debug builds only, and
should never be enabled in a production build. The fact that it exposes
internal kernel functions and state directly to userspace may constitute
a serious security vulnerability if used for any reason other than
testing.

The header defines:
- The FUZZ_TEST() macro for creating test targets.
- The data structures required for the binary serialization format,
  which allows passing complex inputs from userspace.
- The metadata structures for test targets, constraints and annotations,
  which are placed in dedicated ELF sections (.kfuzztest_*) for discovery.

This patch only adds the public interface and build integration; no
runtime logic is included.

Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
Add the core runtime implementation for KFuzzTest. This includes the
module initialization, and the logic for receiving and processing
user-provided inputs through debugfs.

On module load, the framework discovers all test targets by iterating
over the .kfuzztest_target section, creating a corresponding debugfs
directory with a write-only 'input' file for each of them.

Writing to an 'input' file triggers the main fuzzing sequence:
1. The serialized input is copied from userspace into a kernel buffer.
2. The buffer is parsed to validate the region array and relocation
   table.
3. Pointers are patched based on the relocation entries, and in KASAN
   builds the inter-region padding is poisoned.
4. The resulting struct is passed to the user-defined test logic.

Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
Add Documentation/dev-tools/kfuzztest.rst and reference it in the
dev-tools index.

Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
Add two simple fuzz target examples to demonstrate the KFuzzTest API and
provide basic self-tests for the framework.

These examples showcase how a developer can define a fuzz target using
the FUZZ_TEST(), constrain, and annotation macros, and serve as runtime
sanity checks for the core logic. For example, they test that out-of-bounds
memory accesses into poisoned padding regions are correctly detected in a
KASAN build.

These have been tested by writing syzkaller-generated inputs into their
debugfs 'input' files and verifying that the correct KASAN reports were
triggered.

Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
We now expose kasan_poison_range as a KASAN API instead of offloading
this to kfuzztest.
Use __used and __section instead of __attribute__(()).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants