ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 0.648s ok github.com/google/syzkaller/pkg/ast 4.161s ok github.com/google/syzkaller/pkg/bisect 119.367s ok github.com/google/syzkaller/pkg/build 8.849s ok github.com/google/syzkaller/pkg/compiler 28.396s ok github.com/google/syzkaller/pkg/config (cached) ok github.com/google/syzkaller/pkg/cover (cached) ? github.com/google/syzkaller/pkg/cover/backend [no test files] --- FAIL: TestGenerate (74.17s) --- FAIL: TestGenerate/openbsd/amd64 (1.00s) csource_test.go:68: seed=1609249048101445047 --- FAIL: TestGenerate/openbsd/amd64/9 (3.68s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:setuid Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, WUNTRACED) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_setuid(void) { int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); char pwbuf[1024]; struct passwd *pw, pwres; if (getpwnam_r("nobody", &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 || !pw) exit(1); if (setgroups(0, NULL)) exit(1); if (setgid(pw->pw_gid)) exit(1); if (setuid(pw->pw_uid)) exit(1); loop(); exit(1); } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_setuid(); return 0; } :353:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :351:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor126525564 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/10 (4.66s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:true NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static int tunfd = -1; #define MAX_TUN 4 #define TUN_IFACE "tap%d" #define TUN_DEVICE "/dev/tap%d" #define LOCAL_MAC "aa:aa:aa:aa:aa:aa" #define REMOTE_MAC "aa:aa:aa:aa:aa:bb" #define LOCAL_IPV4 "172.20.%d.170" #define REMOTE_IPV4 "172.20.%d.187" #define LOCAL_IPV6 "fe80::%02hxaa" #define REMOTE_IPV6 "fe80::%02hxbb" static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; va_start(args, format); char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); int rv = system(command); if (rv) { if (panic) exit(1); } } static void initialize_tun(int tun_id) { if (tun_id < 0 || tun_id >= MAX_TUN) { exit(1); } char tun_device[sizeof(TUN_DEVICE)]; snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id); char tun_iface[sizeof(TUN_IFACE)]; snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id); execute_command(0, "ifconfig %s destroy", tun_device); tunfd = open(tun_device, O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open %s: errno=%d\n", tun_device, errno); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; char local_mac[sizeof(LOCAL_MAC)]; snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC); execute_command(1, "ifconfig %s lladdr %s", tun_iface, local_mac); char local_ipv4[sizeof(LOCAL_IPV4)]; snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id); execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4); char remote_mac[sizeof(REMOTE_MAC)]; char remote_ipv4[sizeof(REMOTE_IPV4)]; snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC); snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, tun_id); execute_command(0, "arp -s %s %s", remote_ipv4, remote_mac); char local_ipv6[sizeof(LOCAL_IPV6)]; snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, tun_id); execute_command(1, "ifconfig %s inet6 %s", tun_iface, local_ipv6); char remote_ipv6[sizeof(REMOTE_IPV6)]; snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, tun_id); execute_command(0, "ndp -s %s%%%s %s", remote_ipv6, tun_iface, remote_mac); } static long syz_emit_ethernet(volatile long a0, volatile long a1) { if (tunfd < 0) return (uintptr_t)-1; size_t length = a0; const char* data = (char*)a1; return write(tunfd, data, length); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; exit(1); } return rv; } struct tcp_resources { uint32_t seq; uint32_t ack; }; static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile long a2) { if (tunfd < 0) return (uintptr_t)-1; char data[1000]; int rv = read_tun(&data[0], sizeof(data)); if (rv == -1) return (uintptr_t)-1; size_t length = rv; if (length < sizeof(struct ether_header)) return (uintptr_t)-1; struct ether_header* ethhdr = (struct ether_header*)&data[0]; struct tcphdr* tcphdr = 0; if (ethhdr->ether_type == htons(ETHERTYPE_IP)) { if (length < sizeof(struct ether_header) + sizeof(struct ip)) return (uintptr_t)-1; struct ip* iphdr = (struct ip*)&data[sizeof(struct ether_header)]; if (iphdr->ip_p != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + iphdr->ip_hl * 4 + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + iphdr->ip_hl * 4]; } else { if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr)) return (uintptr_t)-1; struct ip6_hdr* ipv6hdr = (struct ip6_hdr*)&data[sizeof(struct ether_header)]; if (ipv6hdr->ip6_nxt != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr) + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + sizeof(struct ip6_hdr)]; } struct tcp_resources* res = (struct tcp_resources*)a0; res->seq = htonl(ntohl(tcphdr->th_seq) + (uint32_t)a1); res->ack = htonl(ntohl(tcphdr->th_ack) + (uint32_t)a2); return 0; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); initialize_tun(procid); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); syz_emit_ethernet(0xe0, 0x20000000); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: syz_extract_tcp_res(0x20000140, 0x800, 0x1000); break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_none(); return 0; } :498:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :496:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor087191822 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/13 (5.76s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_none(); return 0; } :332:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :330:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor700845959 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/8 (6.15s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox: Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); loop(); return 0; } :305:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :303:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor760706874 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/15 (6.55s) csource_test.go:124: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; int collide = 0; again: for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22 + procid*4; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22 + procid*4; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0 + procid*1; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0 + procid*1; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0 + procid*1; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0 + procid*1; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0 + procid*1; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :342:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :340:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor412859080 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/0 (7.77s) csource_test.go:124: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { if (setsid() == -1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); syz_open_pts(); } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_none(); return 0; } :193:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :191:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor605434534 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/11 (7.81s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:false HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); do_sandbox_none(); return 0; } :278:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :276:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor091462571 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/12 (8.07s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:true Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) ({ int ok = 1; __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } else ok = 0; __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); ok; }) static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { NONFAILING(r[0] = *(uint32_t*)0x20000000); NONFAILING(r[1] = *(uint32_t*)0x20000004); } break; case 1: NONFAILING(*(uint16_t*)0x20000040 = 0); NONFAILING(*(uint8_t*)0x20000042 = 0); NONFAILING(*(uint32_t*)0x20000044 = 0x4e22); syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: NONFAILING(*(uint32_t*)0x200000c0 = 8); syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: NONFAILING(*(uint32_t*)0x20000140 = 0xc); syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: NONFAILING(*(uint32_t*)0x200001c0 = 0xc); res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: NONFAILING(*(uint64_t*)0x20001340 = 0x20000200); NONFAILING(*(uint64_t*)0x20001348 = 0x79); NONFAILING(*(uint64_t*)0x20001350 = 0x20000280); NONFAILING(*(uint64_t*)0x20001358 = 0x1000); NONFAILING(*(uint64_t*)0x20001360 = 0x20001280); NONFAILING(*(uint64_t*)0x20001368 = 0xb4); syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: NONFAILING(*(uint16_t*)0x20001440 = 0); NONFAILING(*(uint8_t*)0x20001442 = 0); NONFAILING(*(uint32_t*)0x20001444 = 0x4e22); syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: NONFAILING(*(uint32_t*)0x200014c0 = 1); NONFAILING(*(uint64_t*)0x200014c8 = 0x20001480); NONFAILING(*(uint16_t*)0x20001480 = 6); NONFAILING(*(uint8_t*)0x20001482 = 0x50); NONFAILING(*(uint8_t*)0x20001483 = 6); NONFAILING(*(uint32_t*)0x20001484 = 9); syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: NONFAILING(memcpy((void*)0x20001500, "./file0\000", 8)); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: NONFAILING(*(uint32_t*)0x20001540 = 5); syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: NONFAILING(*(uint8_t*)0x20000000 = -1); NONFAILING(*(uint8_t*)0x20000001 = -1); NONFAILING(*(uint8_t*)0x20000002 = -1); NONFAILING(*(uint8_t*)0x20000003 = -1); NONFAILING(*(uint8_t*)0x20000004 = -1); NONFAILING(*(uint8_t*)0x20000005 = -1); NONFAILING(*(uint8_t*)0x20000006 = 0xaa); NONFAILING(*(uint8_t*)0x20000007 = 0xaa); NONFAILING(*(uint8_t*)0x20000008 = 0xaa); NONFAILING(*(uint8_t*)0x20000009 = 0xaa); NONFAILING(*(uint8_t*)0x2000000a = 0xaa); NONFAILING(*(uint8_t*)0x2000000b = 0xaa); NONFAILING(*(uint16_t*)0x2000000c = htobe16(0x8100)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12)); NONFAILING(*(uint16_t*)0x20000010 = htobe16(0x800)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6)); NONFAILING(*(uint16_t*)0x20000014 = htobe16(0xce)); NONFAILING(*(uint16_t*)0x20000016 = htobe16(0x66)); NONFAILING(*(uint16_t*)0x20000018 = htobe16(8)); NONFAILING(*(uint8_t*)0x2000001a = 0xb5); NONFAILING(*(uint8_t*)0x2000001b = 0x16); NONFAILING(*(uint16_t*)0x2000001c = htobe16(0)); NONFAILING(*(uint32_t*)0x2000001e = htobe32(-1)); NONFAILING(*(uint32_t*)0x20000022 = htobe32(0)); NONFAILING(*(uint8_t*)0x20000026 = 0x89); NONFAILING(*(uint8_t*)0x20000027 = 0xb); NONFAILING(*(uint8_t*)0x20000028 = 0xc2); NONFAILING(*(uint8_t*)0x20000029 = 0xac); NONFAILING(*(uint8_t*)0x2000002a = 0x14); NONFAILING(*(uint8_t*)0x2000002b = 0); NONFAILING(*(uint8_t*)0x2000002c = 0xaa); NONFAILING(*(uint8_t*)0x2000002d = 0xac); NONFAILING(*(uint8_t*)0x2000002e = 0x14); NONFAILING(*(uint8_t*)0x2000002f = 0); NONFAILING(*(uint8_t*)0x20000030 = 0xaa); NONFAILING(*(uint8_t*)0x20000031 = 0x89); NONFAILING(*(uint8_t*)0x20000032 = 0x23); NONFAILING(*(uint8_t*)0x20000033 = 1); NONFAILING(*(uint32_t*)0x20000034 = htobe32(0xe0000001)); NONFAILING(*(uint8_t*)0x20000038 = 0xac); NONFAILING(*(uint8_t*)0x20000039 = 0x14); NONFAILING(*(uint8_t*)0x2000003a = 0); NONFAILING(*(uint8_t*)0x2000003b = 0xbb); NONFAILING(*(uint8_t*)0x2000003c = 0xac); NONFAILING(*(uint8_t*)0x2000003d = 0x14); NONFAILING(*(uint8_t*)0x2000003e = 0); NONFAILING(*(uint8_t*)0x2000003f = 0xbb); NONFAILING(*(uint8_t*)0x20000040 = 0xac); NONFAILING(*(uint8_t*)0x20000041 = 0x14); NONFAILING(*(uint8_t*)0x20000042 = 0); NONFAILING(*(uint8_t*)0x20000043 = 0xaa); NONFAILING(*(uint32_t*)0x20000044 = htobe32(-1)); NONFAILING(*(uint32_t*)0x20000048 = htobe32(-1)); NONFAILING(*(uint32_t*)0x2000004c = htobe32(0)); NONFAILING(*(uint32_t*)0x20000050 = htobe32(-1)); NONFAILING(*(uint8_t*)0x20000054 = 0x88); NONFAILING(*(uint8_t*)0x20000055 = 0xc); NONFAILING(memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10)); NONFAILING(*(uint8_t*)0x20000060 = 0x82); NONFAILING(*(uint8_t*)0x20000061 = 0x11); NONFAILING(memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15)); NONFAILING(*(uint8_t*)0x20000071 = 0x89); NONFAILING(*(uint8_t*)0x20000072 = 0x1b); NONFAILING(*(uint8_t*)0x20000073 = 7); NONFAILING(*(uint32_t*)0x20000074 = htobe32(-1)); NONFAILING(*(uint32_t*)0x20000078 = htobe32(0)); NONFAILING(*(uint32_t*)0x2000007c = htobe32(0)); NONFAILING(*(uint32_t*)0x20000080 = htobe32(0xe0000002)); NONFAILING(*(uint32_t*)0x20000084 = htobe32(0x100)); NONFAILING(*(uint32_t*)0x20000088 = htobe32(0xe0000002)); NONFAILING(*(uint8_t*)0x2000008c = 0x83); NONFAILING(*(uint8_t*)0x2000008d = 7); NONFAILING(*(uint8_t*)0x2000008e = 7); NONFAILING(*(uint32_t*)0x2000008f = htobe32(0xe0000001)); NONFAILING(*(uint8_t*)0x20000096 = 0xc); NONFAILING(*(uint8_t*)0x20000097 = 2); NONFAILING(*(uint16_t*)0x20000098 = htobe16(0)); NONFAILING(*(uint8_t*)0x2000009a = 0xf2); NONFAILING(*(uint8_t*)0x2000009b = 0x1f); NONFAILING(*(uint16_t*)0x2000009c = 0); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6)); NONFAILING(*(uint16_t*)0x200000a0 = htobe16(0xf63)); NONFAILING(*(uint16_t*)0x200000a2 = htobe16(0x65)); NONFAILING(*(uint16_t*)0x200000a4 = htobe16(0xdfc5)); NONFAILING(*(uint8_t*)0x200000a6 = 0x97); NONFAILING(*(uint8_t*)0x200000a7 = 0xf0); NONFAILING(*(uint16_t*)0x200000a8 = htobe16(0x20)); NONFAILING(*(uint32_t*)0x200000aa = htobe32(0)); NONFAILING(*(uint32_t*)0x200000ae = htobe32(-1)); NONFAILING(*(uint8_t*)0x200000b2 = 0); NONFAILING(*(uint8_t*)0x200000b3 = 7); NONFAILING(*(uint8_t*)0x200000b4 = 0x1b); NONFAILING(*(uint8_t*)0x200000b5 = 8); NONFAILING(*(uint32_t*)0x200000b6 = htobe32(-1)); NONFAILING(*(uint32_t*)0x200000ba = htobe32(-1)); NONFAILING(*(uint32_t*)0x200000be = htobe32(0xe0000002)); NONFAILING(*(uint32_t*)0x200000c2 = htobe32(0xe0000002)); NONFAILING(*(uint32_t*)0x200000c6 = htobe32(0xe0000001)); NONFAILING(*(uint32_t*)0x200000ca = htobe32(0x80)); NONFAILING(*(uint8_t*)0x200000ce = 0x89); NONFAILING(*(uint8_t*)0x200000cf = 7); NONFAILING(*(uint8_t*)0x200000d0 = 0xfc); NONFAILING(*(uint32_t*)0x200000d1 = htobe32(0x7f000001)); NONFAILING(*(uint8_t*)0x200000d5 = 0x94); NONFAILING(*(uint8_t*)0x200000d6 = 6); NONFAILING(*(uint32_t*)0x200000d7 = htobe32(3)); NONFAILING(memcpy((void*)0x200000de, "\xa2\x33", 2)); struct csum_inet csum_1; csum_inet_init(&csum_1); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74)); NONFAILING(*(uint16_t*)0x20000098 = csum_inet_digest(&csum_1)); struct csum_inet csum_2; csum_inet_init(&csum_2); NONFAILING(csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132)); NONFAILING(*(uint16_t*)0x2000001c = csum_inet_digest(&csum_2)); break; case 11: NONFAILING(memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41)); NONFAILING(syz_execute_func(0x20000100)); break; case 12: break; case 13: NONFAILING(syz_open_pts()); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; } :359:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :357:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor603746253 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/14 (8.34s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { fprintf(stderr, "### start\n"); int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; res = syscall(SYS_bind, r[1], 0x20000040ul, 8ul); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: *(uint32_t*)0x200000c0 = 8; res = syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: *(uint32_t*)0x20000140 = 0xc; res = syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; res = syscall(SYS_readv, r[2], 0x20001340ul, 3ul); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; res = syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; res = syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; res = syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); (void)res; break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); res = -1; errno = EFAULT; res = syz_execute_func(0x20000100); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: (void)res; break; case 13: res = -1; errno = EFAULT; res = syz_open_pts(); fprintf(stderr, "### call=13 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_none(); return 0; } :331:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :329:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor803947345 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/7 (4.61s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:10 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: socketpair(0x18, 0x1, 0x9e, &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) bind(r1, &(0x7f0000000040)=@un=@abs={0x0, 0x0, 0x2}, 0x8) getpeername$unix(r1, &(0x7f0000000080)=@abs, &(0x7f00000000c0)=0x8) getpeername(r1, &(0x7f0000000100)=@in, &(0x7f0000000140)=0xc) r2 = accept(r0, &(0x7f0000000180)=@in, &(0x7f00000001c0)=0xc) readv(r2, &(0x7f0000001340)=[{&(0x7f0000000200)=""/121, 0x79}, {&(0x7f0000000280)=""/4096, 0x1000}, {&(0x7f0000001280)=""/180, 0xb4}], 0x3) recvfrom(r0, &(0x7f0000001380)=""/145, 0x91, 0x801, &(0x7f0000001440)=@un=@abs={0x0, 0x0, 0x2}, 0x8) ioctl$BIOCSETWF(0xffffffffffffff9c, 0x80104277, &(0x7f00000014c0)={0x1, &(0x7f0000001480)=[{0x6, 0x50, 0x6, 0x9}]}) r3 = openat(0xffffffffffffff9c, &(0x7f0000001500)='./file0\x00', 0x80, 0x55) ioctl$VMM_IOC_TERM(r3, 0x80045604, &(0x7f0000001540)={0x5}) syz_emit_ethernet(0xe0, &(0x7f0000000000)={@broadcast, @local, [{[], {0x8100, 0x6, 0x0, 0x1}}], {@ipv4={0x800, {{0x21, 0x4, 0x0, 0x3d, 0xce, 0x66, 0x8, 0xb5, 0x16, 0x0, @broadcast, @empty, {[@ssrr={0x89, 0xb, 0xc2, [@local={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}]}, @ssrr={0x89, 0x23, 0x1, [@multicast1, @remote={0xac, 0x14, 0x0}, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, @broadcast, @broadcast, @empty, @broadcast]}, @generic={0x88, 0xc, "f6c9d88d8d28f603df8e"}, @generic={0x82, 0x11, "448bc19f8c32cad3eed7baeb393923"}, @ssrr={0x89, 0x1b, 0x7, [@broadcast, @empty, @empty, @multicast2, @rand_addr=0x100, @multicast2]}, @lsrr={0x83, 0x7, 0x7, [@multicast1]}]}}, @icmp=@parameter_prob={0xc, 0x2, 0x0, 0xf2, 0x1f, 0x0, {0x10, 0x4, 0x2, 0x1f, 0xf63, 0x65, 0xdfc5, 0x97, 0xf0, 0x20, @empty, @broadcast, {[@end, @rr={0x7, 0x1b, 0x8, [@broadcast, @broadcast, @multicast2, @multicast2, @multicast1, @rand_addr=0x80]}, @ssrr={0x89, 0x7, 0xfc, [@loopback]}, @ra={0x94, 0x6, 0x3}]}}, "a233"}}}}}) syz_execute_func(&(0x7f0000000100)="45de030faaf3ac44c178e828c421215d696566460f38174500e6008c6cef0e430f01dbc4418f2a530a") syz_extract_tcp_res(&(0x7f0000000140), 0x800, 0x1000) syz_open_pts() csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 500); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 15000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socketpair, 0x18ul, 1ul, 0x9e, 0x20000000ul); if (res != -1) { r[0] = *(uint32_t*)0x20000000; r[1] = *(uint32_t*)0x20000004; } break; case 1: *(uint16_t*)0x20000040 = 0; *(uint8_t*)0x20000042 = 0; *(uint32_t*)0x20000044 = 0x4e22; syscall(SYS_bind, r[1], 0x20000040ul, 8ul); break; case 2: *(uint32_t*)0x200000c0 = 8; syscall(SYS_getpeername, r[1], 0x20000080ul, 0x200000c0ul); break; case 3: *(uint32_t*)0x20000140 = 0xc; syscall(SYS_getpeername, r[1], 0x20000100ul, 0x20000140ul); break; case 4: *(uint32_t*)0x200001c0 = 0xc; res = syscall(SYS_accept, r[0], 0x20000180ul, 0x200001c0ul); if (res != -1) r[2] = res; break; case 5: *(uint64_t*)0x20001340 = 0x20000200; *(uint64_t*)0x20001348 = 0x79; *(uint64_t*)0x20001350 = 0x20000280; *(uint64_t*)0x20001358 = 0x1000; *(uint64_t*)0x20001360 = 0x20001280; *(uint64_t*)0x20001368 = 0xb4; syscall(SYS_readv, r[2], 0x20001340ul, 3ul); break; case 6: *(uint16_t*)0x20001440 = 0; *(uint8_t*)0x20001442 = 0; *(uint32_t*)0x20001444 = 0x4e22; syscall(SYS_recvfrom, r[0], 0x20001380ul, 0x91ul, 0x801ul, 0x20001440ul, 8ul); break; case 7: *(uint32_t*)0x200014c0 = 1; *(uint64_t*)0x200014c8 = 0x20001480; *(uint16_t*)0x20001480 = 6; *(uint8_t*)0x20001482 = 0x50; *(uint8_t*)0x20001483 = 6; *(uint32_t*)0x20001484 = 9; syscall(SYS_ioctl, 0xffffff9c, 0x80104277ul, 0x200014c0ul); break; case 8: memcpy((void*)0x20001500, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20001500ul, 0x80ul, 0x55ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x20001540 = 5; syscall(SYS_ioctl, r[3], 0x80045604ul, 0x20001540ul); break; case 10: *(uint8_t*)0x20000000 = -1; *(uint8_t*)0x20000001 = -1; *(uint8_t*)0x20000002 = -1; *(uint8_t*)0x20000003 = -1; *(uint8_t*)0x20000004 = -1; *(uint8_t*)0x20000005 = -1; *(uint8_t*)0x20000006 = 0xaa; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0xaa; *(uint8_t*)0x20000009 = 0xaa; *(uint8_t*)0x2000000a = 0xaa; *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x20000012, 0x21, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x20000012, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x20000013, 0x3d, 2, 6); *(uint16_t*)0x20000014 = htobe16(0xce); *(uint16_t*)0x20000016 = htobe16(0x66); *(uint16_t*)0x20000018 = htobe16(8); *(uint8_t*)0x2000001a = 0xb5; *(uint8_t*)0x2000001b = 0x16; *(uint16_t*)0x2000001c = htobe16(0); *(uint32_t*)0x2000001e = htobe32(-1); *(uint32_t*)0x20000022 = htobe32(0); *(uint8_t*)0x20000026 = 0x89; *(uint8_t*)0x20000027 = 0xb; *(uint8_t*)0x20000028 = 0xc2; *(uint8_t*)0x20000029 = 0xac; *(uint8_t*)0x2000002a = 0x14; *(uint8_t*)0x2000002b = 0; *(uint8_t*)0x2000002c = 0xaa; *(uint8_t*)0x2000002d = 0xac; *(uint8_t*)0x2000002e = 0x14; *(uint8_t*)0x2000002f = 0; *(uint8_t*)0x20000030 = 0xaa; *(uint8_t*)0x20000031 = 0x89; *(uint8_t*)0x20000032 = 0x23; *(uint8_t*)0x20000033 = 1; *(uint32_t*)0x20000034 = htobe32(0xe0000001); *(uint8_t*)0x20000038 = 0xac; *(uint8_t*)0x20000039 = 0x14; *(uint8_t*)0x2000003a = 0; *(uint8_t*)0x2000003b = 0xbb; *(uint8_t*)0x2000003c = 0xac; *(uint8_t*)0x2000003d = 0x14; *(uint8_t*)0x2000003e = 0; *(uint8_t*)0x2000003f = 0xbb; *(uint8_t*)0x20000040 = 0xac; *(uint8_t*)0x20000041 = 0x14; *(uint8_t*)0x20000042 = 0; *(uint8_t*)0x20000043 = 0xaa; *(uint32_t*)0x20000044 = htobe32(-1); *(uint32_t*)0x20000048 = htobe32(-1); *(uint32_t*)0x2000004c = htobe32(0); *(uint32_t*)0x20000050 = htobe32(-1); *(uint8_t*)0x20000054 = 0x88; *(uint8_t*)0x20000055 = 0xc; memcpy((void*)0x20000056, "\xf6\xc9\xd8\x8d\x8d\x28\xf6\x03\xdf\x8e", 10); *(uint8_t*)0x20000060 = 0x82; *(uint8_t*)0x20000061 = 0x11; memcpy((void*)0x20000062, "\x44\x8b\xc1\x9f\x8c\x32\xca\xd3\xee\xd7\xba\xeb\x39\x39\x23", 15); *(uint8_t*)0x20000071 = 0x89; *(uint8_t*)0x20000072 = 0x1b; *(uint8_t*)0x20000073 = 7; *(uint32_t*)0x20000074 = htobe32(-1); *(uint32_t*)0x20000078 = htobe32(0); *(uint32_t*)0x2000007c = htobe32(0); *(uint32_t*)0x20000080 = htobe32(0xe0000002); *(uint32_t*)0x20000084 = htobe32(0x100); *(uint32_t*)0x20000088 = htobe32(0xe0000002); *(uint8_t*)0x2000008c = 0x83; *(uint8_t*)0x2000008d = 7; *(uint8_t*)0x2000008e = 7; *(uint32_t*)0x2000008f = htobe32(0xe0000001); *(uint8_t*)0x20000096 = 0xc; *(uint8_t*)0x20000097 = 2; *(uint16_t*)0x20000098 = htobe16(0); *(uint8_t*)0x2000009a = 0xf2; *(uint8_t*)0x2000009b = 0x1f; *(uint16_t*)0x2000009c = 0; STORE_BY_BITMASK(uint8_t, , 0x2000009e, 0x10, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x2000009f, 0x1f, 2, 6); *(uint16_t*)0x200000a0 = htobe16(0xf63); *(uint16_t*)0x200000a2 = htobe16(0x65); *(uint16_t*)0x200000a4 = htobe16(0xdfc5); *(uint8_t*)0x200000a6 = 0x97; *(uint8_t*)0x200000a7 = 0xf0; *(uint16_t*)0x200000a8 = htobe16(0x20); *(uint32_t*)0x200000aa = htobe32(0); *(uint32_t*)0x200000ae = htobe32(-1); *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 7; *(uint8_t*)0x200000b4 = 0x1b; *(uint8_t*)0x200000b5 = 8; *(uint32_t*)0x200000b6 = htobe32(-1); *(uint32_t*)0x200000ba = htobe32(-1); *(uint32_t*)0x200000be = htobe32(0xe0000002); *(uint32_t*)0x200000c2 = htobe32(0xe0000002); *(uint32_t*)0x200000c6 = htobe32(0xe0000001); *(uint32_t*)0x200000ca = htobe32(0x80); *(uint8_t*)0x200000ce = 0x89; *(uint8_t*)0x200000cf = 7; *(uint8_t*)0x200000d0 = 0xfc; *(uint32_t*)0x200000d1 = htobe32(0x7f000001); *(uint8_t*)0x200000d5 = 0x94; *(uint8_t*)0x200000d6 = 6; *(uint32_t*)0x200000d7 = htobe32(3); memcpy((void*)0x200000de, "\xa2\x33", 2); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20000096, 74); *(uint16_t*)0x20000098 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20000012, 132); *(uint16_t*)0x2000001c = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x20000100, "\x45\xde\x03\x0f\xaa\xf3\xac\x44\xc1\x78\xe8\x28\xc4\x21\x21\x5d\x69\x65\x66\x46\x0f\x38\x17\x45\x00\xe6\x00\x8c\x6c\xef\x0e\x43\x0f\x01\xdb\xc4\x41\x8f\x2a\x53\x0a", 41); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); use_temporary_dir(); do_sandbox_none(); return 0; } :330:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :328:3: note: previous statement is here if (current_time_ms() - start < 15000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor651986800 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/4 (5.59s) csource_test.go:122: --- FAIL: TestGenerate/openbsd/amd64/5 (6.11s) csource_test.go:122: --- FAIL: TestGenerate/openbsd/amd64/2 (6.03s) csource_test.go:122: --- FAIL: TestGenerate/openbsd/amd64/6 (6.61s) csource_test.go:122: --- FAIL: TestGenerate/openbsd/amd64/1 (5.85s) csource_test.go:122: FAIL FAIL github.com/google/syzkaller/pkg/csource 113.840s ok github.com/google/syzkaller/pkg/db (cached) ? github.com/google/syzkaller/pkg/debugtracer [no test files] ok github.com/google/syzkaller/pkg/email (cached) ? github.com/google/syzkaller/pkg/gce [no test files] ? github.com/google/syzkaller/pkg/gcs [no test files] ? github.com/google/syzkaller/pkg/hash [no test files] ok github.com/google/syzkaller/pkg/host (cached) ? github.com/google/syzkaller/pkg/html [no test files] ok github.com/google/syzkaller/pkg/ifuzz (cached) ? github.com/google/syzkaller/pkg/ifuzz/iset [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc/generated [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86 [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/generated [no test files] ok github.com/google/syzkaller/pkg/instance 6.048s ok github.com/google/syzkaller/pkg/ipc (cached) ? github.com/google/syzkaller/pkg/ipc/ipcconfig [no test files] ? github.com/google/syzkaller/pkg/kcidb [no test files] ok github.com/google/syzkaller/pkg/kconfig 0.274s ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig 1.933s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 9.376s ok github.com/google/syzkaller/pkg/repro 2.353s ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest (cached) ok github.com/google/syzkaller/pkg/serializer (cached) ? github.com/google/syzkaller/pkg/signal [no test files] ok github.com/google/syzkaller/pkg/symbolizer (cached) ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs (cached) ok github.com/google/syzkaller/prog (cached) ok github.com/google/syzkaller/prog/test (cached) ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux (cached) ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ok github.com/google/syzkaller/sys/openbsd (cached) ? github.com/google/syzkaller/sys/openbsd/gen [no test files] ? github.com/google/syzkaller/sys/syz-extract [no test files] ? github.com/google/syzkaller/sys/syz-sysgen [no test files] ? github.com/google/syzkaller/sys/targets [no test files] ? github.com/google/syzkaller/sys/test [no test files] ? github.com/google/syzkaller/sys/test/gen [no test files] ? github.com/google/syzkaller/sys/trusty [no test files] ? github.com/google/syzkaller/sys/trusty/gen [no test files] ? github.com/google/syzkaller/sys/windows [no test files] ? github.com/google/syzkaller/sys/windows/gen [no test files] ok github.com/google/syzkaller/syz-ci 4.738s ok github.com/google/syzkaller/syz-fuzzer (cached) ok github.com/google/syzkaller/syz-hub (cached) ok github.com/google/syzkaller/syz-hub/state (cached) ok github.com/google/syzkaller/syz-manager 17.836s ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ? github.com/google/syzkaller/tools/syz-kconf [no test files] ok github.com/google/syzkaller/tools/syz-linter (cached) ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser (cached) ok github.com/google/syzkaller/tools/syz-trace2syz/proggen (cached) ? github.com/google/syzkaller/tools/syz-tty [no test files] ? github.com/google/syzkaller/tools/syz-upgrade [no test files] ? github.com/google/syzkaller/tools/syz-usbgen [no test files] ok github.com/google/syzkaller/vm 10.932s ? github.com/google/syzkaller/vm/adb [no test files] ? github.com/google/syzkaller/vm/bhyve [no test files] ? github.com/google/syzkaller/vm/gce [no test files] ? github.com/google/syzkaller/vm/gvisor [no test files] ok github.com/google/syzkaller/vm/isolated 0.929s ? github.com/google/syzkaller/vm/kvm [no test files] ? github.com/google/syzkaller/vm/odroid [no test files] ? github.com/google/syzkaller/vm/qemu [no test files] ok github.com/google/syzkaller/vm/vmimpl 1.097s ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL