1#!/bin/sh 2 3# panic: sbflush_internal: ccc 0 mb 0 mbcnt 256 4# cpuid = 4 5# time = 1592126385 6# KDB: stack backtrace: 7# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe012b22f8d0 8# vpanic() at vpanic+0x182/frame 0xfffffe012b22f920 9# panic() at panic+0x43/frame 0xfffffe012b22f980 10# sbrelease_internal() at sbrelease_internal+0xbd/frame 0xfffffe012b22f9a0 11# solisten_proto() at solisten_proto+0xab/frame 0xfffffe012b22fa00 12# sctp_listen() at sctp_listen+0x2f4/frame 0xfffffe012b22fa60 13# solisten() at solisten+0x42/frame 0xfffffe012b22fa80 14# kern_listen() at kern_listen+0x7c/frame 0xfffffe012b22fac0 15# ia32_syscall() at ia32_syscall+0x150/frame 0xfffffe012b22fbf0 16# int0x80_syscall_common() at int0x80_syscall_common+0x9c/frame 0xffffdb10 17# KDB: enter: panic 18# [ thread pid 93263 tid 100202 ] 19# Stopped at kdb_enter+0x37: movq $0,0x10c5456(%rip) 20# db> x/s version 21# version: FreeBSD 13.0-CURRENT #0 r362171: Sun Jun 14 09:06:12 CEST 2020 22# pho@mercat1.netperf.freebsd.org:/usr/src/sys/amd64/compile/PHO 23# db> 24 25[ `uname -p` != "amd64" ] && exit 0 26 27. ../default.cfg 28kldstat -v | grep -q sctp || kldload sctp.ko 29cat > /tmp/syzkaller15.c <<EOF 30// https://syzkaller.appspot.com/bug?id=6b9cfdc1689b0adee1c6f75f56ab034a70500d93 31// autogenerated by syzkaller (https://github.com/google/syzkaller) 32// Reported-by: syzbot+bca42a93f1254ca91e94@syzkaller.appspotmail.com 33 34#define _GNU_SOURCE 35 36#include <sys/types.h> 37 38#include <pwd.h> 39#include <setjmp.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 unsigned long long procid; 54 55static __thread int skip_segv; 56static __thread jmp_buf segv_env; 57 58static void segv_handler(int sig, siginfo_t* info, void* ctx __unused) 59{ 60 uintptr_t addr = (uintptr_t)info->si_addr; 61 const uintptr_t prog_start = 1 << 20; 62 const uintptr_t prog_end = 100 << 20; 63 if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && 64 (addr < prog_start || addr > prog_end)) { 65 _longjmp(segv_env, 1); 66 } 67 exit(sig); 68} 69 70static void install_segv_handler(void) 71{ 72 struct sigaction sa; 73 memset(&sa, 0, sizeof(sa)); 74 sa.sa_sigaction = segv_handler; 75 sa.sa_flags = SA_NODEFER | SA_SIGINFO; 76 sigaction(SIGSEGV, &sa, NULL); 77 sigaction(SIGBUS, &sa, NULL); 78} 79 80#define NONFAILING(...) \ 81 { \ 82 __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ 83 if (_setjmp(segv_env) == 0) { \ 84 __VA_ARGS__; \ 85 } \ 86 __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ 87 } 88 89static void kill_and_wait(int pid, int* status) 90{ 91 kill(pid, SIGKILL); 92 while (waitpid(-1, status, 0) != pid) { 93 } 94} 95 96static void sleep_ms(uint64_t ms) 97{ 98 usleep(ms * 1000); 99} 100 101static uint64_t current_time_ms(void) 102{ 103 struct timespec ts; 104 if (clock_gettime(CLOCK_MONOTONIC, &ts)) 105 exit(1); 106 return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; 107} 108 109static void execute_one(void); 110 111#define WAIT_FLAGS 0 112 113static void loop(void) 114{ 115 int iter __unused; 116 for (iter = 0;; iter++) { 117 int pid = fork(); 118 if (pid < 0) 119 exit(1); 120 if (pid == 0) { 121 execute_one(); 122 exit(0); 123 } 124 int status = 0; 125 uint64_t start = current_time_ms(); 126 for (;;) { 127 if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) 128 break; 129 sleep_ms(1); 130 if (current_time_ms() - start < 5 * 1000) 131 continue; 132 kill_and_wait(pid, &status); 133 break; 134 } 135 } 136} 137 138uint64_t r[1] = {0xffffffffffffffff}; 139 140void execute_one(void) 141{ 142 intptr_t res = 0; 143 res = syscall(SYS_socket, 0x1c, 1, 0x84); 144 if (res != -1) 145 r[0] = res; 146 NONFAILING(*(uint8_t*)0x10000040 = 0xc8); 147 NONFAILING(*(uint8_t*)0x10000041 = 0x51); 148 NONFAILING(*(uint8_t*)0x10000042 = 0); 149 NONFAILING(*(uint8_t*)0x10000043 = 0); 150 NONFAILING(*(uint8_t*)0x10000044 = 0); 151 NONFAILING(*(uint8_t*)0x10000045 = 0); 152 NONFAILING(*(uint8_t*)0x10000046 = 0); 153 NONFAILING(*(uint8_t*)0x10000047 = 0); 154 NONFAILING(*(uint8_t*)0x10000048 = 0); 155 NONFAILING(*(uint8_t*)0x10000049 = 0); 156 NONFAILING(*(uint8_t*)0x1000004a = 0); 157 syscall(SYS_setsockopt, (intptr_t)r[0], 0x84, 0xc, 0x10000040, 0xb); 158 NONFAILING(*(uint8_t*)0x10000180 = 0x5f); 159 NONFAILING(*(uint8_t*)0x10000181 = 0x1c); 160 NONFAILING(*(uint16_t*)0x10000182 = htobe16(0x4e22 + procid * 4)); 161 NONFAILING(*(uint32_t*)0x10000184 = 0); 162 NONFAILING(*(uint64_t*)0x10000188 = htobe64(0)); 163 NONFAILING(*(uint64_t*)0x10000190 = htobe64(1)); 164 NONFAILING(*(uint32_t*)0x10000198 = 0); 165 syscall(SYS_connect, (intptr_t)r[0], 0x10000180, 0x1c); 166 syscall(SYS_listen, (intptr_t)r[0], 7); 167} 168int main(void) 169{ 170 syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); 171 install_segv_handler(); 172 for (procid = 0; procid < 4; procid++) { 173 if (fork() == 0) { 174 loop(); 175 } 176 } 177 sleep(1000000); 178 return 0; 179} 180EOF 181mycc -o /tmp/syzkaller15 -Wall -Wextra -O0 -m32 /tmp/syzkaller15.c || 182 exit 1 183 184(cd /tmp; ./syzkaller15) & 185sleep 60 186pkill -9 syzkaller15 187wait 188 189rm -f /tmp/syzkaller15 /tmp/syzkaller15.c /tmp/syzkaller15.core 190exit 0 191