Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lkl hid fuzzer #515

Merged
merged 6 commits into from
Feb 27, 2023
Merged

Lkl hid fuzzer #515

merged 6 commits into from
Feb 27, 2023

Conversation

rodionov
Copy link

This change adds @HclX's HID fuzzer.

Copy link
Member

@tavip tavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work Eugene, thank you! I left a few comments inline for a couple minor issues.

arch/lkl/kernel/vmlinux-fuzzing-postlink.lds Outdated Show resolved Hide resolved
tools/lkl/Makefile Outdated Show resolved Hide resolved
arch/lkl/kernel/setup.c Show resolved Hide resolved
arch/lkl/Makefile.postlink Outdated Show resolved Hide resolved
arch/lkl/Makefile.postlink Show resolved Hide resolved
tools/lkl/Makefile.autoconf Outdated Show resolved Hide resolved
arch/lkl/Kconfig Outdated Show resolved Hide resolved
arch/lkl/Kconfig Outdated Show resolved Hide resolved
tools/lkl/Makefile Outdated Show resolved Hide resolved
Pad '/init' string in fs_setup functio to make sure it's 8 bytes,
otherwise KASan would emit an error. The kernel's strncpy
implementation attempts to read 8 bytes at once and, thus,
triggers KASan violation for the 6-byte string.

Signed-off-by: Eugene Rodionov <[email protected]>
Copy link
Member

@tavip tavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

There are a few checkpatch warnings please check and see if it makes sense to fix some of them.

rodionov and others added 5 commits February 27, 2023 23:03
This change adds two LKL kernel config options:
 * LKL_FUZZING which enables libFuzzer fuzzing instrumentation for the
   kernel code
 * LKL_LINE_COV which enables code coverage instrumentation for the fuzz
   targets.

These kernel config options are enabled via environment variables which
should be set up either in the environment or in the make files.

To build LKL fuzzers run (currently there are no fuzzers checked in yet):
make -C tools/lkl LKL_FUZZING=1 fuzzers

Signed-off-by: Xuan Xing <[email protected]>
Signed-off-by: Eugene Rodionov <[email protected]>
Incremental linking in lld doesn't work well with the group sections
(GRP_COMDAT) present in the input files -- in this case the linker
semantics is unclear and not defined. This causes problems for building
LKL fuzzers with libFuzzer instrumentation (-fsanitize=fuzzer) which
generates object files with group sections due to the SanitizerCoverage
instrumentation.

This CL implements a workaround for this issue by introducing another
post-link vmlinux pass.

1) First, vmlinux is linked with an empty linker script to avoid merging
   input sections

2) Then, .group sections (GRP_COMDAT) are stripped from the vmlinux
   image with `objcopy --remove-section=.group`.

3) Finally, we relink the vmlinux with the original linker scrip (using
   incremental linking).

Signed-off-by: Eugene Rodionov <[email protected]>
As LKL fuzzers might be built with different kernel config options
than the ones provided in the defconfig this change introduces an
additional fuzzing_defconfig file.

It is assumed that all LKL fuzzers are built using the same kernel
config.

Signed-off-by: Xuan Xing <[email protected]>
Signed-off-by: Eugene Rodionov <[email protected]>
This fuzzer fuzzes Linux kernel HID subsystem via /dev/uhid device.

To build the fuzzer:

make -C tools/lkl LKL_FUZZING=1 fuzzers

Signed-off-by: Xuan Xing <[email protected]>
Add a new target to build LKL-based fuzzers using clang/lld toolchain.

Signed-off-by: Eugene Rodionov <[email protected]>
@tavip tavip merged commit 83a905f into lkl:master Feb 27, 2023
@rodionov
Copy link
Author

Many thanks, @tavip! The checkpatch warning have been fixed.

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.

3 participants