Skip to content

KFuzzTest: a new kernel fuzzing framework

Ethan Graham linux-crypto linux-mm lkml llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest10 patches 8 repliesIn review

Changes since RFC v2 from the cover letter

- Per feedback from Ignat Korchagin a fuzz target has been defined for the load_script function in binfmt_script.c, and all fuzz targets are built with CONFIG_KFUZZTEST=y rather than a specialized configuration option per module.
- Per feedback from David Gow and Alexander Potapenko, KFuzzTest linkage definitions have been moved into the generic linkage header so that the framework isn't bound to x86_64.

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10mm/kasan: implement kasan_poison_rangeinclude/linux/kasan.h mm/kasan/shadow.c+45 -01 reply
2/10kfuzztest: add user-facing API and data structuresinclude/asm-generic/vmlinux.lds.h include/linux/kfuzztest.h lib/Kconfig.debug +1 more+536 -11 reply
3/10kfuzztest: implement core module and input processinginclude/linux/kfuzztest.h lib/Makefile lib/kfuzztest/Makefile +2 more+454 -01 reply
4/10tools: add kfuzztest-bridge utilitytools/Makefile tools/kfuzztest-bridge/.gitignore tools/kfuzztest-bridge/Build +12 more+1602 -62 replies
5/10kfuzztest: add ReST documentationDocumentation/dev-tools/index.rst Documentation/dev-tools/kfuzztest.rst tools/kfuzztest-bridge/input_parser.c+388 -00 replies
6/10kfuzztest: add KFuzzTest sample fuzz targetssamples/Kconfig samples/Makefile samples/kfuzztest/Makefile +2 more+141 -00 replies
7/10crypto: implement KFuzzTest targets for PKCS7 and RSA parsingcrypto/asymmetric_keys/Makefile crypto/asymmetric_keys/tests/Makefile crypto/asymmetric_keys/tests/pkcs7_kfuzz.c +1 more+64 -02 replies
8/10drivers/auxdisplay: add a KFuzzTest for parse_xy()drivers/auxdisplay/charlcd.c drivers/auxdisplay/tests/charlcd_kfuzz.c+28 -00 replies
9/10fs/binfmt_script: add KFuzzTest target for load_scriptfs/binfmt_script.c fs/tests/binfmt_script_kfuzz.c+59 -00 replies
10/10MAINTAINERS: add maintainer information for KFuzzTestMAINTAINERS+8 -01 reply

Reviews trailers per patch

5 of 10 patches have a Reviewed-by or Acked-by.

PatchAlexander PotapenkoIgnat Korchagin
1/10R-b
2/10
3/10
4/10
5/10A-b
6/10A-b
7/10R-b
8/10
9/10
10/10A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH v1 0/10] KFuzzTest: a new kernel fuzzing framework

From: Ethan Graham <[email protected]>

This patch series introduces KFuzzTest, a lightweight framework for creating in-kernel fuzz targets for internal kernel functions.

The primary motivation for KFuzzTest is to simplify the fuzzing of low-level, relatively stateless functions (e.g., data parsers, format converters) that are difficult to exercise effectively from the syscall boundary. It is intended for in-situ fuzzing of kernel code without requiring that it be built as a separate userspace library or that its dependencies be stubbed out. Using a simple macro-based API, developers can add a new fuzz target with minimal boilerplate code.

The core design consists of three main parts:
1. A FUZZ_TEST(name, struct_type) macro that allows developers to easily define a fuzz test.
2. A binary input format that allows a userspace fuzzer to serialize complex, pointer-rich C structures into a single buffer.
3. Metadata for test targets, constraints, and annotations, which is emitted into dedicated ELF sections to allow for discovery and inspection by userspace tools. These are found in ".kfuzztest_{targets, constraints, annotations}".

To demonstrate this framework's viability, support for KFuzzTest has been prototyped in a development fork of syzkaller, enabling coverage-guided fuzzing. To validate its end-to-end effectiveness, we performed an experiment by manually introducing an off-by-one buffer over-read into pkcs7_parse_message, like so:

- ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen);
+ ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen + 1);

A syzkaller instance fuzzing the new test_pkcs7_parse_message target introduced in patch 7 successfully triggered the bug inside of asn1_ber_decoder in under 30 seconds from a cold start. Similar experiements on the other new fuzz targets (patches 8-9) also successfully identified injected bugs, proving that KFuzzTest is effective when paired with a coverage-guided fuzzing engine.

A note on build system integration: several new fuzz targets (patches 7-9) are included by conditionally importing a .c file when CONFIG_KFUZZTEST=y. While this may seem unusual, it follows a pattern used by some KUnit tests (e.g., in /fs/binfmt_elf.c). We considered defining macros like VISIBLE_IF_KFUZZTEST, but believe the final integration approach is best decided by subsystem maintainers. This avoids creating a one-size-fits-all abstraction prematurely.

The patch series is structured as follows:
- Patch 1 adds and exposes kasan_poison_range for poisoning memory ranges with an unaligned start address and KASAN_GRANULE_SIZE aligned end address.
- Patch 2 introduces the core KFuzzTest API and data structures.
- Patch 3 adds the runtime implementation for the framework.
- Patch 4 adds a tool for sending structured inputs into a fuzz target.
- Patch 5 adds documentation.
- Patch 6 provides sample fuzz targets.
- Patch 7 defines fuzz targets for several functions in /crypto.
- Patch 8 defines a fuzz target for parse_xy in /drivers/auxdisplay.
- Patch 9 defines a fuzz target for load_script in /fs.
- Patch 10 adds maintainer information for KFuzzTest.

Changes since RFC v2:
- Per feedback from Ignat Korchagin a fuzz target has been defined for the load_script function in binfmt_script.c, and all fuzz targets are built with CONFIG_KFUZZTEST=y rather than a specialized configuration option per module.
- Per feedback from David Gow and Alexander Potapenko, KFuzzTest linkage definitions have been moved into the generic linkage header so that the framework isn't bound to x86_64.

Ethan Graham (10):
mm/kasan: implement kasan_poison_range
kfuzztest: add user-facing API and data structures
kfuzztest: implement core module and input processing
tools: add kfuzztest-bridge utility
kfuzztest: add ReST documentation
kfuzztest: add KFuzzTest sample fuzz targets
crypto: implement KFuzzTest targets for PKCS7 and RSA parsing drivers/auxdisplay: add a KFuzzTest for parse_xy() fs/binfmt_script: add KFuzzTest target for load_script
MAINTAINERS: add maintainer information for KFuzzTest

 Documentation/dev-tools/index.rst             |   1 +
 Documentation/dev-tools/kfuzztest.rst         | 385 ++++++++++++++
 MAINTAINERS                                   |   8 +
 crypto/asymmetric_keys/Makefile               |   2 +
 crypto/asymmetric_keys/tests/Makefile         |   2 +
 crypto/asymmetric_keys/tests/pkcs7_kfuzz.c    |  22 +
 .../asymmetric_keys/tests/rsa_helper_kfuzz.c  |  38 ++
 drivers/auxdisplay/charlcd.c                  |   8 +
 drivers/auxdisplay/tests/charlcd_kfuzz.c      |  20 +
 fs/binfmt_script.c                            |   8 +
 fs/tests/binfmt_script_kfuzz.c                |  51 ++
 include/asm-generic/vmlinux.lds.h             |  22 +-
 include/linux/kasan.h                         |  11 +
 include/linux/kfuzztest.h                     | 498 ++++++++++++++++++
 lib/Kconfig.debug                             |   1 +
 lib/Makefile                                  |   2 +
 lib/kfuzztest/Kconfig                         |  20 +
 lib/kfuzztest/Makefile                        |   4 +
 lib/kfuzztest/main.c                          | 240 +++++++++
 lib/kfuzztest/parse.c                         | 204 +++++++
 mm/kasan/shadow.c                             |  34 ++
 samples/Kconfig                               |   7 +
 samples/Makefile                              |   1 +
 samples/kfuzztest/Makefile                    |   3 +
 samples/kfuzztest/overflow_on_nested_buffer.c |  71 +++
 samples/kfuzztest/underflow_on_buffer.c       |  59 +++
 tools/Makefile                                |  15 +-
 tools/kfuzztest-bridge/.gitignore             |   2 +
 tools/kfuzztest-bridge/Build                  |   6 +
 tools/kfuzztest-bridge/Makefile               |  48 ++
 tools/kfuzztest-bridge/bridge.c               | 103 ++++
 tools/kfuzztest-bridge/byte_buffer.c          |  87 +++
 tools/kfuzztest-bridge/byte_buffer.h          |  31 ++
 tools/kfuzztest-bridge/encoder.c              | 391 ++++++++++++++
 tools/kfuzztest-bridge/encoder.h              |  16 +
 tools/kfuzztest-bridge/input_lexer.c          | 242 +++++++++
 tools/kfuzztest-bridge/input_lexer.h          |  57 ++
 tools/kfuzztest-bridge/input_parser.c         | 397 ++++++++++++++
 tools/kfuzztest-bridge/input_parser.h         |  81 +++
 tools/kfuzztest-bridge/rand_stream.c          |  77 +++
 tools/kfuzztest-bridge/rand_stream.h          |  57 ++
 41 files changed, 3325 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/dev-tools/kfuzztest.rst
 create mode 100644 crypto/asymmetric_keys/tests/Makefile
 create mode 100644 crypto/asymmetric_keys/tests/pkcs7_kfuzz.c
 create mode 100644 crypto/asymmetric_keys/tests/rsa_helper_kfuzz.c
 create mode 100644 drivers/auxdisplay/tests/charlcd_kfuzz.c
 create mode 100644 fs/tests/binfmt_script_kfuzz.c
 create mode 100644 include/linux/kfuzztest.h
 create mode 100644 lib/kfuzztest/Kconfig
 create mode 100644 lib/kfuzztest/Makefile
 create mode 100644 lib/kfuzztest/main.c
 create mode 100644 lib/kfuzztest/parse.c
 create mode 100644 samples/kfuzztest/Makefile
 create mode 100644 samples/kfuzztest/overflow_on_nested_buffer.c
 create mode 100644 samples/kfuzztest/underflow_on_buffer.c
 create mode 100644 tools/kfuzztest-bridge/.gitignore
 create mode 100644 tools/kfuzztest-bridge/Build
 create mode 100644 tools/kfuzztest-bridge/Makefile
 create mode 100644 tools/kfuzztest-bridge/bridge.c
 create mode 100644 tools/kfuzztest-bridge/byte_buffer.c
 create mode 100644 tools/kfuzztest-bridge/byte_buffer.h
 create mode 100644 tools/kfuzztest-bridge/encoder.c
 create mode 100644 tools/kfuzztest-bridge/encoder.h
 create mode 100644 tools/kfuzztest-bridge/input_lexer.c
 create mode 100644 tools/kfuzztest-bridge/input_lexer.h
 create mode 100644 tools/kfuzztest-bridge/input_parser.c
 create mode 100644 tools/kfuzztest-bridge/input_parser.h
 create mode 100644 tools/kfuzztest-bridge/rand_stream.c
 create mode 100644 tools/kfuzztest-bridge/rand_stream.h
Signature · 1 line
2.51.0.384.g4c02a37b29-goog