xref: /freebsd/tools/test/stress2/misc/syzkaller7.sh (revision 7f658f99f7ed5d1d0e0802073bb22eb8a0a784fb)
18a272653SPeter Holm#!/bin/sh
28a272653SPeter Holm
38a272653SPeter Holm# panic: Duplicate free of 0xfffff800049ad800 from zone
48a272653SPeter Holm# 0xfffff800041e82c0(mbuf) slab 0xfffff800049adf90(8)
58a272653SPeter Holm#
68a272653SPeter Holm# KDB: stack backtrace:
78a272653SPeter Holm# db_trace_self_wrapper() at db_trace_self_wrapper+0x47/frame
88a272653SPeter Holm# 0xfffffe0016b2c4a0
98a272653SPeter Holm# vpanic() at vpanic+0x1e0/frame 0xfffffe0016b2c500
108a272653SPeter Holm# panic() at panic+0x43/frame 0xfffffe0016b2c560
118a272653SPeter Holm# uma_dbg_free() at uma_dbg_free+0x246/frame 0xfffffe0016b2c5b0
128a272653SPeter Holm# uma_zfree_arg() at uma_zfree_arg+0x1aa/frame 0xfffffe0016b2c640
138a272653SPeter Holm# uipc_ready() at uipc_ready+0x19f/frame 0xfffffe0016b2c690
148a272653SPeter Holm# sendfile_iodone() at sendfile_iodone+0x342/frame 0xfffffe0016b2c6f0
158a272653SPeter Holm# vnode_pager_generic_getpages_done_async() at
168a272653SPeter Holm# vnode_pager_generic_getpages_done_async+0x4a/frame 0xfffffe0016b2c720
178a272653SPeter Holm# bufdone() at bufdone+0xa1/frame 0xfffffe0016b2c7a0
188a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c800
198a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c860
208a272653SPeter Holm# g_io_deliver() at g_io_deliver+0x35b/frame 0xfffffe0016b2c8c0
218a272653SPeter Holm# g_disk_done() at g_disk_done+0x179/frame 0xfffffe0016b2c910
228a272653SPeter Holm# dadone() at dadone+0x655/frame 0xfffffe0016b2c9a0
238a272653SPeter Holm# xpt_done_process() at xpt_done_process+0x5b2/frame 0xfffffe0016b2ca00
248a272653SPeter Holm# xpt_done_td() at xpt_done_td+0x175/frame 0xfffffe0016b2ca60
258a272653SPeter Holm# fork_exit() at fork_exit+0xb0/frame 0xfffffe0016b2cab0
268a272653SPeter Holm# fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0016b2cab0
278a272653SPeter Holm# --- trap 0, rip = 0, rsp = 0, rbp = 0 ---
288a272653SPeter Holm
298a272653SPeter Holm# Reproduced on r359769
308a272653SPeter Holm# Fixed by r359779
318a272653SPeter Holm
328a272653SPeter Holm[ `uname -p` = "i386" ] && exit 0
338a272653SPeter Holm
348a272653SPeter Holm. ../default.cfg
358a272653SPeter Holmcat > /tmp/syzkaller7.c <<EOF
368a272653SPeter Holm// https://syzkaller.appspot.com/bug?id=3a27f6d4656356facc22a9329be797ef1143d0ad
378a272653SPeter Holm// autogenerated by syzkaller (https://github.com/google/syzkaller)
388a272653SPeter Holm
398a272653SPeter Holm#define _GNU_SOURCE
408a272653SPeter Holm
418a272653SPeter Holm#include <sys/types.h>
428a272653SPeter Holm
438a272653SPeter Holm#include <pwd.h>
448a272653SPeter Holm#include <signal.h>
458a272653SPeter Holm#include <stdarg.h>
468a272653SPeter Holm#include <stdbool.h>
478a272653SPeter Holm#include <stdint.h>
488a272653SPeter Holm#include <stdio.h>
498a272653SPeter Holm#include <stdlib.h>
508a272653SPeter Holm#include <string.h>
518a272653SPeter Holm#include <sys/endian.h>
528a272653SPeter Holm#include <sys/syscall.h>
538a272653SPeter Holm#include <sys/wait.h>
548a272653SPeter Holm#include <time.h>
558a272653SPeter Holm#include <unistd.h>
568a272653SPeter Holm
578a272653SPeter Holmstatic void kill_and_wait(int pid, int* status)
588a272653SPeter Holm{
598a272653SPeter Holm  kill(pid, SIGKILL);
608a272653SPeter Holm  while (waitpid(-1, status, 0) != pid) {
618a272653SPeter Holm  }
628a272653SPeter Holm}
638a272653SPeter Holm
648a272653SPeter Holmstatic void sleep_ms(uint64_t ms)
658a272653SPeter Holm{
668a272653SPeter Holm  usleep(ms * 1000);
678a272653SPeter Holm}
688a272653SPeter Holm
698a272653SPeter Holmstatic uint64_t current_time_ms(void)
708a272653SPeter Holm{
718a272653SPeter Holm  struct timespec ts;
728a272653SPeter Holm  if (clock_gettime(CLOCK_MONOTONIC, &ts))
738a272653SPeter Holm    exit(1);
748a272653SPeter Holm  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
758a272653SPeter Holm}
768a272653SPeter Holm
778a272653SPeter Holmstatic void execute_one(void);
788a272653SPeter Holm
798a272653SPeter Holm#define WAIT_FLAGS 0
808a272653SPeter Holm
818a272653SPeter Holmstatic void loop(void)
828a272653SPeter Holm{
83*7f658f99SPeter Holm  int iter __unused;
848a272653SPeter Holm  for (iter = 0;; iter++) {
858a272653SPeter Holm    int pid = fork();
868a272653SPeter Holm    if (pid < 0)
878a272653SPeter Holm      exit(1);
888a272653SPeter Holm    if (pid == 0) {
898a272653SPeter Holm      execute_one();
908a272653SPeter Holm      exit(0);
918a272653SPeter Holm    }
928a272653SPeter Holm    int status = 0;
938a272653SPeter Holm    uint64_t start = current_time_ms();
948a272653SPeter Holm    for (;;) {
958a272653SPeter Holm      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
968a272653SPeter Holm        break;
978a272653SPeter Holm      sleep_ms(1);
988a272653SPeter Holm      if (current_time_ms() - start < 5 * 1000)
998a272653SPeter Holm        continue;
1008a272653SPeter Holm      kill_and_wait(pid, &status);
1018a272653SPeter Holm      break;
1028a272653SPeter Holm    }
1038a272653SPeter Holm  }
1048a272653SPeter Holm}
1058a272653SPeter Holm
1068a272653SPeter Holmuint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
1078a272653SPeter Holm                 0xffffffffffffffff, 0xffffffffffffffff};
1088a272653SPeter Holm
1098a272653SPeter Holmvoid execute_one(void)
1108a272653SPeter Holm{
1118a272653SPeter Holm  long res = 0;
1128a272653SPeter Holm  memcpy((void*)0x20001180, "./file0\000", 8);
1138a272653SPeter Holm  res = syscall(SYS_open, 0x20001180, 0x8240, 0);
1148a272653SPeter Holm  if (res != -1)
1158a272653SPeter Holm    r[0] = res;
1168a272653SPeter Holm  res = syscall(SYS_socketpair, 1, 1, 0, 0x20000100);
1178a272653SPeter Holm  if (res != -1) {
1188a272653SPeter Holm    r[1] = *(uint32_t*)0x20000100;
1198a272653SPeter Holm    r[2] = *(uint32_t*)0x20000104;
1208a272653SPeter Holm  }
1218a272653SPeter Holm  memcpy((void*)0x20000480, "./file0\000", 8);
1228a272653SPeter Holm  res = syscall(SYS_open, 0x20000480, 0x80000000000206, 0);
1238a272653SPeter Holm  if (res != -1)
1248a272653SPeter Holm    r[3] = res;
1258a272653SPeter Holm  res = syscall(SYS_dup, r[3]);
1268a272653SPeter Holm  if (res != -1)
1278a272653SPeter Holm    r[4] = res;
1288a272653SPeter Holm  *(uint64_t*)0x20000100 = 0x200002c0;
1298a272653SPeter Holm  memcpy((void*)0x200002c0, "\xdd", 1);
1308a272653SPeter Holm  *(uint64_t*)0x20000108 = 1;
1318a272653SPeter Holm  syscall(SYS_pwritev, r[4], 0x20000100, 1, 0);
1328a272653SPeter Holm  *(uint64_t*)0x20002e80 = 0x20000540;
1338a272653SPeter Holm  memcpy((void*)0x20000540, "\x7f", 1);
1348a272653SPeter Holm  *(uint64_t*)0x20002e88 = 1;
1358a272653SPeter Holm  syscall(SYS_pwritev, r[3], 0x20002e80, 1, 0xbf24);
1368a272653SPeter Holm  memcpy((void*)0x200004c0,
1378a272653SPeter Holm         "\x89\x88\xaa\x4a\xc3\x95\x23\x77\x54\xee\x66\xf3\x8d\xa4\xae\xf3\x47"
1388a272653SPeter Holm         "\x6d\x78\xb7\x1f\xe6\x0d\xb7\x4a\x9f\xb9\xc9\x99\x91\x6c\x98",
1398a272653SPeter Holm         32);
1408a272653SPeter Holm  syscall(SYS_setsockopt, r[2], 0, 2, 0x200004c0, 0x20);
1418a272653SPeter Holm  syscall(SYS_fcntl, r[4], 4, 0x10044);
1428a272653SPeter Holm  syscall(SYS_read, r[4], 0x20000000, 0x6d999);
1438a272653SPeter Holm  syscall(SYS_sendfile, r[0], r[1], 0, 2);
1448a272653SPeter Holm}
1458a272653SPeter Holmint main(void)
1468a272653SPeter Holm{
1478a272653SPeter Holm  syscall(SYS_mmap, 0x20000000, 0x1000000, 3, 0x1012, -1, 0ul);
1488a272653SPeter Holm  loop();
1498a272653SPeter Holm  return 0;
1508a272653SPeter Holm}
1518a272653SPeter HolmEOF
1528a272653SPeter Holmmycc -o /tmp/syzkaller7 -Wall -Wextra -O2 /tmp/syzkaller7.c -lpthread ||
1538a272653SPeter Holm    exit 1
1548a272653SPeter Holm
1558a272653SPeter Holm(cd /tmp; timeout 5m ./syzkaller7) &
1568a272653SPeter Holmsleep 60
1578a272653SPeter Holmwhile pkill -9 syzkaller7; do :; done
1588a272653SPeter Holmwait
1598a272653SPeter Holm
1608a272653SPeter Holmrm -f /tmp/syzkaller7 /tmp/syzkaller7.c /tmp/syzkaller7.core /tmp/file0
1618a272653SPeter Holmexit 0
162