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