freebsd-dev/sys/kern
Andrew Turner b3c0d957a2 Add support for the Clang Coverage Sanitizer in the kernel (KCOV).
When building with KCOV enabled the compiler will insert function calls
to probes allowing us to trace the execution of the kernel from userspace.
These probes are on function entry (trace-pc) and on comparison operations
(trace-cmp).

Userspace can enable the use of these probes on a single kernel thread with
an ioctl interface. It can allocate space for the probe with KIOSETBUFSIZE,
then mmap the allocated buffer and enable tracing with KIOENABLE, with the
trace mode being passed in as the int argument. When complete KIODISABLE
is used to disable tracing.

The first item in the buffer is the number of trace event that have
happened. Userspace can write 0 to this to reset the tracing, and is
expected to do so on first use.

The format of the buffer depends on the trace mode. When in PC tracing just
the return address of the probe is stored. Under comparison tracing the
comparison type, the two arguments, and the return address are traced. The
former method uses on entry per trace event, while the later uses 4. As
such they are incompatible so only a single mode may be enabled.

KCOV is expected to help fuzzing the kernel, and while in development has
already found a number of issues. It is required for the syzkaller system
call fuzzer [1]. Other kernel fuzzers could also make use of it, either
with the current interface, or by extending it with new modes.

A man page is currently being worked on and is expected to be committed
soon, however having the code in the kernel now is useful for other
developers to use.

[1] https://github.com/google/syzkaller

Submitted by:	Mitchell Horne <mhorne063@gmail.com> (Earlier version)
Reviewed by:	kib
Testing by:	tuexen
Sponsored by:	DARPA, AFRL
Sponsored by:	The FreeBSD Foundation (Mitchell Horne)
Differential Revision:	https://reviews.freebsd.org/D14599
2019-01-12 11:21:28 +00:00
..
bus_if.m add support for marking interrupt handlers as suspended 2018-12-17 17:11:00 +00:00
capabilities.conf capsicum: allow ppoll(2) in capability mode 2018-11-04 17:12:53 +00:00
clock_if.m
cpufreq_if.m
device_if.m
genassym.sh
genoffset.c With epoch not inlined, there is no point in using _lite KPI. While here, 2018-11-13 23:45:38 +00:00
genoffset.sh expose thread_lite definition to tied modules 2018-07-03 02:50:07 +00:00
imgact_aout.c Remove iBCS2, part2: general kernel 2018-12-19 21:57:58 +00:00
imgact_binmisc.c Add helper functions to copy strings into struct image_args. 2018-11-29 21:00:56 +00:00
imgact_elf32.c
imgact_elf64.c
imgact_elf.c Remove proctree acquire from note_procstat_proc 2018-12-08 11:38:39 +00:00
imgact_gzip.c Use C99 designated initializers for struct execsw 2018-03-13 13:09:10 +00:00
imgact_shell.c Add helper functions to copy strings into struct image_args. 2018-11-29 21:00:56 +00:00
init_main.c Remove iBCS2, part2: general kernel 2018-12-19 21:57:58 +00:00
init_sysent.c Regen. 2018-12-07 15:19:00 +00:00
kern_acct.c
kern_alq.c
kern_clock.c Tidy up hardclock. 2018-11-29 03:44:02 +00:00
kern_clocksource.c Rename hardclock_cnt() to hardclock() and remove the old implementation. 2018-09-06 02:10:59 +00:00
kern_condvar.c
kern_conf.c dev_refthread: Do not initialize *ref when reference was not acquired 2018-10-20 19:42:38 +00:00
kern_cons.c Replace ttyprintf with sbuf_printf and tty drain routine 2018-10-20 18:31:36 +00:00
kern_context.c Remove superfluous bzero in getcontext/swapcontext/sendsig 2018-11-26 20:56:05 +00:00
kern_cpu.c kern_cpu: When adding abs frequency allow for unordered insertion 2018-07-19 11:28:14 +00:00
kern_cpuset.c Add malloc_domainset(9) and _domainset variants to other allocator KPIs. 2018-10-30 18:26:34 +00:00
kern_ctf.c
kern_descrip.c vfs: mostly depessimize NDINIT_ALL 2018-12-14 03:55:08 +00:00
kern_dtrace.c systrace: track it like sdt probes 2018-04-27 15:16:34 +00:00
kern_dump.c Print the dump progress indicator after calling dump_start(). 2018-05-01 17:32:43 +00:00
kern_environment.c Add dynamic_kenv assertion to init_static_kenv 2018-11-13 04:34:30 +00:00
kern_et.c
kern_event.c proc: postpone proc unlock until after reporting with kqueue 2018-12-08 06:34:12 +00:00
kern_exec.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
kern_exit.c proc: handle sdt exit probe before taking the proc lock 2018-12-08 06:31:43 +00:00
kern_fail.c
kern_ffclock.c
kern_fork.c Microoptimize corner case of ID bitmap handling. 2018-12-19 20:29:52 +00:00
kern_hhook.c
kern_idle.c
kern_intr.c add support for marking interrupt handlers as suspended 2018-12-17 17:11:00 +00:00
kern_jail.c Replace hand-rolled unrefs if > 1 with refcount_release_if_not_last 2018-12-07 16:11:45 +00:00
kern_kcov.c Add support for the Clang Coverage Sanitizer in the kernel (KCOV). 2019-01-12 11:21:28 +00:00
kern_khelp.c
kern_kthread.c proc: always store parent pid in p_oppid 2018-11-16 17:07:54 +00:00
kern_ktr.c
kern_ktrace.c Reduce overhead of ktrace checks in the common case. 2018-05-09 00:00:47 +00:00
kern_linker.c Add flags variants to linker_files / stack(9) symbol resolution 2018-10-20 18:08:43 +00:00
kern_lock.c Annotate Giant drop/pickup macros with __predict_false 2018-12-07 12:06:03 +00:00
kern_lockf.c lockf: annotate LOCKF_DEBUG only var 2018-05-19 05:04:38 +00:00
kern_lockstat.c lockstat: track lockstat just like sdt probes 2018-04-24 01:04:10 +00:00
kern_loginclass.c Replace hand-rolled unrefs if > 1 with refcount_release_if_not_last 2018-12-07 16:11:45 +00:00
kern_malloc.c Fix DDB's "show malloc" after r338899. 2018-12-19 00:17:22 +00:00
kern_mbuf.c netdump: Fix netdumping with INVARIANTS kernels 2018-11-12 05:24:20 +00:00
kern_mib.c For hw.{physmem,realmem,usermem} MIBs, clamp instead truncating. 2018-12-29 15:55:44 +00:00
kern_module.c Use NULL for SYSINIT's last arg, which is a pointer type 2018-05-18 17:58:09 +00:00
kern_mtxpool.c Increase MTX_POOL_SLEEP_SIZE from 128 to 1024. 2018-12-24 23:52:35 +00:00
kern_mutex.c locks: plug warnings about unitialized variables 2018-11-13 21:29:56 +00:00
kern_ntptime.c Clear pad bytes in the struct exported by kern.ntp_pll.gettime. 2018-11-20 20:32:10 +00:00
kern_osd.c
kern_physio.c physio: avoid uninitialized variables 2018-05-19 04:09:58 +00:00
kern_pmc.c Add malloc_domainset(9) and _domainset variants to other allocator KPIs. 2018-10-30 18:26:34 +00:00
kern_poll.c
kern_priv.c Check for probes enabled in priv_check_cred before evaluting the error. 2018-12-19 23:28:29 +00:00
kern_proc.c pfind, pfind_any: Correct zombie logic 2018-12-28 13:32:14 +00:00
kern_procctl.c Rename PROC_PDEATHSIG_SET -> PROC_PDEATHSIG_CTL and PROC_PDEATHSIG_GET 2018-04-20 15:19:27 +00:00
kern_prot.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
kern_racct.c racct: add RACCT_ENABLED macro and racct_set_unlocked 2018-12-07 16:47:34 +00:00
kern_rangelock.c
kern_rctl.c call racct_proc_ucred_changed() under the proc lock 2018-04-20 13:08:04 +00:00
kern_resource.c Make lim_cur inline if possible. 2018-12-11 12:01:46 +00:00
kern_rmlock.c Make no assertions about lock state when the scheduler is stopped. 2018-11-13 20:48:05 +00:00
kern_rwlock.c locks: plug warnings about unitialized variables 2018-11-13 21:29:56 +00:00
kern_sdt.c
kern_sema.c
kern_sendfile.c Plug sendfile(2) on a listening socket with proper error code. 2018-10-16 15:57:16 +00:00
kern_sharedpage.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
kern_shutdown.c Don't enter DDB for fatal traps before panic by default. 2018-11-01 21:34:17 +00:00
kern_sig.c Remove unneeded NULL check for td_ucred 2019-01-04 21:12:17 +00:00
kern_switch.c make critical_{enter, exit} inline 2018-07-03 01:55:09 +00:00
kern_sx.c sx: retire SX_NOADAPTIVE 2018-12-05 16:43:03 +00:00
kern_synch.c Provide SDT_PROBES_ENABLED macro. 2018-12-08 06:30:41 +00:00
kern_syscalls.c fix a typo resulting in a wrong variable in kern_syscall_deregister 2018-08-02 09:41:55 +00:00
kern_sysctl.c const poison the new pointer of __sysctl. 2018-12-18 12:44:38 +00:00
kern_tc.c Make timespecadd(3) and friends public 2018-07-30 15:46:40 +00:00
kern_thr.c Don't acquire evclass_lock with a spinlock held 2018-07-11 19:38:42 +00:00
kern_thread.c Add support for the Clang Coverage Sanitizer in the kernel (KCOV). 2019-01-12 11:21:28 +00:00
kern_time.c Make timespecadd(3) and friends public 2018-07-30 15:46:40 +00:00
kern_timeout.c
kern_tslog.c
kern_ubsan.c Port the NetBSD ubsan runtime to the FreeBSD kernel. 2018-11-06 17:32:07 +00:00
kern_umtx.c umtx: avoid umtxshm locking on object termination if possible 2018-12-08 14:04:57 +00:00
kern_uuid.c
kern_xxx.c Normalize COMPAT_43 syscall declarations. 2018-12-04 16:48:47 +00:00
ksched.c
link_elf_obj.c Fix mips build after r339931. 2018-10-30 21:35:56 +00:00
link_elf.c As a follow-up to r339930 and various reports implement logging in case 2018-10-30 20:51:03 +00:00
linker_if.m
Make.tags.inc Retire dpt(4) 2018-10-22 02:35:12 +00:00
Makefile
makesyscalls.sh Remove iBCS2, part2: general kernel 2018-12-19 21:57:58 +00:00
md4c.c
md5c.c
msi_if.m
p1003_1b.c
pic_if.m
posix4_mib.c Use NULL for SYSINIT's last arg, which is a pointer type 2018-05-18 17:58:09 +00:00
sched_4bsd.c Create a new macro for static DPCPU data. 2018-07-05 17:13:37 +00:00
sched_ule.c Fix the long term ULE load balancer so that it actually works. The 2018-07-29 00:30:06 +00:00
serdev_if.m
stack_protector.c
subr_acl_nfs4.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
subr_acl_posix1e.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
subr_autoconf.c
subr_blist.c blst_leaf_alloc updates bighint for a leaf when an allocation is successful 2018-12-09 17:55:10 +00:00
subr_boot.c Create helper functions for parsing boot args. 2018-07-13 16:43:05 +00:00
subr_bufring.c
subr_bus_dma.c
subr_bus.c add support for marking interrupt handlers as suspended 2018-12-17 17:11:00 +00:00
subr_busdma_bufalloc.c Add malloc_domainset(9) and _domainset variants to other allocator KPIs. 2018-10-30 18:26:34 +00:00
subr_capability.c kern_sendit: use pre-initialized rights 2018-05-23 01:48:09 +00:00
subr_clock.c
subr_compressor.c Update to Zstandard 1.3.8 2018-12-29 21:18:01 +00:00
subr_counter.c Fix pre-SI_SUB_CPU initialization of per-CPU counters. 2018-07-10 00:18:12 +00:00
subr_devmap.c Raise the size of L3 table for early devmap on arm64 2018-07-19 21:58:06 +00:00
subr_devstat.c devstat(9): Constify function parameters that can be const 2018-08-23 01:42:45 +00:00
subr_disk.c Implement a 'car limit' for bioq. 2018-06-13 16:48:07 +00:00
subr_dummy_vdso_tc.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
subr_early.c Add a file missed in r339321 2018-10-12 00:32:45 +00:00
subr_epoch.c epoch(9) revert r340097 - no longer a need for multiple sections per cpu 2018-11-14 00:12:04 +00:00
subr_eventhandler.c Fix initialization of eventhandler mutex. 2018-03-19 22:43:27 +00:00
subr_fattime.c
subr_firmware.c
subr_gtaskqueue.c Drain grouptaskqueue of the gtask before detaching it. 2018-10-29 14:36:03 +00:00
subr_hash.c
subr_hints.c res_find: Fix fallback logic 2018-08-18 19:45:56 +00:00
subr_inflate.c There's two files in the sys tree named inflate.c, in addition 2018-07-13 17:41:28 +00:00
subr_intr.c
subr_kdb.c Always stop the scheduler when entering kdb 2018-10-30 14:54:15 +00:00
subr_kobj.c
subr_lock.c locks: tweak backoff a little bit 2018-04-08 16:34:10 +00:00
subr_log.c
subr_mchain.c
subr_module.c Have preload_delete_name() free pages backing preloaded data. 2018-07-19 20:00:28 +00:00
subr_msgbuf.c msgbuf: Light detailing (const'ify and bool'itize) 2018-08-09 17:42:27 +00:00
subr_param.c
subr_pcpu.c Ensure the DPCPU and VNET module spaces are aligned to hold a pointer. 2018-07-30 14:25:17 +00:00
subr_pctrie.c
subr_pidctrl.c When pidctrl_daemon() is called multiple times within an interval, it 2018-06-07 07:48:50 +00:00
subr_power.c
subr_prf.c Replace ttyprintf with sbuf_printf and tty drain routine 2018-10-20 18:31:36 +00:00
subr_prof.c ANSIfy sys/kern 2018-06-01 13:26:45 +00:00
subr_rman.c add support for marking interrupt handlers as suspended 2018-12-17 17:11:00 +00:00
subr_rtc.c Improve error messages from clock_if.m method failures. 2018-09-02 20:17:51 +00:00
subr_sbuf.c
subr_scanf.c
subr_sfbuf.c
subr_sglist.c
subr_sleepqueue.c turnstile / sleepqueue: annotate variables only used by debug builds 2018-05-19 05:00:16 +00:00
subr_smp.c Expose threads-per-core and physical core count information 2019-01-04 18:31:17 +00:00
subr_stack.c Add flags variants to linker_files / stack(9) symbol resolution 2018-10-20 18:08:43 +00:00
subr_syscall.c Deinline vfork handling out of the syscall return path. 2018-12-19 20:27:26 +00:00
subr_taskqueue.c Add a taskqueue_quiesce(9) KPI. 2018-11-21 17:18:27 +00:00
subr_terminal.c teken, vt(4): New callbacks to lock the terminal once 2018-05-16 09:01:02 +00:00
subr_trap.c Deinline racct throttling out of syscall exit path. 2018-11-29 05:08:46 +00:00
subr_turnstile.c Remove an unused argument to turnstile_unpend. 2018-06-02 22:37:53 +00:00
subr_uio.c simplify control flow so that gcc knows we never pass save to curthread_pflags_restore 2018-05-19 04:04:44 +00:00
subr_unit.c Implement unr64 2018-11-20 14:58:41 +00:00
subr_vmem.c Remove a redundant check. 2018-10-25 15:40:59 +00:00
subr_witness.c convert inpcbinfo hash and info rwlocks to epoch + mutex 2018-06-19 01:54:00 +00:00
sys_capability.c Let kern.trap_enotcap be set as a tunable. 2018-12-06 17:29:37 +00:00
sys_generic.c kern_poll: Restore explanatory comment removed in r177374 2018-11-01 23:46:23 +00:00
sys_getrandom.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
sys_pipe.c pipe: use unr64 2018-11-20 14:59:27 +00:00
sys_procdesc.c proc: always store parent pid in p_oppid 2018-11-16 17:07:54 +00:00
sys_process.c Add a missing definition for the !COMPAT_FREEBSD32 case. 2018-12-03 21:07:10 +00:00
sys_socket.c
syscalls.c Regen. 2018-12-07 15:19:00 +00:00
syscalls.master const poison the new pointer of __sysctl. 2018-12-18 12:44:38 +00:00
systrace_args.c Regen. 2018-12-07 15:19:00 +00:00
sysv_ipc.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
sysv_msg.c ANSIfy sys/kern 2018-06-01 13:26:45 +00:00
sysv_sem.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
sysv_shm.c Remove one-use variable. 2018-11-11 00:21:28 +00:00
tty_compat.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
tty_info.c Avoid fixing the tty_info() buffer size in tty.h. 2018-11-06 23:41:44 +00:00
tty_inq.c tty: use __unused annotation instead to silence warnings 2018-05-19 04:48:26 +00:00
tty_outq.c tty: use __unused annotation instead to silence warnings 2018-05-19 04:48:26 +00:00
tty_pts.c Move 32-bit compat support for FIODGNAME to the right place. 2018-10-26 17:59:25 +00:00
tty_tty.c
tty_ttydisc.c Replace ttyprintf with sbuf_printf and tty drain routine 2018-10-20 18:31:36 +00:00
tty.c Avoid fixing the tty_info() buffer size in tty.h. 2018-11-06 23:41:44 +00:00
uipc_accf.c
uipc_debug.c Load balance sockets with new SO_REUSEPORT_LB option. 2018-06-06 15:45:57 +00:00
uipc_domain.c
uipc_mbuf2.c
uipc_mbuf.c Add a SPD cache to speed up lookups. 2018-05-22 15:54:25 +00:00
uipc_mbufhash.c
uipc_mqueue.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
uipc_sem.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
uipc_shm.c Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
uipc_sockbuf.c Retire sbsndptr() KPI 2018-11-19 00:54:31 +00:00
uipc_socket.c Simplify sosetopt() so that function has single return point. No 2019-01-10 00:25:12 +00:00
uipc_syscalls.c Normalize COMPAT_43 syscall declarations. 2018-12-04 16:48:47 +00:00
uipc_usrreq.c Plug some networking sysctl leaks. 2018-11-22 20:49:41 +00:00
vfs_acl.c
vfs_aio.c vfs_aio.c: rename "physio" symbols to "bio". 2018-11-26 18:31:00 +00:00
vfs_bio.c Correct accuracy of the barrier writes accounting. 2018-12-02 12:53:39 +00:00
vfs_cache.c cache: retire cache_enter compat schim 2018-11-29 09:32:59 +00:00
vfs_cluster.c ANSIfy sys/kern 2018-06-01 13:26:45 +00:00
vfs_default.c Oops, rounddown() for the start was misspelled roundup() in r342295, 2018-12-22 09:31:55 +00:00
vfs_export.c Ensure that directory entry padding bytes are zeroed. 2018-11-23 22:24:59 +00:00
vfs_extattr.c
vfs_hash.c
vfs_init.c Only call sigdeferstop() for NFS. 2018-10-23 21:43:41 +00:00
vfs_lookup.c vfs: mostly depessimize NDINIT_ALL 2018-12-14 03:55:08 +00:00
vfs_mount.c Some filesystems (like cd9660 and ext3) require that VFS_STATFS() 2018-12-21 01:09:25 +00:00
vfs_mountroot.c Clarify panic in set_rootvnode(). 2018-12-15 19:18:58 +00:00
vfs_subr.c Avoid overfow in vtruncbuf() 2019-01-08 09:04:27 +00:00
vfs_syscalls.c style(9): fix the indent of a return. 2019-01-09 17:23:59 +00:00
vfs_vnops.c Implement O_BENEATH and AT_BENEATH. 2018-10-25 22:16:34 +00:00
vnode_if.src Make vop_symlink take a const target path. 2018-11-02 14:42:36 +00:00