From owner-svn-src-all@freebsd.org Fri Sep 4 00:12:29 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A9D2D3CFDE0; Fri, 4 Sep 2020 00:12:29 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BjJ5n43qrz4FH3; Fri, 4 Sep 2020 00:12:29 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6EB4D2400E; Fri, 4 Sep 2020 00:12:29 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0840CT9i024202; Fri, 4 Sep 2020 00:12:29 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0840CSfD024198; Fri, 4 Sep 2020 00:12:28 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202009040012.0840CSfD024198@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 4 Sep 2020 00:12:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365319 - in head/sys/compat: lindebugfs linsysfs linux X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in head/sys/compat: lindebugfs linsysfs linux X-SVN-Commit-Revision: 365319 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2020 00:12:29 -0000 Author: markj Date: Fri Sep 4 00:12:28 2020 New Revision: 365319 URL: https://svnweb.freebsd.org/changeset/base/365319 Log: Add emulation support for the Linux kcov(4) ioctl API. This makes it possible to run an unmodified Linux syzkaller executor against the Linuxulator, and have it gather code coverage information. Sponsored by: The FreeBSD Foundation Modified: head/sys/compat/lindebugfs/lindebugfs.c head/sys/compat/linsysfs/linsysfs.c head/sys/compat/linux/linux_ioctl.c head/sys/compat/linux/linux_ioctl.h Modified: head/sys/compat/lindebugfs/lindebugfs.c ============================================================================== --- head/sys/compat/lindebugfs/lindebugfs.c Fri Sep 4 00:11:01 2020 (r365318) +++ head/sys/compat/lindebugfs/lindebugfs.c Fri Sep 4 00:12:28 2020 (r365319) @@ -299,6 +299,9 @@ debugfs_init(PFS_INIT_ARGS) { debugfs_root = pi->pi_root; + + (void)debugfs_create_symlink("kcov", NULL, "/dev/kcov"); + return (0); } Modified: head/sys/compat/linsysfs/linsysfs.c ============================================================================== --- head/sys/compat/linsysfs/linsysfs.c Fri Sep 4 00:11:01 2020 (r365318) +++ head/sys/compat/linsysfs/linsysfs.c Fri Sep 4 00:12:28 2020 (r365319) @@ -624,6 +624,8 @@ linsysfs_init(PFS_INIT_ARGS) struct pfs_node *net; struct pfs_node *power_supply; struct pfs_node *devdir, *chardev; + struct pfs_node *kernel; + struct pfs_node *debug; devclass_t devclass; device_t dev; @@ -671,6 +673,11 @@ linsysfs_init(PFS_INIT_ARGS) linsysfs_listcpus(cpu); linsysfs_listnics(net); + + /* /sys/kernel */ + kernel = pfs_create_dir(root, "kernel", NULL, NULL, NULL, 0); + /* /sys/kernel/debug, mountpoint for lindebugfs. */ + debug = pfs_create_dir(kernel, "debug", NULL, NULL, NULL, 0); return (0); } Modified: head/sys/compat/linux/linux_ioctl.c ============================================================================== --- head/sys/compat/linux/linux_ioctl.c Fri Sep 4 00:11:01 2020 (r365318) +++ head/sys/compat/linux/linux_ioctl.c Fri Sep 4 00:12:28 2020 (r365319) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -117,6 +118,7 @@ static linux_ioctl_function_t linux_ioctl_v4l2; static linux_ioctl_function_t linux_ioctl_special; static linux_ioctl_function_t linux_ioctl_fbsd_usb; static linux_ioctl_function_t linux_ioctl_evdev; +static linux_ioctl_function_t linux_ioctl_kcov; static struct linux_ioctl_handler cdrom_handler = { linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX }; @@ -146,6 +148,8 @@ static struct linux_ioctl_handler fbsd_usb = { linux_ioctl_fbsd_usb, FBSD_LUSB_MIN, FBSD_LUSB_MAX }; static struct linux_ioctl_handler evdev_handler = { linux_ioctl_evdev, LINUX_IOCTL_EVDEV_MIN, LINUX_IOCTL_EVDEV_MAX }; +static struct linux_ioctl_handler kcov_handler = +{ linux_ioctl_kcov, LINUX_KCOV_MIN, LINUX_KCOV_MAX }; DATA_SET(linux_ioctl_handler_set, cdrom_handler); DATA_SET(linux_ioctl_handler_set, vfat_handler); @@ -161,6 +165,7 @@ DATA_SET(linux_ioctl_handler_set, video_handler); DATA_SET(linux_ioctl_handler_set, video2_handler); DATA_SET(linux_ioctl_handler_set, fbsd_usb); DATA_SET(linux_ioctl_handler_set, evdev_handler); +DATA_SET(linux_ioctl_handler_set, kcov_handler); /* * Keep sorted by low. @@ -3570,6 +3575,38 @@ linux_ioctl_evdev(struct thread *td, struct linux_ioct args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_INOUT; return (sys_ioctl(td, (struct ioctl_args *)args)); +} + +static int +linux_ioctl_kcov(struct thread *td, struct linux_ioctl_args *args) +{ + int error; + + error = 0; + switch (args->cmd & 0xffff) { + case LINUX_KCOV_INIT_TRACE: + args->cmd = KIOSETBUFSIZE; + break; + case LINUX_KCOV_ENABLE: + args->cmd = KIOENABLE; + if (args->arg == 0) + args->arg = KCOV_MODE_TRACE_PC; + else if (args->arg == 1) + args->arg = KCOV_MODE_TRACE_CMP; + else + error = EINVAL; + break; + case LINUX_KCOV_DISABLE: + args->cmd = KIODISABLE; + break; + default: + error = ENOTTY; + break; + } + + if (error == 0) + error = sys_ioctl(td, (struct ioctl_args *)args); + return (error); } /* Modified: head/sys/compat/linux/linux_ioctl.h ============================================================================== --- head/sys/compat/linux/linux_ioctl.h Fri Sep 4 00:11:01 2020 (r365318) +++ head/sys/compat/linux/linux_ioctl.h Fri Sep 4 00:12:28 2020 (r365319) @@ -762,6 +762,17 @@ #define LINUX_IOCTL_EVDEV_MAX 0x45ff #define LINUX_IOCTL_EVDEV_CLK LINUX_CLOCK_REALTIME | \ LINUX_CLOCK_MONOTONIC |LINUX_CLOCK_BOOTTIME + +/* + * kcov(4) shims + */ +#define LINUX_KCOV_MIN 0x6300 +#define LINUX_KCOV_MAX 0x63ff +#define LINUX_KCOV_INIT_TRACE 0x6301 +#define LINUX_KCOV_ENABLE 0x6364 +#define LINUX_KCOV_DISABLE 0x6365 +#define LINUX_KCOV_REMOTE_ENABLE 0x6366 + /* * Pluggable ioctl handlers */