3 # panic: mtx_lock() of spin mutex (null) @ ../../../kern/uipc_ktls.c:1034
6 # KDB: stack backtrace:
7 # db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe013a91b6c0
8 # vpanic() at vpanic+0x182/frame 0xfffffe013a91b710
9 # panic() at panic+0x43/frame 0xfffffe013a91b770
10 # __mtx_lock_flags() at __mtx_lock_flags+0x13c/frame 0xfffffe013a91b7c0
11 # ktls_get_rx_mode() at ktls_get_rx_mode+0x4e/frame 0xfffffe013a91b7f0
12 # tcp_default_ctloutput() at tcp_default_ctloutput+0x800/frame 0xfffffe013a91b960
13 # tcp_ctloutput() at tcp_ctloutput+0x1f5/frame 0xfffffe013a91b9d0
14 # sogetopt() at sogetopt+0x101/frame 0xfffffe013a91ba40
15 # kern_getsockopt() at kern_getsockopt+0xb4/frame 0xfffffe013a91baa0
16 # sys_getsockopt() at sys_getsockopt+0x52/frame 0xfffffe013a91bad0
17 # amd64_syscall() at amd64_syscall+0x159/frame 0xfffffe013a91bbf0
18 # fast_syscall_common() at fast_syscall_common+0x101/frame 0xfffffe013a91bbf0
19 # --- syscall (0, FreeBSD ELF64, nosys), rip = 0x80045446a, rsp = 0x7fffdffdcf88, rbp = 0x7fffdffdcfc0 ---
21 # [ thread pid 5313 tid 101679 ]
22 # Stopped at kdb_enter+0x37: movq $0,0x10c7fa6(%rip)
24 # version: FreeBSD 13.0-CURRENT #0 r361886: Tue Jun 9 08:32:24 CEST 2020\012 pho@t2.osted.lan:/usr/src/sys/amd64/compile/KTLS\012
27 # Reproduced on r361886 with "options KERN_TLS"
29 [ `uname -p` = "i386" ] && exit 0
32 cat > /tmp/syzkaller14.c <<EOF
33 // https://syzkaller.appspot.com/bug?id=d50164ce557a20a785510aac5d6f104d8a62e779
34 // autogenerated by syzkaller (https://github.com/google/syzkaller)
35 // Reported-by: syzbot+a8829e888a93a4a04619@syzkaller.appspotmail.com
39 #include <sys/types.h>
51 #include <sys/endian.h>
52 #include <sys/syscall.h>
57 static unsigned long long procid;
59 static void kill_and_wait(int pid, int* status)
62 while (waitpid(-1, status, 0) != pid) {
66 static void sleep_ms(uint64_t ms)
71 static uint64_t current_time_ms(void)
74 if (clock_gettime(CLOCK_MONOTONIC, &ts))
76 return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
79 static void thread_start(void* (*fn)(void*), void* arg)
83 pthread_attr_init(&attr);
84 pthread_attr_setstacksize(&attr, 128 << 10);
86 for (i = 0; i < 100; i++) {
87 if (pthread_create(&th, &attr, fn, arg) == 0) {
88 pthread_attr_destroy(&attr);
91 if (errno == EAGAIN) {
106 static void event_init(event_t* ev)
108 if (pthread_mutex_init(&ev->mu, 0))
110 if (pthread_cond_init(&ev->cv, 0))
115 static void event_reset(event_t* ev)
120 static void event_set(event_t* ev)
122 pthread_mutex_lock(&ev->mu);
126 pthread_mutex_unlock(&ev->mu);
127 pthread_cond_broadcast(&ev->cv);
130 static void event_wait(event_t* ev)
132 pthread_mutex_lock(&ev->mu);
134 pthread_cond_wait(&ev->cv, &ev->mu);
135 pthread_mutex_unlock(&ev->mu);
138 static int event_isset(event_t* ev)
140 pthread_mutex_lock(&ev->mu);
142 pthread_mutex_unlock(&ev->mu);
146 static int event_timedwait(event_t* ev, uint64_t timeout)
148 uint64_t start = current_time_ms();
149 uint64_t now = start;
150 pthread_mutex_lock(&ev->mu);
154 uint64_t remain = timeout - (now - start);
156 ts.tv_sec = remain / 1000;
157 ts.tv_nsec = (remain % 1000) * 1000 * 1000;
158 pthread_cond_timedwait(&ev->cv, &ev->mu, &ts);
159 now = current_time_ms();
160 if (now - start > timeout)
164 pthread_mutex_unlock(&ev->mu);
173 static struct thread_t threads[16];
174 static void execute_call(int call);
177 static void* thr(void* arg)
179 struct thread_t* th = (struct thread_t*)arg;
181 event_wait(&th->ready);
182 event_reset(&th->ready);
183 execute_call(th->call);
184 __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
185 event_set(&th->done);
190 static void execute_one(void)
195 for (call = 0; call < 3; call++) {
196 for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
198 struct thread_t* th = &threads[thread];
201 event_init(&th->ready);
202 event_init(&th->done);
203 event_set(&th->done);
204 thread_start(thr, th);
206 if (!event_isset(&th->done))
208 event_reset(&th->done);
210 __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
211 event_set(&th->ready);
212 if (collide && (call % 2) == 0)
214 event_timedwait(&th->done, 45);
218 for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
226 static void execute_one(void);
230 static void loop(void)
233 for (iter = 0;; iter++) {
242 uint64_t start = current_time_ms();
244 if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
247 if (current_time_ms() - start < 5 * 1000)
249 kill_and_wait(pid, &status);
255 uint64_t r[1] = {0xffffffffffffffff};
257 void execute_call(int call)
262 res = syscall(SYS_socket, 0x1cul, 1ul, 0);
267 syscall(SYS_getsockopt, r[0], 6, 0x2a, 0ul, 0ul);
270 syscall(SYS_listen, r[0], 1);
276 syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul);
277 for (procid = 0; procid < 4; procid++) {
286 mycc -o /tmp/syzkaller14 -Wall -Wextra -O2 /tmp/syzkaller14.c -lpthread ||
289 (cd /tmp; ./syzkaller14) &
294 rm -f /tmp/syzkaller14 /tmp/syzkaller14.c /tmp/syzkaller14.core