KUnit Fuzz Harnesses (PoC)#18
Open
ethangraham2001 wants to merge 2 commits intomasterfrom
Open
Conversation
Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
Demonstrates the proposed KUnit fuzz harness API. Signed-off-by: Ethan Graham <ethan.w.s.graham@gmail.com>
ethangraham2001
commented
Mar 26, 2026
Comment on lines
-164
to
+174
| #define KUNIT_CASE(test_name) \ | ||
| { .run_case = test_name, .name = #test_name, \ | ||
| .module_name = KBUILD_MODNAME} | ||
| #define KUNIT_CASE(test_name) \ | ||
| { .run_case = test_name, \ | ||
| .name = #test_name, \ | ||
| .module_name = KBUILD_MODNAME } |
Owner
Author
There was a problem hiding this comment.
My formatter got excited and git add -p wouldn't let me split this.
ethangraham2001
commented
Mar 26, 2026
Comment on lines
+317
to
+320
| /* | ||
| * Do not create file to re-run test if test runs on init, or if the | ||
| * suite represents a set of fuzzing harnesses. | ||
| */ |
Owner
Author
There was a problem hiding this comment.
Oops - this comment is from another attempt. Behavior is unchanged here, ignore the comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An idea that was floated around in the mailing list when the first KFuzzTest RFC was sent up was the idea of integrating KFuzzTest into KUnit rather than maintaining it as a separate framework.
At the time it was decided that it would be pragmatic to keep KFuzzTest as a standalone framework, after having some time to reflect, it seemed like it would be a good idea to try it out. There are a few benefits to this.
These two patches implement a simple PoC for fuzzing harnesses in KUnit as a special type of KUnit test. Much of the design is taken directly from KFuzzTest, allowing a userspace fuzzer (or arbitrary program) to send inputs via debugfs to invoke a fuzz test. The flow looks like so
write()data into/sys/kernel/debug/kunit/suite-name/fuzzioctl(..., handle_id)the same file to invoke the fuzz test on the data previously sent.Here,
handle_idrepresents the logical index in the array of available fuzz targets for the suite. This can be easily read from debugfs by reading from the[...]/kunit/suite-name/fuzzfile, like so:I'm not super familiar with the KUnit codebase so this implementation is pretty hacky, but it seems to work reasonably well in practice. Using the same pkcs7 PoC from previous patch series, a fuzzer was able to trigger an injected bug as demonstrated by a KASAN report.
Commit 2 shows how the previously macro-defined fuzz targets can be implemented similarly as KUnit tests - these examples likely aren't the best however, as they don't use any specific KUnit functionality.
I used this fuzzer to trigger the bug: https://github.com/ethangraham2001/KFuzz-Uring/tree/kunit-fuzz-poc
Note that throughput is significantly lower than with the simple
write()based approach from the previous KFuzzTest implementation, seeing as we are spawning a thread for every invocation - maybe a different model should be considered for the fuzzing harnesses. The number of inputs/sec is still higher than syzkaller however, but it's a less smart fuzzer and therefore difficult to faithfully compare.There are a couple of samples built into the KUnit examples; one of these contains an OOB that can very easily be triggered.