ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 1.267s ok github.com/google/syzkaller/pkg/ast 2.302s ok github.com/google/syzkaller/pkg/bisect 50.613s ok github.com/google/syzkaller/pkg/build 0.207s ok github.com/google/syzkaller/pkg/compiler 15.341s ok github.com/google/syzkaller/pkg/config (cached) ok github.com/google/syzkaller/pkg/cover (cached) ? github.com/google/syzkaller/pkg/cover/backend [no test files] --- FAIL: TestGenerate (8.48s) --- FAIL: TestGenerate/freebsd/386 (1.21s) csource_test.go:68: seed=1612478805926431458 --- FAIL: TestGenerate/freebsd/386/0 (1.07s) csource_test.go:124: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :202:10: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor639498041 -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/12 (1.47s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:true Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (sig == SIGBUS) { valid = 1; } if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) ({ int ok = 1; __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } else ok = 0; __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); ok; }) static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: NONFAILING(memcpy((void*)0x10000000, "./file0\000", 8)); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: NONFAILING(memcpy((void*)0x10000040, "./file0\000", 8)); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: NONFAILING(memcpy((void*)0x100000c0, "./file0\000", 8)); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: NONFAILING(memcpy((void*)0x10000100, "./file0\000", 8)); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: NONFAILING(*(uint8_t*)0x10000140 = 0xa); NONFAILING(*(uint8_t*)0x10000141 = 1); NONFAILING(memcpy((void*)0x10000142, "./file0\000", 8)); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: NONFAILING(memcpy((void*)0x10000180, "./file0\000", 8)); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: NONFAILING(memcpy((void*)0x100001c0, "./file0\000", 8)); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: NONFAILING(*(uint32_t*)0x10000200 = 0); NONFAILING(*(uint16_t*)0x10000204 = 3); NONFAILING(*(uint8_t*)0x10000206 = 9); NONFAILING(*(uint32_t*)0x10000240 = 8); syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: NONFAILING(memcpy((void*)0x10000280, "./file0\000", 8)); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: NONFAILING(*(uint8_t*)0x10000380 = 0x10); NONFAILING(*(uint8_t*)0x10000381 = 2); NONFAILING(*(uint16_t*)0x10000382 = htobe16(0x4e23)); NONFAILING(*(uint32_t*)0x10000384 = htobe32(0xe0000002)); NONFAILING(*(uint8_t*)0x10000388 = 0); NONFAILING(*(uint8_t*)0x10000389 = 0); NONFAILING(*(uint8_t*)0x1000038a = 0); NONFAILING(*(uint8_t*)0x1000038b = 0); NONFAILING(*(uint8_t*)0x1000038c = 0); NONFAILING(*(uint8_t*)0x1000038d = 0); NONFAILING(*(uint8_t*)0x1000038e = 0); NONFAILING(*(uint8_t*)0x1000038f = 0); NONFAILING(*(uint64_t*)0x10000390 = 0); NONFAILING(*(uint64_t*)0x10000398 = 0); NONFAILING(*(uint64_t*)0x100003a0 = 0); NONFAILING(*(uint64_t*)0x100003a8 = 0); NONFAILING(*(uint64_t*)0x100003b0 = 0); NONFAILING(*(uint64_t*)0x100003b8 = 0); NONFAILING(*(uint64_t*)0x100003c0 = 0); NONFAILING(*(uint64_t*)0x100003c8 = 0); NONFAILING(*(uint64_t*)0x100003d0 = 0); NONFAILING(*(uint64_t*)0x100003d8 = 0); NONFAILING(*(uint64_t*)0x100003e0 = 0); NONFAILING(*(uint64_t*)0x100003e8 = 0); NONFAILING(*(uint64_t*)0x100003f0 = 0); NONFAILING(*(uint64_t*)0x100003f8 = 0); NONFAILING(*(uint64_t*)0x10000400 = 0); NONFAILING(*(uint32_t*)0x10000408 = 0); NONFAILING(*(uint16_t*)0x1000040c = 0x1ff); NONFAILING(*(uint16_t*)0x1000040e = 5); NONFAILING(*(uint16_t*)0x10000410 = 0x7ff); NONFAILING(*(uint32_t*)0x10000440 = 0x94); syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: NONFAILING(*(uint8_t*)0x10000000 = 0xaa); NONFAILING(*(uint8_t*)0x10000001 = 0xaa); NONFAILING(*(uint8_t*)0x10000002 = 0xaa); NONFAILING(*(uint8_t*)0x10000003 = 0xaa); NONFAILING(*(uint8_t*)0x10000004 = 0xaa); NONFAILING(*(uint8_t*)0x10000005 = 0xaa); NONFAILING(*(uint8_t*)0x10000006 = 0); NONFAILING(*(uint8_t*)0x10000007 = 0); NONFAILING(*(uint8_t*)0x10000008 = 0); NONFAILING(*(uint8_t*)0x10000009 = 0); NONFAILING(*(uint8_t*)0x1000000a = 0); NONFAILING(*(uint8_t*)0x1000000b = 0); NONFAILING(*(uint16_t*)0x1000000c = htobe16(0x800)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6)); NONFAILING(*(uint16_t*)0x10000010 = htobe16(0x3c)); NONFAILING(*(uint16_t*)0x10000012 = htobe16(0x68)); NONFAILING(*(uint16_t*)0x10000014 = htobe16(0x7b)); NONFAILING(*(uint8_t*)0x10000016 = 0x78); NONFAILING(*(uint8_t*)0x10000017 = 0x35); NONFAILING(*(uint16_t*)0x10000018 = htobe16(0)); NONFAILING(*(uint8_t*)0x1000001a = 0xac); NONFAILING(*(uint8_t*)0x1000001b = 0x14); NONFAILING(*(uint8_t*)0x1000001c = 0); NONFAILING(*(uint8_t*)0x1000001d = 0xbb); NONFAILING(*(uint8_t*)0x1000001e = 0xac); NONFAILING(*(uint8_t*)0x1000001f = 0x14); NONFAILING(*(uint8_t*)0x10000020 = 0); NONFAILING(*(uint8_t*)0x10000021 = 0xaa); NONFAILING(*(uint8_t*)0x10000022 = 0x44); NONFAILING(*(uint8_t*)0x10000023 = 0x14); NONFAILING(*(uint8_t*)0x10000024 = 1); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4)); NONFAILING(*(uint8_t*)0x10000026 = 0xac); NONFAILING(*(uint8_t*)0x10000027 = 0x14); NONFAILING(*(uint8_t*)0x10000028 = 0); NONFAILING(*(uint8_t*)0x10000029 = 0xaa); NONFAILING(*(uint32_t*)0x1000002a = htobe32(0x23c0)); NONFAILING(*(uint32_t*)0x1000002e = htobe32(0x401)); NONFAILING(*(uint32_t*)0x10000032 = htobe32(0xc3)); NONFAILING(*(uint8_t*)0x10000036 = 0xd); NONFAILING(*(uint8_t*)0x10000037 = 0); NONFAILING(*(uint16_t*)0x10000038 = htobe16(0)); NONFAILING(*(uint16_t*)0x1000003a = htobe16(2)); NONFAILING(*(uint16_t*)0x1000003c = htobe16(6)); NONFAILING(*(uint32_t*)0x1000003e = htobe32(0x1ff)); NONFAILING(*(uint32_t*)0x10000042 = htobe32(2)); NONFAILING(*(uint32_t*)0x10000046 = htobe32(4)); struct csum_inet csum_1; csum_inet_init(&csum_1); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20)); NONFAILING(*(uint16_t*)0x10000038 = csum_inet_digest(&csum_1)); struct csum_inet csum_2; csum_inet_init(&csum_2); NONFAILING(csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40)); NONFAILING(*(uint16_t*)0x10000018 = csum_inet_digest(&csum_2)); break; case 11: NONFAILING(memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62)); NONFAILING(syz_execute_func(0x10000080)); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; } :375:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor469409747 -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 (1.58s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :345:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor661755064 -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 (1.89s) csource_test.go:124: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23 + procid*4); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0 + procid*1; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0 + procid*1; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0 + procid*1; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :355:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor267006845 -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/14 (2.17s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); res = syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); res = syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); res = syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); res = syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); res = syscall(SYS_lchmod, 0x10000180, 8); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); res = syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; res = syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; res = syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); (void)res; break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); res = -1; errno = EFAULT; res = syz_execute_func(0x10000080); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: (void)res; break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :345:17: error: use of undeclared identifier 'SYS___realpathat' res = syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor190507521 -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/1 (2.11s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :343:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor908740791 -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/3 (2.39s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:false RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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 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 loop(void) { int i, call, thread; for (call = 0; call < 13; 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); } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :262:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor556402346 -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 (2.61s) csource_test.go:124: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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; int collide = 0; again: for (call = 0; call < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :351:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor922422747 -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 (2.34s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23 + procid*4); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0 + procid*1; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0 + procid*1; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0 + procid*1; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :345:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor728433004 -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 (1.33s) csource_test.go:122: --- FAIL: TestGenerate/freebsd/386/10 (1.93s) csource_test.go:122: --- FAIL: TestGenerate/freebsd/386/7 (1.99s) csource_test.go:124: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:10 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: chflagsat(0xffffffffffffffff, &(0x7f0000000000)='./file0\x00', 0x101900, 0x0) __realpathat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', &(0x7f0000000080)=""/4, 0x4, 0x0) r0 = open$dir(&(0x7f00000000c0)='./file0\x00', 0x8000, 0x40) mknodat(r0, &(0x7f0000000100)='./file0\x00', 0x100, 0xfffff001) connectat(r0, 0xffffffffffffff9c, &(0x7f0000000140)=@un=@file={0xa, 0x1, './file0\x00'}, 0xa) lchmod(&(0x7f0000000180)='./file0\x00', 0x8) freebsd12_shm_open(&(0x7f00000001c0)='./file0\x00', 0x2, 0x1b3) getsockopt$inet_sctp_SCTP_EVENT(0xffffffffffffffff, 0x84, 0x1e, &(0x7f0000000200)={0x0, 0x3, 0x9}, &(0x7f0000000240)=0x8) r1 = openat(r0, &(0x7f0000000280)='./file0\x00', 0x4, 0x54) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(r1, 0x84, 0x23, &(0x7f0000000380)={@in={{0x10, 0x2, 0x3, @multicast2}}, 0x0, 0x1ff, 0x5, 0x7ff}, &(0x7f0000000440)=0x94) syz_emit_ethernet(0x4a, &(0x7f0000000000)={@local, @empty, [], {@ipv4={0x800, {{0xa, 0x4, 0x0, 0x3b, 0x3c, 0x68, 0x7b, 0x78, 0x35, 0x0, @remote={0xac, 0x14, 0x0}, @local={0xac, 0x14, 0x0}, {[@timestamp={0x44, 0x14, 0x1, 0x0, 0x8, [{[@local={0xac, 0x14, 0x0}], 0x23c0}, {[], 0x401}, {[], 0xc3}]}]}}, @icmp=@timestamp={0xd, 0x0, 0x0, 0x2, 0x6, 0x1ff, 0x2, 0x4}}}}}) syz_execute_func(&(0x7f0000000080)="660f381cddf0810803000000c44b0fc4e15d73f6fe2e3ef20f38f137f009aafeefffffc4e1177dc73e66643e260fbf4832c4e271907c95a30f8f06000000") syz_extract_tcp_res(&(0x7f00000000c0), 0x2, 0x4) csource_test.go:125: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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 < 13; 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); } } #ifndef SYS_freebsd12_shm_open #define SYS_freebsd12_shm_open 482 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x10000000, "./file0\000", 8); syscall(SYS_chflagsat, -1, 0x10000000, 0x101900, 0); break; case 1: memcpy((void*)0x10000040, "./file0\000", 8); syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); break; case 2: memcpy((void*)0x100000c0, "./file0\000", 8); res = syscall(SYS_open, 0x100000c0, 0x8000, 0x40); if (res != -1) r[0] = res; break; case 3: memcpy((void*)0x10000100, "./file0\000", 8); syscall(SYS_mknodat, (intptr_t)r[0], 0x10000100, 0x100, 0xfffff001ull); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 1; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_connectat, (intptr_t)r[0], 0xffffff9c, 0x10000140, 0xa); break; case 5: memcpy((void*)0x10000180, "./file0\000", 8); syscall(SYS_lchmod, 0x10000180, 8); break; case 6: memcpy((void*)0x100001c0, "./file0\000", 8); syscall(SYS_freebsd12_shm_open, 0x100001c0, 2, 0x1b3); break; case 7: *(uint32_t*)0x10000200 = 0; *(uint16_t*)0x10000204 = 3; *(uint8_t*)0x10000206 = 9; *(uint32_t*)0x10000240 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x1e, 0x10000200, 0x10000240); break; case 8: memcpy((void*)0x10000280, "./file0\000", 8); res = syscall(SYS_openat, (intptr_t)r[0], 0x10000280, 4, 0x54); if (res != -1) r[1] = res; break; case 9: *(uint8_t*)0x10000380 = 0x10; *(uint8_t*)0x10000381 = 2; *(uint16_t*)0x10000382 = htobe16(0x4e23); *(uint32_t*)0x10000384 = htobe32(0xe0000002); *(uint8_t*)0x10000388 = 0; *(uint8_t*)0x10000389 = 0; *(uint8_t*)0x1000038a = 0; *(uint8_t*)0x1000038b = 0; *(uint8_t*)0x1000038c = 0; *(uint8_t*)0x1000038d = 0; *(uint8_t*)0x1000038e = 0; *(uint8_t*)0x1000038f = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint64_t*)0x100003e0 = 0; *(uint64_t*)0x100003e8 = 0; *(uint64_t*)0x100003f0 = 0; *(uint64_t*)0x100003f8 = 0; *(uint64_t*)0x10000400 = 0; *(uint32_t*)0x10000408 = 0; *(uint16_t*)0x1000040c = 0x1ff; *(uint16_t*)0x1000040e = 5; *(uint16_t*)0x10000410 = 0x7ff; *(uint32_t*)0x10000440 = 0x94; syscall(SYS_getsockopt, (intptr_t)r[1], 0x84, 0x23, 0x10000380, 0x10000440); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xaa; *(uint8_t*)0x10000006 = 0; *(uint8_t*)0x10000007 = 0; *(uint8_t*)0x10000008 = 0; *(uint8_t*)0x10000009 = 0; *(uint8_t*)0x1000000a = 0; *(uint8_t*)0x1000000b = 0; *(uint16_t*)0x1000000c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 0x3b, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x3c); *(uint16_t*)0x10000012 = htobe16(0x68); *(uint16_t*)0x10000014 = htobe16(0x7b); *(uint8_t*)0x10000016 = 0x78; *(uint8_t*)0x10000017 = 0x35; *(uint16_t*)0x10000018 = htobe16(0); *(uint8_t*)0x1000001a = 0xac; *(uint8_t*)0x1000001b = 0x14; *(uint8_t*)0x1000001c = 0; *(uint8_t*)0x1000001d = 0xbb; *(uint8_t*)0x1000001e = 0xac; *(uint8_t*)0x1000001f = 0x14; *(uint8_t*)0x10000020 = 0; *(uint8_t*)0x10000021 = 0xaa; *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0x14; *(uint8_t*)0x10000024 = 1; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 8, 4, 4); *(uint8_t*)0x10000026 = 0xac; *(uint8_t*)0x10000027 = 0x14; *(uint8_t*)0x10000028 = 0; *(uint8_t*)0x10000029 = 0xaa; *(uint32_t*)0x1000002a = htobe32(0x23c0); *(uint32_t*)0x1000002e = htobe32(0x401); *(uint32_t*)0x10000032 = htobe32(0xc3); *(uint8_t*)0x10000036 = 0xd; *(uint8_t*)0x10000037 = 0; *(uint16_t*)0x10000038 = htobe16(0); *(uint16_t*)0x1000003a = htobe16(2); *(uint16_t*)0x1000003c = htobe16(6); *(uint32_t*)0x1000003e = htobe32(0x1ff); *(uint32_t*)0x10000042 = htobe32(2); *(uint32_t*)0x10000046 = htobe32(4); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x10000036, 20); *(uint16_t*)0x10000038 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_2); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\x38\x1c\xdd\xf0\x81\x08\x03\x00\x00\x00\xc4\x4b\x0f\xc4\xe1\x5d\x73\xf6\xfe\x2e\x3e\xf2\x0f\x38\xf1\x37\xf0\x09\xaa\xfe\xef\xff\xff\xc4\xe1\x17\x7d\xc7\x3e\x66\x64\x3e\x26\x0f\xbf\x48\x32\xc4\xe2\x71\x90\x7c\x95\xa3\x0f\x8f\x06\x00\x00\x00", 62); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :343:11: error: use of undeclared identifier 'SYS___realpathat' syscall(SYS___realpathat, 0xffffff9c, 0x10000040, 0x10000080, 4, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor763109246 -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 (1.50s) csource_test.go:122: --- FAIL: TestGenerate/freebsd/386/8 (1.12s) csource_test.go:122: --- FAIL: TestGenerate/freebsd/386/4 (0.94s) csource_test.go:122: --- FAIL: TestGenerate/freebsd/386/5 (1.50s) csource_test.go:122: FAIL FAIL github.com/google/syzkaller/pkg/csource 18.394s 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 2.835s ? 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 3.451s ok github.com/google/syzkaller/pkg/ipc 9.383s ? 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.071s ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig 0.130s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 5.860s ok github.com/google/syzkaller/pkg/repro 0.258s ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 68.546s 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.462s ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs 16.515s ok github.com/google/syzkaller/prog 36.094s ok github.com/google/syzkaller/prog/test (cached) ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux 0.301s ? 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 0.346s ok github.com/google/syzkaller/syz-fuzzer 0.989s ok github.com/google/syzkaller/syz-hub 0.169s ok github.com/google/syzkaller/syz-hub/state 0.294s ok github.com/google/syzkaller/syz-manager 2.635s ? 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] ? github.com/google/syzkaller/tools/syz-kconf [no test files] ok github.com/google/syzkaller/tools/syz-linter 3.576s ? 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 0.114s ok github.com/google/syzkaller/tools/syz-trace2syz/proggen 0.575s ? 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 11.163s ? github.com/google/syzkaller/vm/adb [no test files] ? github.com/google/syzkaller/vm/bhyve [no test files] ? github.com/google/syzkaller/vm/gce [no test files] ? github.com/google/syzkaller/vm/gvisor [no test files] ok github.com/google/syzkaller/vm/isolated 0.147s ? 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 0.117s ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL