xref: /freebsd/tools/test/stress2/misc/syzkaller7.sh (revision 8a272653d9fbd9fc37691c9aad6a05089b4ecb4d)
1*8a272653SPeter Holm#!/bin/sh
2*8a272653SPeter Holm
3*8a272653SPeter Holm# panic: Duplicate free of 0xfffff800049ad800 from zone
4*8a272653SPeter Holm# 0xfffff800041e82c0(mbuf) slab 0xfffff800049adf90(8)
5*8a272653SPeter Holm#
6*8a272653SPeter Holm# KDB: stack backtrace:
7*8a272653SPeter Holm# db_trace_self_wrapper() at db_trace_self_wrapper+0x47/frame
8*8a272653SPeter Holm# 0xfffffe0016b2c4a0
9*8a272653SPeter Holm# vpanic() at vpanic+0x1e0/frame 0xfffffe0016b2c500
10*8a272653SPeter Holm# panic() at panic+0x43/frame 0xfffffe0016b2c560
11*8a272653SPeter Holm# uma_dbg_free() at uma_dbg_free+0x246/frame 0xfffffe0016b2c5b0
12*8a272653SPeter Holm# uma_zfree_arg() at uma_zfree_arg+0x1aa/frame 0xfffffe0016b2c640
13*8a272653SPeter Holm# uipc_ready() at uipc_ready+0x19f/frame 0xfffffe0016b2c690
14*8a272653SPeter Holm# sendfile_iodone() at sendfile_iodone+0x342/frame 0xfffffe0016b2c6f0
15*8a272653SPeter Holm# vnode_pager_generic_getpages_done_async() at
16*8a272653SPeter Holm# vnode_pager_generic_getpages_done_async+0x4a/frame 0xfffffe0016b2c720
17*8a272653SPeter Holm# bufdone() at bufdone+0xa1/frame 0xfffffe0016b2c7a0
18*8a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c800
19*8a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c860
20*8a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c8c0
21*8a272653SPeter Holm# g_disk_done() at g_disk_done+0x179/frame 0xfffffe0016b2c910
22*8a272653SPeter Holm# dadone() at dadone+0x655/frame 0xfffffe0016b2c9a0
23*8a272653SPeter Holm# xpt_done_process() at xpt_done_process+0x5b2/frame 0xfffffe0016b2ca00
24*8a272653SPeter Holm# xpt_done_td() at xpt_done_td+0x175/frame 0xfffffe0016b2ca60
25*8a272653SPeter Holm# fork_exit() at fork_exit+0xb0/frame 0xfffffe0016b2cab0
26*8a272653SPeter Holm# fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0016b2cab0
27*8a272653SPeter Holm# --- trap 0, rip = 0, rsp = 0, rbp = 0 ---
28*8a272653SPeter Holm
29*8a272653SPeter Holm# Reproduced on r359769
30*8a272653SPeter Holm# Fixed by r359779
31*8a272653SPeter Holm
32*8a272653SPeter Holm[ `uname -p` = "i386" ] && exit 0
33*8a272653SPeter Holm
34*8a272653SPeter Holm. ../default.cfg
35*8a272653SPeter Holmcat > /tmp/syzkaller7.c <<EOF
36*8a272653SPeter Holm// https://syzkaller.appspot.com/bug?id=3a27f6d4656356facc22a9329be797ef1143d0ad
37*8a272653SPeter Holm// autogenerated by syzkaller (https://github.com/google/syzkaller)
38*8a272653SPeter Holm
39*8a272653SPeter Holm#define _GNU_SOURCE
40*8a272653SPeter Holm
41*8a272653SPeter Holm#include <sys/types.h>
42*8a272653SPeter Holm
43*8a272653SPeter Holm#include <pwd.h>
44*8a272653SPeter Holm#include <signal.h>
45*8a272653SPeter Holm#include <stdarg.h>
46*8a272653SPeter Holm#include <stdbool.h>
47*8a272653SPeter Holm#include <stdint.h>
48*8a272653SPeter Holm#include <stdio.h>
49*8a272653SPeter Holm#include <stdlib.h>
50*8a272653SPeter Holm#include <string.h>
51*8a272653SPeter Holm#include <sys/endian.h>
52*8a272653SPeter Holm#include <sys/syscall.h>
53*8a272653SPeter Holm#include <sys/wait.h>
54*8a272653SPeter Holm#include <time.h>
55*8a272653SPeter Holm#include <unistd.h>
56*8a272653SPeter Holm
57*8a272653SPeter Holmstatic void kill_and_wait(int pid, int* status)
58*8a272653SPeter Holm{
59*8a272653SPeter Holm  kill(pid, SIGKILL);
60*8a272653SPeter Holm  while (waitpid(-1, status, 0) != pid) {
61*8a272653SPeter Holm  }
62*8a272653SPeter Holm}
63*8a272653SPeter Holm
64*8a272653SPeter Holmstatic void sleep_ms(uint64_t ms)
65*8a272653SPeter Holm{
66*8a272653SPeter Holm  usleep(ms * 1000);
67*8a272653SPeter Holm}
68*8a272653SPeter Holm
69*8a272653SPeter Holmstatic uint64_t current_time_ms(void)
70*8a272653SPeter Holm{
71*8a272653SPeter Holm  struct timespec ts;
72*8a272653SPeter Holm  if (clock_gettime(CLOCK_MONOTONIC, &ts))
73*8a272653SPeter Holm    exit(1);
74*8a272653SPeter Holm  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
75*8a272653SPeter Holm}
76*8a272653SPeter Holm
77*8a272653SPeter Holmstatic void execute_one(void);
78*8a272653SPeter Holm
79*8a272653SPeter Holm#define WAIT_FLAGS 0
80*8a272653SPeter Holm
81*8a272653SPeter Holmstatic void loop(void)
82*8a272653SPeter Holm{
83*8a272653SPeter Holm  int iter;
84*8a272653SPeter Holm  for (iter = 0;; iter++) {
85*8a272653SPeter Holm    int pid = fork();
86*8a272653SPeter Holm    if (pid < 0)
87*8a272653SPeter Holm      exit(1);
88*8a272653SPeter Holm    if (pid == 0) {
89*8a272653SPeter Holm      execute_one();
90*8a272653SPeter Holm      exit(0);
91*8a272653SPeter Holm    }
92*8a272653SPeter Holm    int status = 0;
93*8a272653SPeter Holm    uint64_t start = current_time_ms();
94*8a272653SPeter Holm    for (;;) {
95*8a272653SPeter Holm      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
96*8a272653SPeter Holm        break;
97*8a272653SPeter Holm      sleep_ms(1);
98*8a272653SPeter Holm      if (current_time_ms() - start < 5 * 1000)
99*8a272653SPeter Holm        continue;
100*8a272653SPeter Holm      kill_and_wait(pid, &status);
101*8a272653SPeter Holm      break;
102*8a272653SPeter Holm    }
103*8a272653SPeter Holm  }
104*8a272653SPeter Holm}
105*8a272653SPeter Holm
106*8a272653SPeter Holmuint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
107*8a272653SPeter Holm                 0xffffffffffffffff, 0xffffffffffffffff};
108*8a272653SPeter Holm
109*8a272653SPeter Holmvoid execute_one(void)
110*8a272653SPeter Holm{
111*8a272653SPeter Holm  long res = 0;
112*8a272653SPeter Holm  memcpy((void*)0x20001180, "./file0\000", 8);
113*8a272653SPeter Holm  res = syscall(SYS_open, 0x20001180, 0x8240, 0);
114*8a272653SPeter Holm  if (res != -1)
115*8a272653SPeter Holm    r[0] = res;
116*8a272653SPeter Holm  res = syscall(SYS_socketpair, 1, 1, 0, 0x20000100);
117*8a272653SPeter Holm  if (res != -1) {
118*8a272653SPeter Holm    r[1] = *(uint32_t*)0x20000100;
119*8a272653SPeter Holm    r[2] = *(uint32_t*)0x20000104;
120*8a272653SPeter Holm  }
121*8a272653SPeter Holm  memcpy((void*)0x20000480, "./file0\000", 8);
122*8a272653SPeter Holm  res = syscall(SYS_open, 0x20000480, 0x80000000000206, 0);
123*8a272653SPeter Holm  if (res != -1)
124*8a272653SPeter Holm    r[3] = res;
125*8a272653SPeter Holm  res = syscall(SYS_dup, r[3]);
126*8a272653SPeter Holm  if (res != -1)
127*8a272653SPeter Holm    r[4] = res;
128*8a272653SPeter Holm  *(uint64_t*)0x20000100 = 0x200002c0;
129*8a272653SPeter Holm  memcpy((void*)0x200002c0, "\xdd", 1);
130*8a272653SPeter Holm  *(uint64_t*)0x20000108 = 1;
131*8a272653SPeter Holm  syscall(SYS_pwritev, r[4], 0x20000100, 1, 0);
132*8a272653SPeter Holm  *(uint64_t*)0x20002e80 = 0x20000540;
133*8a272653SPeter Holm  memcpy((void*)0x20000540, "\x7f", 1);
134*8a272653SPeter Holm  *(uint64_t*)0x20002e88 = 1;
135*8a272653SPeter Holm  syscall(SYS_pwritev, r[3], 0x20002e80, 1, 0xbf24);
136*8a272653SPeter Holm  memcpy((void*)0x200004c0,
137*8a272653SPeter Holm         "\x89\x88\xaa\x4a\xc3\x95\x23\x77\x54\xee\x66\xf3\x8d\xa4\xae\xf3\x47"
138*8a272653SPeter Holm         "\x6d\x78\xb7\x1f\xe6\x0d\xb7\x4a\x9f\xb9\xc9\x99\x91\x6c\x98",
139*8a272653SPeter Holm         32);
140*8a272653SPeter Holm  syscall(SYS_setsockopt, r[2], 0, 2, 0x200004c0, 0x20);
141*8a272653SPeter Holm  syscall(SYS_fcntl, r[4], 4, 0x10044);
142*8a272653SPeter Holm  syscall(SYS_read, r[4], 0x20000000, 0x6d999);
143*8a272653SPeter Holm  syscall(SYS_sendfile, r[0], r[1], 0, 2);
144*8a272653SPeter Holm}
145*8a272653SPeter Holmint main(void)
146*8a272653SPeter Holm{
147*8a272653SPeter Holm  syscall(SYS_mmap, 0x20000000, 0x1000000, 3, 0x1012, -1, 0ul);
148*8a272653SPeter Holm  loop();
149*8a272653SPeter Holm  return 0;
150*8a272653SPeter Holm}
151*8a272653SPeter HolmEOF
152*8a272653SPeter Holmmycc -o /tmp/syzkaller7 -Wall -Wextra -O2 /tmp/syzkaller7.c -lpthread ||
153*8a272653SPeter Holm    exit 1
154*8a272653SPeter Holm
155*8a272653SPeter Holm(cd /tmp; timeout 5m ./syzkaller7) &
156*8a272653SPeter Holmsleep 60
157*8a272653SPeter Holmwhile pkill -9 syzkaller7; do :; done
158*8a272653SPeter Holmwait
159*8a272653SPeter Holm
160*8a272653SPeter Holmrm -f /tmp/syzkaller7 /tmp/syzkaller7.c /tmp/syzkaller7.core /tmp/file0
161*8a272653SPeter Holmexit 0
162