18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# panic: Bad tailq NEXT(0xffffffff81cb0ba0->tqh_last) != NULL 48a272653SPeter Holm# cpuid = 0 58a272653SPeter Holm# time = 1605424954 68a272653SPeter Holm# KDB: stack backtrace: 78a272653SPeter Holm# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe010125c2e0 88a272653SPeter Holm# vpanic() at vpanic+0x182/frame 0xfffffe010125c330 98a272653SPeter Holm# panic() at panic+0x43/frame 0xfffffe010125c390 108a272653SPeter Holm# callout_process() at callout_process+0x34f/frame 0xfffffe010125c400 118a272653SPeter Holm# handleevents() at handleevents+0x185/frame 0xfffffe010125c440 128a272653SPeter Holm# timercb() at timercb+0x196/frame 0xfffffe010125c490 138a272653SPeter Holm# lapic_handle_timer() at lapic_handle_timer+0x9b/frame 0xfffffe010125c4c0 148a272653SPeter Holm# Xtimerint() at Xtimerint+0xb1/frame 0xfffffe010125c4c0 158a272653SPeter Holm# --- interrupt, rip = 0xffffffff80c56c69, rsp = 0xfffffe010125c590, rbp = 0xfffffe010125c5c0 --- 168a272653SPeter Holm# witness_unlock() at witness_unlock+0x79/frame 0xfffffe010125c5c0 178a272653SPeter Holm# __mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfffffe010125c5f0 188a272653SPeter Holm# kqueue_register() at kqueue_register+0x9e3/frame 0xfffffe010125c680 198a272653SPeter Holm# kqueue_kevent() at kqueue_kevent+0x106/frame 0xfffffe010125c950 208a272653SPeter Holm# kern_kevent_fp() at kern_kevent_fp+0x95/frame 0xfffffe010125c9a0 218a272653SPeter Holm# kern_kevent() at kern_kevent+0x80/frame 0xfffffe010125ca00 228a272653SPeter Holm# kern_kevent_generic() at kern_kevent_generic+0x70/frame 0xfffffe010125ca60 238a272653SPeter Holm# sys_kevent() at sys_kevent+0x61/frame 0xfffffe010125cac0 248a272653SPeter Holm# amd64_syscall() at amd64_syscall+0x144/frame 0xfffffe010125cbf0 258a272653SPeter Holm# fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe010125cbf0 268a272653SPeter Holm# --- syscall (0, FreeBSD ELF64, nosys), rip = 0x800380c6a, rsp = 0x7fffffffe4d8, rbp = 0x7fffffffe500 --- 278a272653SPeter Holm# KDB: enter: panic 288a272653SPeter Holm# [ thread pid 36082 tid 144846 ] 298a272653SPeter Holm# Stopped at kdb_enter+0x37: movq $0,0x10aa7f6(%rip) 308a272653SPeter Holm# db> x/s version 318a272653SPeter Holm# version: FreeBSD 13.0-CURRENT #0 r367672: Sat Nov 14 08:42:14 CET 2020 328a272653SPeter Holm# pho@t2.osted.lan:/usr/src/sys/amd64/compile/PHO 338a272653SPeter Holm# db> 348a272653SPeter Holm 358a272653SPeter Holm[ `uname -p` != "amd64" ] && exit 0 368a272653SPeter Holm 378a272653SPeter Holm# Fixed by r367849 388a272653SPeter Holm 398a272653SPeter Holm. ../default.cfg 408a272653SPeter Holmcat > /tmp/syzkaller27.c <<EOF 418a272653SPeter Holm// https://syzkaller.appspot.com/bug?id=6b64d673525304a89af91e0db71f2dee8e8da0f7 428a272653SPeter Holm// autogenerated by syzkaller (https://github.com/google/syzkaller) 438a272653SPeter Holm// Reported-by: syzbot+79569cd4d76636b2cc1c@syzkaller.appspotmail.com 448a272653SPeter Holm 458a272653SPeter Holm#define _GNU_SOURCE 468a272653SPeter Holm 478a272653SPeter Holm#include <sys/types.h> 488a272653SPeter Holm 498a272653SPeter Holm#include <pwd.h> 508a272653SPeter Holm#include <signal.h> 518a272653SPeter Holm#include <stdarg.h> 528a272653SPeter Holm#include <stdbool.h> 538a272653SPeter Holm#include <stdint.h> 548a272653SPeter Holm#include <stdio.h> 558a272653SPeter Holm#include <stdlib.h> 568a272653SPeter Holm#include <string.h> 578a272653SPeter Holm#include <sys/endian.h> 588a272653SPeter Holm#include <sys/syscall.h> 598a272653SPeter Holm#include <sys/wait.h> 608a272653SPeter Holm#include <time.h> 618a272653SPeter Holm#include <unistd.h> 628a272653SPeter Holm 638a272653SPeter Holmstatic void kill_and_wait(int pid, int* status) 648a272653SPeter Holm{ 658a272653SPeter Holm kill(pid, SIGKILL); 668a272653SPeter Holm while (waitpid(-1, status, 0) != pid) { 678a272653SPeter Holm } 688a272653SPeter Holm} 698a272653SPeter Holm 708a272653SPeter Holmstatic void sleep_ms(uint64_t ms) 718a272653SPeter Holm{ 728a272653SPeter Holm usleep(ms * 1000); 738a272653SPeter Holm} 748a272653SPeter Holm 758a272653SPeter Holmstatic uint64_t current_time_ms(void) 768a272653SPeter Holm{ 778a272653SPeter Holm struct timespec ts; 788a272653SPeter Holm if (clock_gettime(CLOCK_MONOTONIC, &ts)) 798a272653SPeter Holm exit(1); 808a272653SPeter Holm return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; 818a272653SPeter Holm} 828a272653SPeter Holm 838a272653SPeter Holmstatic void execute_one(void); 848a272653SPeter Holm 858a272653SPeter Holm#define WAIT_FLAGS 0 868a272653SPeter Holm 878a272653SPeter Holmstatic void loop(void) 888a272653SPeter Holm{ 89*7f658f99SPeter Holm int iter __unused = 0; 908a272653SPeter Holm for (;; iter++) { 918a272653SPeter Holm int pid = fork(); 928a272653SPeter Holm if (pid < 0) 938a272653SPeter Holm exit(1); 948a272653SPeter Holm if (pid == 0) { 958a272653SPeter Holm execute_one(); 968a272653SPeter Holm exit(0); 978a272653SPeter Holm } 988a272653SPeter Holm int status = 0; 998a272653SPeter Holm uint64_t start = current_time_ms(); 1008a272653SPeter Holm for (;;) { 1018a272653SPeter Holm if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) 1028a272653SPeter Holm break; 1038a272653SPeter Holm sleep_ms(1); 1048a272653SPeter Holm if (current_time_ms() - start < 5 * 1000) 1058a272653SPeter Holm continue; 1068a272653SPeter Holm kill_and_wait(pid, &status); 1078a272653SPeter Holm break; 1088a272653SPeter Holm } 1098a272653SPeter Holm } 1108a272653SPeter Holm} 1118a272653SPeter Holm 1128a272653SPeter Holmuint64_t r[1] = {0xffffffffffffffff}; 1138a272653SPeter Holm 1148a272653SPeter Holmvoid execute_one(void) 1158a272653SPeter Holm{ 1168a272653SPeter Holm intptr_t res = 0; 1178a272653SPeter Holm res = syscall(SYS_kqueue); 1188a272653SPeter Holm if (res != -1) 1198a272653SPeter Holm r[0] = res; 1208a272653SPeter Holm *(uint64_t*)0x200000c0 = 0; 1218a272653SPeter Holm *(uint16_t*)0x200000c8 = 0xfff9; 1228a272653SPeter Holm *(uint16_t*)0x200000ca = 0x4001; 1238a272653SPeter Holm *(uint32_t*)0x200000cc = 4; 1248a272653SPeter Holm *(uint64_t*)0x200000d0 = 0; 1258a272653SPeter Holm *(uint64_t*)0x200000d8 = 0; 1268a272653SPeter Holm *(uint64_t*)0x200000e0 = 0; 1278a272653SPeter Holm *(uint64_t*)0x200000e8 = 0; 1288a272653SPeter Holm *(uint64_t*)0x200000f0 = 0; 1298a272653SPeter Holm *(uint64_t*)0x200000f8 = 0; 1308a272653SPeter Holm syscall(SYS_kevent, r[0], 0x200000c0ul, 1ul, 0ul, 0ul, 0ul); 1318a272653SPeter Holm} 1328a272653SPeter Holmint main(void) 1338a272653SPeter Holm{ 1348a272653SPeter Holm sleep(2); /* pho */ 1358a272653SPeter Holm syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul); 1368a272653SPeter Holm loop(); 1378a272653SPeter Holm return 0; 1388a272653SPeter Holm} 1398a272653SPeter HolmEOF 1408a272653SPeter Holmmycc -o /tmp/syzkaller27 -Wall -Wextra -O0 /tmp/syzkaller27.c || 1418a272653SPeter Holm exit 1 1428a272653SPeter Holm 1438a272653SPeter Holm(cd ../testcases/swap; ./swap -t 1m -i 20 -h > /dev/null 2>&1) & 1448a272653SPeter Holmfor i in `jot 256`; do 1458a272653SPeter Holm (cd /tmp; timeout 3m ./syzkaller27) & 1468a272653SPeter Holmdone 1478a272653SPeter Holmwait 1488a272653SPeter Holm 1498a272653SPeter Holmrm -rf /tmp/syzkaller27 /tmp/syzkaller27.c /tmp/syzkaller.* 1508a272653SPeter Holmexit 0 151