xref: /freebsd/tools/test/stress2/misc/syzkaller33.sh (revision 7f658f99f7ed5d1d0e0802073bb22eb8a0a784fb)
1#!/bin/sh
2
3# Fatal trap 18: integer divide fault while in kernel mode
4# cpuid = 0; apic id = 00
5# instruction pointer     = 0x20:0xffffffff80c310ee
6# stack pointer           = 0x28:0xfffffe0131a629e0
7# frame pointer           = 0x28:0xfffffe0131a62a30
8# code segment            = base 0x0, limit 0xfffff, type 0x1b
9#                         = DPL 0, pres 1, long 1, def32 0, gran 1
10# processor eflags        = interrupt enabled, resume, IOPL = 0
11# current process         = 12 (swi4: clock (0))
12# trap number             = 18
13# panic: integer divide fault
14# cpuid = 0
15# time = 1618722013
16# KDB: stack backtrace:
17# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0131a626f0
18# vpanic() at vpanic+0x181/frame 0xfffffe0131a62740
19# panic() at panic+0x43/frame 0xfffffe0131a627a0
20# trap_fatal() at trap_fatal+0x387/frame 0xfffffe0131a62800
21# trap() at trap+0xa4/frame 0xfffffe0131a62910
22# calltrap() at calltrap+0x8/frame 0xfffffe0131a62910
23# --- trap 0x12, rip = 0xffffffff80c310ee, rsp = 0xfffffe0131a629e0, rbp = 0xfffffe0131a62a30 ---
24# realtimer_expire_l() at realtimer_expire_l+0xee/frame 0xfffffe0131a62a30
25# softclock_call_cc() at softclock_call_cc+0x15d/frame 0xfffffe0131a62b00
26# softclock() at softclock+0x66/frame 0xfffffe0131a62b20
27# ithread_loop() at ithread_loop+0x279/frame 0xfffffe0131a62bb0
28# fork_exit() at fork_exit+0x80/frame 0xfffffe0131a62bf0
29# fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0131a62bf0
30# --- trap 0, rip = 0, rsp = 0, rbp = 0 ---
31# KDB: enter: panic
32# [ thread pid 12 tid 100161 ]
33# Stopped at      kdb_enter+0x37: movq    $0,0x1283f9e(%rip)
34# db> x/s version
35# version: FreeBSD 14.0-CURRENT #0 main-n246123-21afed4b1d1-dirty: Sat Apr 17 07:39:42 CEST 2021
36# pho@t2.osted.lan:/usr/src/sys/amd64/compile/PHO
37# db>
38
39[ `uname -p` != "amd64" ] && exit 0
40
41. ../default.cfg
42cat > /tmp/syzkaller33.c <<EOF
43// https://syzkaller.appspot.com/bug?id=38b58493445d524070d1a7cd73612f8cc9d01f39
44// autogenerated by syzkaller (https://github.com/google/syzkaller)
45// Reported-by: syzbot+5ab360bd3d3e3c5a6e0e@syzkaller.appspotmail.com
46
47#define _GNU_SOURCE
48
49#include <sys/types.h>
50
51#include <pwd.h>
52#include <signal.h>
53#include <stdarg.h>
54#include <stdbool.h>
55#include <stdint.h>
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <sys/endian.h>
60#include <sys/syscall.h>
61#include <sys/wait.h>
62#include <time.h>
63#include <unistd.h>
64
65static void kill_and_wait(int pid, int* status)
66{
67  kill(pid, SIGKILL);
68  while (waitpid(-1, status, 0) != pid) {
69  }
70}
71
72static void sleep_ms(uint64_t ms)
73{
74  usleep(ms * 1000);
75}
76
77static uint64_t current_time_ms(void)
78{
79  struct timespec ts;
80  if (clock_gettime(CLOCK_MONOTONIC, &ts))
81    exit(1);
82  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
83}
84
85static void execute_one(void);
86
87#define WAIT_FLAGS 0
88
89static void loop(void)
90{
91  int iter __unused = 0;
92  for (;; iter++) {
93    int pid = fork();
94    if (pid < 0)
95      exit(1);
96    if (pid == 0) {
97      execute_one();
98      exit(0);
99    }
100    int status = 0;
101    uint64_t start = current_time_ms();
102    for (;;) {
103      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
104        break;
105      sleep_ms(1);
106      if (current_time_ms() - start < 5000) {
107        continue;
108      }
109      kill_and_wait(pid, &status);
110      break;
111    }
112  }
113}
114
115uint64_t r[1] = {0x0};
116
117void execute_one(void)
118{
119  intptr_t res = 0;
120  res = syscall(SYS_ktimer_create, 0ul, 0ul, 0x200011c0ul);
121  if (res != -1)
122    r[0] = *(uint32_t*)0x200011c0;
123  *(uint64_t*)0x20001200 = 0x800000000000000;
124  *(uint64_t*)0x20001208 = 0;
125  *(uint64_t*)0x20001210 = 0;
126  *(uint64_t*)0x20001218 = 0xa2b;
127  syscall(SYS_ktimer_settime, r[0], 1ul, 0x20001200ul, 0ul);
128}
129int main(void)
130{
131  syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul);
132  loop();
133  return 0;
134}
135EOF
136mycc -o /tmp/syzkaller33 -Wall -Wextra -O0 /tmp/syzkaller33.c ||
137    exit 1
138
139(cd /tmp; timeout 3m ./syzkaller33)
140
141rm -rf /tmp/syzkaller33 /tmp/syzkaller33.c /tmp/syzkaller.*
142exit 0
143