xref: /freebsd/tools/test/stress2/misc/syzkaller27.sh (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1#!/bin/sh
2
3# panic: Bad tailq NEXT(0xffffffff81cb0ba0->tqh_last) != NULL
4# cpuid = 0
5# time = 1605424954
6# KDB: stack backtrace:
7# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe010125c2e0
8# vpanic() at vpanic+0x182/frame 0xfffffe010125c330
9# panic() at panic+0x43/frame 0xfffffe010125c390
10# callout_process() at callout_process+0x34f/frame 0xfffffe010125c400
11# handleevents() at handleevents+0x185/frame 0xfffffe010125c440
12# timercb() at timercb+0x196/frame 0xfffffe010125c490
13# lapic_handle_timer() at lapic_handle_timer+0x9b/frame 0xfffffe010125c4c0
14# Xtimerint() at Xtimerint+0xb1/frame 0xfffffe010125c4c0
15# --- interrupt, rip = 0xffffffff80c56c69, rsp = 0xfffffe010125c590, rbp = 0xfffffe010125c5c0 ---
16# witness_unlock() at witness_unlock+0x79/frame 0xfffffe010125c5c0
17# __mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfffffe010125c5f0
18# kqueue_register() at kqueue_register+0x9e3/frame 0xfffffe010125c680
19# kqueue_kevent() at kqueue_kevent+0x106/frame 0xfffffe010125c950
20# kern_kevent_fp() at kern_kevent_fp+0x95/frame 0xfffffe010125c9a0
21# kern_kevent() at kern_kevent+0x80/frame 0xfffffe010125ca00
22# kern_kevent_generic() at kern_kevent_generic+0x70/frame 0xfffffe010125ca60
23# sys_kevent() at sys_kevent+0x61/frame 0xfffffe010125cac0
24# amd64_syscall() at amd64_syscall+0x144/frame 0xfffffe010125cbf0
25# fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe010125cbf0
26# --- syscall (0, FreeBSD ELF64, nosys), rip = 0x800380c6a, rsp = 0x7fffffffe4d8, rbp = 0x7fffffffe500 ---
27# KDB: enter: panic
28# [ thread pid 36082 tid 144846 ]
29# Stopped at      kdb_enter+0x37: movq    $0,0x10aa7f6(%rip)
30# db> x/s version
31# version:        FreeBSD 13.0-CURRENT #0 r367672: Sat Nov 14 08:42:14 CET 2020
32# pho@t2.osted.lan:/usr/src/sys/amd64/compile/PHO
33# db>
34
35[ `uname -p` != "amd64" ] && exit 0
36
37# Fixed by r367849
38
39. ../default.cfg
40cat > /tmp/syzkaller27.c <<EOF
41// https://syzkaller.appspot.com/bug?id=6b64d673525304a89af91e0db71f2dee8e8da0f7
42// autogenerated by syzkaller (https://github.com/google/syzkaller)
43// Reported-by: syzbot+79569cd4d76636b2cc1c@syzkaller.appspotmail.com
44
45#define _GNU_SOURCE
46
47#include <sys/types.h>
48
49#include <pwd.h>
50#include <signal.h>
51#include <stdarg.h>
52#include <stdbool.h>
53#include <stdint.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <sys/endian.h>
58#include <sys/syscall.h>
59#include <sys/wait.h>
60#include <time.h>
61#include <unistd.h>
62
63static void kill_and_wait(int pid, int* status)
64{
65  kill(pid, SIGKILL);
66  while (waitpid(-1, status, 0) != pid) {
67  }
68}
69
70static void sleep_ms(uint64_t ms)
71{
72  usleep(ms * 1000);
73}
74
75static uint64_t current_time_ms(void)
76{
77  struct timespec ts;
78  if (clock_gettime(CLOCK_MONOTONIC, &ts))
79    exit(1);
80  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
81}
82
83static void execute_one(void);
84
85#define WAIT_FLAGS 0
86
87static void loop(void)
88{
89  int iter __unused = 0;
90  for (;; iter++) {
91    int pid = fork();
92    if (pid < 0)
93      exit(1);
94    if (pid == 0) {
95      execute_one();
96      exit(0);
97    }
98    int status = 0;
99    uint64_t start = current_time_ms();
100    for (;;) {
101      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
102        break;
103      sleep_ms(1);
104      if (current_time_ms() - start < 5 * 1000)
105        continue;
106      kill_and_wait(pid, &status);
107      break;
108    }
109  }
110}
111
112uint64_t r[1] = {0xffffffffffffffff};
113
114void execute_one(void)
115{
116  intptr_t res = 0;
117  res = syscall(SYS_kqueue);
118  if (res != -1)
119    r[0] = res;
120  *(uint64_t*)0x200000c0 = 0;
121  *(uint16_t*)0x200000c8 = 0xfff9;
122  *(uint16_t*)0x200000ca = 0x4001;
123  *(uint32_t*)0x200000cc = 4;
124  *(uint64_t*)0x200000d0 = 0;
125  *(uint64_t*)0x200000d8 = 0;
126  *(uint64_t*)0x200000e0 = 0;
127  *(uint64_t*)0x200000e8 = 0;
128  *(uint64_t*)0x200000f0 = 0;
129  *(uint64_t*)0x200000f8 = 0;
130  syscall(SYS_kevent, r[0], 0x200000c0ul, 1ul, 0ul, 0ul, 0ul);
131}
132int main(void)
133{
134  sleep(2);	/* pho */
135  syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul);
136  loop();
137  return 0;
138}
139EOF
140mycc -o /tmp/syzkaller27 -Wall -Wextra -O0 /tmp/syzkaller27.c ||
141    exit 1
142
143(cd ../testcases/swap; ./swap -t 1m -i 20 -h > /dev/null 2>&1) &
144for i in `jot 256`; do
145	(cd /tmp; timeout 3m ./syzkaller27) &
146done
147wait
148
149rm -rf /tmp/syzkaller27 /tmp/syzkaller27.c /tmp/syzkaller.*
150exit 0
151