Skip to content

Commit a4691de

Browse files
vegardtorvalds
authored andcommitted
kcov: allow more fine-grained coverage instrumentation
For more targeted fuzzing, it's better to disable kernel-wide instrumentation and instead enable it on a per-subsystem basis. This follows the pattern of UBSAN and allows you to compile in the kcov driver without instrumenting the whole kernel. To instrument a part of the kernel, you can use either # for a single file in the current directory KCOV_INSTRUMENT_filename.o := y or # for all the files in the current directory (excluding subdirectories) KCOV_INSTRUMENT := y or # (same as above) ccflags-y += $(CFLAGS_KCOV) or # for all the files in the current directory (including subdirectories) subdir-ccflags-y += $(CFLAGS_KCOV) Link: http://lkml.kernel.org/r/1464008380-11405-1-git-send-email-vegard.nossum@oracle.com Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f1cb637 commit a4691de

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎lib/Kconfig.debug‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,17 @@ config KCOV
719719

720720
For more details, see Documentation/kcov.txt.
721721

722+
config KCOV_INSTRUMENT_ALL
723+
bool "Instrument all code by default"
724+
depends on KCOV
725+
default y if KCOV
726+
help
727+
If you are doing generic system call fuzzing (like e.g. syzkaller),
728+
then you will want to instrument the whole kernel and you should
729+
say y here. If you are doing more targeted fuzzing (like e.g.
730+
filesystem fuzzing with AFL) then you will want to enable coverage
731+
for more specific subsets of files, and should say n here.
732+
722733
config DEBUG_SHIRQ
723734
bool "Debug shared IRQ handlers"
724735
depends on DEBUG_KERNEL

‎scripts/Makefile.lib‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ endif
138138

139139
ifeq ($(CONFIG_KCOV),y)
140140
_c_flags += $(if $(patsubst n%,, \
141-
$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)y), \
141+
$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
142142
$(CFLAGS_KCOV))
143143
endif
144144

0 commit comments

Comments
 (0)