xref: /freebsd/tools/test/stress2/misc/syzkaller29.sh (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
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# May change policy for random threads to domainset_fixed
30exit 0
31
32. ../default.cfg
33cat > /tmp/syzkaller29.c <<EOF
34// https://syzkaller.appspot.com/bug?id=c3452066dba9238c4551010eb130944442d9174f
35// autogenerated by syzkaller (https://github.com/google/syzkaller)
36// Reported-by: syzbot+6743fa07b9b7528dc561@syzkaller.appspotmail.com
37
38#define _GNU_SOURCE
39
40#include <sys/types.h>
41
42#include <pwd.h>
43#include <signal.h>
44#include <stdarg.h>
45#include <stdbool.h>
46#include <stdint.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#include <sys/endian.h>
51#include <sys/syscall.h>
52#include <sys/wait.h>
53#include <time.h>
54#include <unistd.h>
55
56static void kill_and_wait(int pid, int* status)
57{
58  kill(pid, SIGKILL);
59  while (waitpid(-1, status, 0) != pid) {
60  }
61}
62
63static void sleep_ms(uint64_t ms)
64{
65  usleep(ms * 1000);
66}
67
68static uint64_t current_time_ms(void)
69{
70  struct timespec ts;
71  if (clock_gettime(CLOCK_MONOTONIC, &ts))
72    exit(1);
73  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
74}
75
76static void execute_one(void);
77
78#define WAIT_FLAGS 0
79
80static void loop(void)
81{
82  int iter __unused = 0;
83  for (;; iter++) {
84    int pid = fork();
85    if (pid < 0)
86      exit(1);
87    if (pid == 0) {
88      execute_one();
89      exit(0);
90    }
91    int status = 0;
92    uint64_t start = current_time_ms();
93    for (;;) {
94      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
95        break;
96      sleep_ms(1);
97      if (current_time_ms() - start < 5 * 1000)
98        continue;
99      kill_and_wait(pid, &status);
100      break;
101    }
102  }
103}
104
105void execute_one(void)
106{
107  *(uint64_t*)0x20000240 = 1;
108  *(uint64_t*)0x20000248 = 0;
109  *(uint64_t*)0x20000250 = 0;
110  *(uint64_t*)0x20000258 = 0;
111  syscall(SYS_cpuset_setdomain, 2ul, 2ul, 0ul, 0x20ul, 0x20000240ul, 4ul);
112  *(uint64_t*)0x20000240 = 1;
113  *(uint64_t*)0x20000248 = 0;
114  *(uint64_t*)0x20000250 = 0;
115  *(uint64_t*)0x20000258 = 0;
116  syscall(SYS_cpuset_setdomain, 3ul, 2ul, 0ul, 0x20ul, 0x20000240ul, 1ul);
117}
118int main(void)
119{
120  syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul);
121  loop();
122  return 0;
123}
124EOF
125mycc -o /tmp/syzkaller29 -Wall -Wextra -O0 /tmp/syzkaller29.c ||
126    exit 1
127
128(cd /tmp; timeout 3m ./syzkaller29)
129
130rm -rf /tmp/syzkaller29 /tmp/syzkaller29.c /tmp/syzkaller.*
131exit 0
132