From owner-svn-src-user@freebsd.org Sun Jun 7 12:15:42 2020 Return-Path: Delivered-To: svn-src-user@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 5A8C3329D20 for ; Sun, 7 Jun 2020 12:15:42 +0000 (UTC) (envelope-from pho@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 49fwML1gtqz4bB3; Sun, 7 Jun 2020 12:15:42 +0000 (UTC) (envelope-from pho@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 3461C12FDC; Sun, 7 Jun 2020 12:15:42 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 057CFgwi046297; Sun, 7 Jun 2020 12:15:42 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 057CFgsI046296; Sun, 7 Jun 2020 12:15:42 GMT (envelope-from pho@FreeBSD.org) Message-Id: <202006071215.057CFgsI046296@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Sun, 7 Jun 2020 12:15:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r361890 - user/pho/stress2/misc X-SVN-Group: user X-SVN-Commit-Author: pho X-SVN-Commit-Paths: user/pho/stress2/misc X-SVN-Commit-Revision: 361890 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2020 12:15:42 -0000 Author: pho Date: Sun Jun 7 12:15:41 2020 New Revision: 361890 URL: https://svnweb.freebsd.org/changeset/base/361890 Log: Added a syzkaller reproducer. Added: user/pho/stress2/misc/syzkaller13.sh (contents, props changed) Added: user/pho/stress2/misc/syzkaller13.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/syzkaller13.sh Sun Jun 7 12:15:41 2020 (r361890) @@ -0,0 +1,249 @@ +#!/bin/sh + +# Kernel page fault with the following non-sleepable locks held: +# exclusive sleep mutex so_rcv (so_rcv) r = 0 (0xfffffe012b5ee300) locked @ kern/uipc_usrreq.c:1272 +# exclusive sleep mutex socket (socket) r = 0 (0xfffffe012b5ee1a8) locked @ kern/uipc_usrreq.c:1265 +# shared rw unp_link_rwlock (unp_link_rwlock) r = 0 (0xffffffff81d99640) locked @ kern/uipc_usrreq.c:1334 +# stack backtrace: +# #0 0xffffffff80c35701 at witness_debugger+0x71 +# #1 0xffffffff80c3669d at witness_warn+0x40d +# #2 0xffffffff8106fb90 at trap_pfault+0x80 +# #3 0xffffffff8106f1a5 at trap+0x2a5 +# #4 0xffffffff810450d8 at calltrap+0x8 +# #5 0xffffffff80bc6fcc at sendfile_iodone+0x1ac +# #6 0xffffffff80f3d98a at vnode_pager_generic_getpages_done_async+0x3a +# #7 0xffffffff80c8236c at bufdone+0x6c +# #8 0xffffffff80b0c06e at g_io_deliver+0x25e +# #9 0xffffffff80b0c06e at g_io_deliver+0x25e +# #10 0xffffffff80b08dfd at g_disk_done+0xed +# #11 0xffffffff803ac1f3 at dadone+0x603 +# #12 0xffffffff8037ddf2 at xpt_done_process+0x382 +# #13 0xffffffff8037fdb5 at xpt_done_td+0xf5 +# #14 0xffffffff80b85b10 at fork_exit+0x80 +# #15 0xffffffff8104611e at fork_trampoline+0xe +# +# +# Fatal trap 12: page fault while in kernel mode +# cpuid = 23; apic id = 2b +# fault virtual address = 0x8 +# fault code = supervisor read data, page not present +# instruction pointer = 0x20:0xffffffff80c74bc0 +# stack pointer = 0x0:0xfffffe0126b118e0 +# frame pointer = 0x0:0xfffffe0126b11920 +# code segment = base 0x0, limit 0xfffff, type 0x1b +# = DPL 0, pres 1, long 1, def32 0, gran 1 +# processor eflags = interrupt enabled, resume, IOPL = 0 +# current process = 32 (doneq0) +# trap number = 12 +# panic: page fault +# cpuid = 23 +# time = 1591531029 +# KDB: stack backtrace: +# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0126b11590 +# vpanic() at vpanic+0x182/frame 0xfffffe0126b115e0 +# panic() at panic+0x43/frame 0xfffffe0126b11640 +# trap_fatal() at trap_fatal+0x387/frame 0xfffffe0126b116a0 +# trap_pfault() at trap_pfault+0x99/frame 0xfffffe0126b11700 +# trap() at trap+0x2a5/frame 0xfffffe0126b11810 +# calltrap() at calltrap+0x8/frame 0xfffffe0126b11810 +# --- trap 0xc, rip = 0xffffffff80c74bc0, rsp = 0xfffffe0126b118e0, rbp = 0xfffffe0126b11920 --- +# uipc_ready() at uipc_ready+0x1f0/frame 0xfffffe0126b11920 +# sendfile_iodone() at sendfile_iodone+0x1ac/frame 0xfffffe0126b11960 +# vnode_pager_generic_getpages_done_async() at vnode_pager_generic_getpages_done_async+0x3a/frame 0xfffffe0126b11980 +# bufdone() at bufdone+0x6c/frame 0xfffffe0126b119f0 +# g_io_deliver() at g_io_deliver+0x25e/frame 0xfffffe0126b11a40 +# g_io_deliver() at g_io_deliver+0x25e/frame 0xfffffe0126b11a90 +# g_disk_done() at g_disk_done+0xed/frame 0xfffffe0126b11ad0 +# dadone() at dadone+0x603/frame 0xfffffe0126b11b20 +# xpt_done_process() at xpt_done_process+0x382/frame 0xfffffe0126b11b60 +# xpt_done_td() at xpt_done_td+0xf5/frame 0xfffffe0126b11bb0 +# fork_exit() at fork_exit+0x80/frame 0xfffffe0126b11bf0 +# fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0126b11bf0 +# --- trap 0, rip = 0, rsp = 0, rbp = 0 --- +# KDB: enter: panic +# [ thread pid 32 tid 100163 ] +# Stopped at kdb_enter+0x37: movq $0,0x10c72c6(%rip) +# db> + +# $FreeBSD$ + +# Reproduced on r361889 + +[ `uname -p` = "i386" ] && exit 0 + +. ../default.cfg +cat > /tmp/syzkaller13.c < + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned long long procid; + +static void kill_and_wait(int pid, int* status) +{ + kill(pid, SIGKILL); + while (waitpid(-1, status, 0) != pid) { + } +} + +static void sleep_ms(uint64_t ms) +{ + usleep(ms * 1000); +} + +static uint64_t current_time_ms(void) +{ + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts)) + exit(1); + return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; +} + +static void use_temporary_dir(void) +{ + char tmpdir_template[] = "./syzkaller.XXXXXX"; + char* tmpdir = mkdtemp(tmpdir_template); + if (!tmpdir) + exit(1); + if (chmod(tmpdir, 0777)) + exit(1); + if (chdir(tmpdir)) + exit(1); +} + +static void remove_dir(const char* dir) +{ + DIR* dp; + struct dirent* ep; + dp = opendir(dir); + if (dp == NULL) + exit(1); + while ((ep = readdir(dp))) { + if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) + continue; + char filename[FILENAME_MAX]; + snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); + struct stat st; + if (lstat(filename, &st)) + exit(1); + if (S_ISDIR(st.st_mode)) { + remove_dir(filename); + continue; + } + if (unlink(filename)) + exit(1); + } + closedir(dp); + if (rmdir(dir)) + exit(1); +} + +static void execute_one(void); + +#define WAIT_FLAGS 0 + +static void loop(void) +{ + int iter; + for (iter = 0;; iter++) { + char cwdbuf[32]; + sprintf(cwdbuf, "./%d", iter); + if (mkdir(cwdbuf, 0777)) + exit(1); + int pid = fork(); + if (pid < 0) + exit(1); + if (pid == 0) { + if (chdir(cwdbuf)) + exit(1); + execute_one(); + exit(0); + } + int status = 0; + uint64_t start = current_time_ms(); + for (;;) { + if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) + break; + sleep_ms(1); + if (current_time_ms() - start < 5 * 1000) + continue; + kill_and_wait(pid, &status); + break; + } + remove_dir(cwdbuf); + } +} + +uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, + 0xffffffffffffffff, 0xffffffffffffffff}; + +void execute_one(void) +{ + intptr_t res = 0; + memcpy((void*)0x20000100, "./file0\000", 8); + res = syscall(SYS_open, 0x20000100ul, 0x40000400000002c2ul, 0ul); + if (res != -1) + r[0] = res; + syscall(SYS_fcntl, r[0], 4ul, 0x10048ul); + *(uint64_t*)0x20000340 = 0x20000180; + *(uint64_t*)0x20000348 = 0x81700; + syscall(SYS_writev, r[0], 0x20000340ul, 0x1000000000000013ul); + res = syscall(SYS_socket, 2ul, 2ul, 0x88); + if (res != -1) + r[1] = res; + res = syscall(SYS_socketpair, 1ul, 1ul, 0, 0x20000000ul); + if (res != -1) + r[2] = *(uint32_t*)0x20000000; + res = syscall(SYS_dup2, r[2], r[1]); + if (res != -1) + r[3] = res; + memcpy((void*)0x20000140, "./file0\000", 8); + res = syscall(SYS_open, 0x20000140ul, 0ul, 0ul); + if (res != -1) + r[4] = res; + syscall(SYS_sendfile, r[4], r[3], 0ul, 1ul, 0ul, 0ul, 0ul); +} +int main(void) +{ + syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul); + for (procid = 0; procid < 4; procid++) { + if (fork() == 0) { + use_temporary_dir(); + loop(); + } + } + sleep(1000000); + return 0; +} +EOF +mycc -o /tmp/syzkaller13 -Wall -Wextra -O2 /tmp/syzkaller13.c -lpthread || + exit 1 + +(cd ../testcases/swap; ./swap -t 1m -i 20 -h > /dev/null 2>&1) & +(cd /tmp; ./syzkaller13) & +sleep 60 +pkill -9 syzkaller13 swap +wait + +rm -f /tmp/syzkaller13 /tmp/syzkaller13.c /tmp/syzkaller13.core /tmp/file0 +exit 0