xref: /freebsd/tools/test/stress2/misc/syzkaller29.sh (revision c1d255d3)
1#!/bin/sh
2
3# panic: uma_zalloc_debug: called within spinlock or critical section
4# cpuid = 9
5# time = 1606151277
6# KDB: stack backtrace:
7# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0101c628a0
8# vpanic() at vpanic+0x181/frame 0xfffffe0101c628f0
9# panic() at panic+0x43/frame 0xfffffe0101c62950
10# uma_zalloc_arg() at uma_zalloc_arg+0x1e6/frame 0xfffffe0101c62990
11# cpuset_modify_domain() at cpuset_modify_domain+0x1bf/frame 0xfffffe0101c62a10
12# kern_cpuset_setdomain() at kern_cpuset_setdomain+0x402/frame 0xfffffe0101c62aa0
13# sys_cpuset_setdomain() at sys_cpuset_setdomain+0x26/frame 0xfffffe0101c62ac0
14# amd64_syscall() at amd64_syscall+0x147/frame 0xfffffe0101c62bf0
15# fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe0101c62bf0
16# --- syscall (0, FreeBSD ELF64, nosys), rip = 0x800380d4a, rsp = 0x7fffffffe4b8, rbp = 0x7fffffffe4f0 ---
17# KDB: enter: panic
18# [ thread pid 81187 tid 100369 ]
19# Stopped at      kdb_enter+0x37: movq    $0,0x10b3236(%rip)
20# db> x/s version
21# version: FreeBSD 13.0-CURRENT #0 r367945: Mon Nov 23 09:10:40 CET 2020
22# pho@t2.osted.lan:/usr/src/sys/amd64/compile/PHO
23# db>
24
25[ `uname -p` != "amd64" ] && exit 0
26
27# Fixed by r368116
28
29. ../default.cfg
30cat > /tmp/syzkaller29.c <<EOF
31// https://syzkaller.appspot.com/bug?id=c3452066dba9238c4551010eb130944442d9174f
32// autogenerated by syzkaller (https://github.com/google/syzkaller)
33// Reported-by: syzbot+6743fa07b9b7528dc561@syzkaller.appspotmail.com
34
35#define _GNU_SOURCE
36
37#include <sys/types.h>
38
39#include <pwd.h>
40#include <signal.h>
41#include <stdarg.h>
42#include <stdbool.h>
43#include <stdint.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include <sys/endian.h>
48#include <sys/syscall.h>
49#include <sys/wait.h>
50#include <time.h>
51#include <unistd.h>
52
53static void kill_and_wait(int pid, int* status)
54{
55  kill(pid, SIGKILL);
56  while (waitpid(-1, status, 0) != pid) {
57  }
58}
59
60static void sleep_ms(uint64_t ms)
61{
62  usleep(ms * 1000);
63}
64
65static uint64_t current_time_ms(void)
66{
67  struct timespec ts;
68  if (clock_gettime(CLOCK_MONOTONIC, &ts))
69    exit(1);
70  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
71}
72
73static void execute_one(void);
74
75#define WAIT_FLAGS 0
76
77static void loop(void)
78{
79  int iter = 0;
80  for (;; iter++) {
81    int pid = fork();
82    if (pid < 0)
83      exit(1);
84    if (pid == 0) {
85      execute_one();
86      exit(0);
87    }
88    int status = 0;
89    uint64_t start = current_time_ms();
90    for (;;) {
91      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
92        break;
93      sleep_ms(1);
94      if (current_time_ms() - start < 5 * 1000)
95        continue;
96      kill_and_wait(pid, &status);
97      break;
98    }
99  }
100}
101
102void execute_one(void)
103{
104  *(uint64_t*)0x20000240 = 1;
105  *(uint64_t*)0x20000248 = 0;
106  *(uint64_t*)0x20000250 = 0;
107  *(uint64_t*)0x20000258 = 0;
108  syscall(SYS_cpuset_setdomain, 2ul, 2ul, 0ul, 0x20ul, 0x20000240ul, 4ul);
109  *(uint64_t*)0x20000240 = 1;
110  *(uint64_t*)0x20000248 = 0;
111  *(uint64_t*)0x20000250 = 0;
112  *(uint64_t*)0x20000258 = 0;
113  syscall(SYS_cpuset_setdomain, 3ul, 2ul, 0ul, 0x20ul, 0x20000240ul, 1ul);
114}
115int main(void)
116{
117  syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul);
118  loop();
119  return 0;
120}
121EOF
122mycc -o /tmp/syzkaller29 -Wall -Wextra -O0 /tmp/syzkaller29.c ||
123    exit 1
124
125(cd /tmp; timeout 3m ./syzkaller29)
126
127rm -rf /tmp/syzkaller29 syzkaller29.c /tmp/syzkaller.*
128exit 0
129