ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 0.722s ok github.com/google/syzkaller/pkg/ast 2.493s ok github.com/google/syzkaller/pkg/auth (cached) ok github.com/google/syzkaller/pkg/bisect 54.336s ok github.com/google/syzkaller/pkg/build 0.182s ok github.com/google/syzkaller/pkg/compiler 9.007s ? github.com/google/syzkaller/pkg/config [no test files] ok github.com/google/syzkaller/pkg/cover (cached) ok github.com/google/syzkaller/pkg/cover/backend (cached) --- FAIL: TestGenerate (5.91s) --- FAIL: TestGenerate/freebsd/386 (0.78s) csource_test.go:52: seed=1633436526488189434 --- FAIL: TestGenerate/freebsd/386/14 (0.64s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:true LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); res = syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); res = syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); res = syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); res = syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; res = syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: res = syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); break; case 9: res = syscall(SYS_fchown, -1, 0, -1); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); res = -1; errno = EFAULT; res = syz_execute_func(0x10000180); fprintf(stderr, "### call=10 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor503457183 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/13 (0.65s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor616544882 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/0 (0.65s) csource_test.go:118: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } #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; } static void sandbox_common() { if (setsid() == -1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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; *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); syscall(SYS_fchown, -1, 0, -1); memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :105:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :110:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :123:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor013007145 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/15 (0.67s) csource_test.go:118: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21 + procid*4); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0 + procid*1; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0 + procid*1; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :197:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :202:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :215:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor319538496 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/8 (0.72s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox: Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } 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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); loop(); return 0; } :194:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :199:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :212:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor010330740 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/9 (0.66s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:setuid Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_setuid(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor408850755 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/4 (0.68s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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 < 10; 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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor733650029 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/7 (0.75s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:10 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor036089576 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/11 (0.94s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:false HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); do_sandbox_none(); return 0; } :149:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :154:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :167:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor350861607 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/6 (0.88s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: preadv(0xffffffffffffff9c, &(0x7f0000000100)=[{&(0x7f0000000000)=""/246, 0xf6}], 0x1, 0x3) (fail_nth: 1) ioctl$EVIOCSKEYCODE_V2(0xffffffffffffffff, 0x80284504, &(0x7f0000000140)={0x18, 0x0, 0x0, 0x3, "c58a218bd7a6d43fa27fb7ecff97f8575080071a6e67ff4ae3da941255135f66"}) pipe2(&(0x7f0000000180)={0xffffffffffffffff, 0xffffffffffffffff}, 0x100000) bind$inet(r0, &(0x7f00000001c0)={0x10, 0x2, 0x1, @local={0xac, 0x14, 0x0}}, 0x10) r2 = openat$evdev(0xffffff9c, &(0x7f0000000200), 0x400, 0x0) setsockopt$inet_mreqsrc(r1, 0x0, 0x49, &(0x7f0000000240)={@loopback, @remote={0xac, 0x14, 0x0}}, 0xc) r3 = fhopen(&(0x7f0000000280)={{[0x7, 0xffff]}, {0x1, 0x200, "ff6b9be9cd59535cae92e72e488bf984"}}, 0x800) setsockopt$inet_tcp_TCP_TXTLS_MODE(r3, 0x6, 0x28, &(0x7f00000002c0)=0x2, 0x4) ioctl$UI_SET_FFBIT(r2, 0x2004556b) fchown(0xffffffffffffffff, 0x0, 0xffffffffffffffff) syz_extract_tcp_res$synack(&(0x7f0000000000)={0x41424344}, 0x1, 0x0) syz_emit_ethernet(0x13d, &(0x7f0000000040)={@broadcast, @random="fbefaa9b57d9", [], {@ipv4={0x800, {{0x6, 0x4, 0x2, 0x6, 0x12f, 0x67, 0x82, 0x7f, 0x3e, 0x0, @loopback, @empty, {[@end, @end]}}, @tcp={{0x2, 0x1, 0x41424344, r4, 0x0, 0x0, 0x9, 0x8, 0x1, 0x0, 0x9, {[@nop, @sack={0x5, 0xa, [0x8, 0x1000]}, @sack_perm={0x4, 0x2}, @sack_perm={0x4, 0x2}]}}, {"2a17c517488b9b69480a1d73e132ceaab06389b24a15ac7b84499fbcc2b99707d17062745906bfb74964f7071713a68860d7f0fd3c5f40082caf10633457f4af8dc90200812fa58c511675b526c00f63cad693e031d2a73f63fb5b6d6eaeb05da17be58bf9fd432eca9efd56d05df2e8a22b4f1f1c5d1928be69e5ddb6574b247f875585788212bf57006b20fa40a9da68c64a7ff33916faf00ddd00f15d0d557075c43870c40142cb9db2de70daa76a351e4cd007b5adf14aeae355bc6ea15f839dc15755cdedf8497bc8d75c3eb6a5d60dd3d79f0a0eefd5d7cb300c0b035a93f6624bae35e6bbe46b217af73fb83534eff0"}}}}}}) syz_execute_func(&(0x7f0000000180)="1fc4e1edddac8e00000000c4c135d9c1660f3a0957c835f76712c4e30d4b20fe0f2ac5c4c3cd7bd0fef26dc4c15df1e5") syz_extract_tcp_res(&(0x7f00000001c0), 0x1, 0xb6b) csource_test.go:119: 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 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } 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; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &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: *(uint32_t*)0x10000100 = 0x10000000; *(uint32_t*)0x10000104 = 0xf6; inject_fault(1); syscall(SYS_preadv, 0xffffff9c, 0x10000100, 1, 3); break; case 1: *(uint8_t*)0x10000140 = 0x18; *(uint8_t*)0x10000141 = 0; *(uint16_t*)0x10000142 = 0; *(uint32_t*)0x10000144 = 3; memcpy((void*)0x10000148, "\xc5\x8a\x21\x8b\xd7\xa6\xd4\x3f\xa2\x7f\xb7\xec\xff\x97\xf8\x57\x50\x80\x07\x1a\x6e\x67\xff\x4a\xe3\xda\x94\x12\x55\x13\x5f\x66", 32); syscall(SYS_ioctl, -1, 0x80284504, 0x10000140); break; case 2: res = syscall(SYS_pipe2, 0x10000180, 0x100000); if (res != -1) { r[0] = *(uint32_t*)0x10000180; r[1] = *(uint32_t*)0x10000184; } break; case 3: *(uint8_t*)0x100001c0 = 0x10; *(uint8_t*)0x100001c1 = 2; *(uint16_t*)0x100001c2 = htobe16(0x4e21 + procid*4); *(uint8_t*)0x100001c4 = 0xac; *(uint8_t*)0x100001c5 = 0x14; *(uint8_t*)0x100001c6 = 0 + procid*1; *(uint8_t*)0x100001c7 = 0xaa; memset((void*)0x100001c8, 0, 8); syscall(SYS_bind, (intptr_t)r[0], 0x100001c0, 0x10); break; case 4: memcpy((void*)0x10000200, "/dev/input/eventN\000", 18); res = syscall(SYS_openat, 0xffffff9c, 0x10000200, 0x400, 0); if (res != -1) r[2] = res; break; case 5: *(uint32_t*)0x10000240 = htobe32(0x7f000001); *(uint8_t*)0x10000244 = 0xac; *(uint8_t*)0x10000245 = 0x14; *(uint8_t*)0x10000246 = 0 + procid*1; *(uint8_t*)0x10000247 = 0xbb; *(uint32_t*)0x10000248 = htobe32(0); syscall(SYS_setsockopt, (intptr_t)r[1], 0, 0x49, 0x10000240, 0xc); break; case 6: *(uint32_t*)0x10000280 = 7; *(uint32_t*)0x10000284 = 0xffff; *(uint16_t*)0x10000288 = 1; *(uint16_t*)0x1000028a = 0x200; memcpy((void*)0x1000028c, "\xff\x6b\x9b\xe9\xcd\x59\x53\x5c\xae\x92\xe7\x2e\x48\x8b\xf9\x84", 16); res = syscall(SYS_fhopen, 0x10000280, 0x800); if (res != -1) r[3] = res; break; case 7: *(uint32_t*)0x100002c0 = 2; syscall(SYS_setsockopt, (intptr_t)r[3], 6, 0x28, 0x100002c0, 4); break; case 8: syscall(SYS_ioctl, (intptr_t)r[2], 0x2004556b, 0); break; case 9: syscall(SYS_fchown, -1, 0, -1); break; case 10: memcpy((void*)0x10000180, "\x1f\xc4\xe1\xed\xdd\xac\x8e\x00\x00\x00\x00\xc4\xc1\x35\xd9\xc1\x66\x0f\x3a\x09\x57\xc8\x35\xf7\x67\x12\xc4\xe3\x0d\x4b\x20\xfe\x0f\x2a\xc5\xc4\xc3\xcd\x7b\xd0\xfe\xf2\x6d\xc4\xc1\x5d\xf1\xe5", 48); syz_execute_func(0x10000180); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); setup_fault(); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :197:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :202:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :215:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: clang [-o /tmp/syz-executor536321626 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/2 (0.74s) csource_test.go:116: --- FAIL: TestGenerate/freebsd/386/5 (0.87s) csource_test.go:116: --- FAIL: TestGenerate/freebsd/386/1 (0.69s) csource_test.go:116: --- FAIL: TestGenerate/freebsd/386/3 (0.70s) csource_test.go:116: FAIL FAIL github.com/google/syzkaller/pkg/csource 9.035s 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 1.367s ? 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 1.205s ok github.com/google/syzkaller/pkg/ipc 4.888s ? 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.033s ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig (cached) ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 5.816s ok github.com/google/syzkaller/pkg/repro (cached) ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 47.101s ok github.com/google/syzkaller/pkg/serializer (cached) ? github.com/google/syzkaller/pkg/signal [no test files] ok github.com/google/syzkaller/pkg/symbolizer 0.252s ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs 8.589s 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/darwin [no test files] ? github.com/google/syzkaller/sys/darwin/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 (cached) 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 1.153s ? github.com/google/syzkaller/syz-runner [no test files] ok github.com/google/syzkaller/syz-verifier 0.107s ? 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-build [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] ok github.com/google/syzkaller/tools/syz-kconf (cached) ok github.com/google/syzkaller/tools/syz-linter 3.036s ? 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 (cached) ? 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 (cached) ? 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 (cached) ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL