ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 1.839s ok github.com/google/syzkaller/pkg/ast 2.357s ok github.com/google/syzkaller/pkg/bisect 49.602s ok github.com/google/syzkaller/pkg/build 0.123s ? github.com/google/syzkaller/pkg/cmdprof [no test files] ok github.com/google/syzkaller/pkg/compiler 10.810s ok github.com/google/syzkaller/pkg/config (cached) ? github.com/google/syzkaller/pkg/cover [no test files] --- FAIL: TestGenerate (6.02s) --- FAIL: TestGenerate/freebsd/386 (1.35s) csource_test.go:67: seed=1607238938081883469 --- FAIL: TestGenerate/freebsd/386/0 (1.37s) csource_test.go:123: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; syscall(SYS_fchflags, (intptr_t)r[0], 0x485); *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); syz_execute_func(0x10000080); } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :217:16: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor062718235 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/7 (1.34s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox: Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); syz_execute_func(0x10000080); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); loop(); return 0; } :345:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor552159237 -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.14s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: NONFAILING(*(uint32_t*)0x10000000 = 5); NONFAILING(*(uint32_t*)0x10000004 = 7); syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) NONFAILING(r[2] = *(uint32_t*)0x10000044); break; case 6: NONFAILING(memcpy((void*)0x10000080, "./file0\000", 8)); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: NONFAILING(memcpy((void*)0x100000c0, "./file0\000", 8)); NONFAILING(memcpy((void*)0x10000100, "\000", 1)); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: NONFAILING(*(uint32_t*)0x10000140 = 0xffffff9c); NONFAILING(*(uint16_t*)0x10000144 = 0xefac); NONFAILING(*(uint16_t*)0x10000146 = 0); NONFAILING(*(uint32_t*)0x10000148 = r[0]); NONFAILING(*(uint16_t*)0x1000014c = 0x24); NONFAILING(*(uint16_t*)0x1000014e = 0); NONFAILING(*(uint32_t*)0x10000150 = r[1]); NONFAILING(*(uint16_t*)0x10000154 = 0); NONFAILING(*(uint16_t*)0x10000156 = 0); NONFAILING(*(uint32_t*)0x10000158 = r[0]); NONFAILING(*(uint16_t*)0x1000015c = 0x40); NONFAILING(*(uint16_t*)0x1000015e = 0); NONFAILING(*(uint32_t*)0x10000160 = r[0]); NONFAILING(*(uint16_t*)0x10000164 = 0x2000); NONFAILING(*(uint16_t*)0x10000166 = 0); NONFAILING(*(uint32_t*)0x10000168 = r[2]); NONFAILING(*(uint16_t*)0x1000016c = 0x100); NONFAILING(*(uint16_t*)0x1000016e = 0); NONFAILING(*(uint32_t*)0x10000170 = r[3]); NONFAILING(*(uint16_t*)0x10000174 = 4); NONFAILING(*(uint16_t*)0x10000176 = 0); NONFAILING(*(uint32_t*)0x10000178 = r[4]); NONFAILING(*(uint16_t*)0x1000017c = 0x40); NONFAILING(*(uint16_t*)0x1000017e = 0); NONFAILING(*(uint32_t*)0x10000180 = r[5]); NONFAILING(*(uint16_t*)0x10000184 = 0x10); NONFAILING(*(uint16_t*)0x10000186 = 0); NONFAILING(*(uint32_t*)0x100001c0 = 5); NONFAILING(*(uint32_t*)0x100001c4 = 0x44); NONFAILING(*(uint64_t*)0x10000200 = 5); syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: NONFAILING(memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6)); NONFAILING(*(uint8_t*)0x10000006 = 0xaa); NONFAILING(*(uint8_t*)0x10000007 = 0xaa); NONFAILING(*(uint8_t*)0x10000008 = 0xaa); NONFAILING(*(uint8_t*)0x10000009 = 0xaa); NONFAILING(*(uint8_t*)0x1000000a = 0xaa); NONFAILING(*(uint8_t*)0x1000000b = 0xaa); 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, 2, 0, 2)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6)); NONFAILING(*(uint16_t*)0x10000010 = htobe16(0x45)); NONFAILING(*(uint16_t*)0x10000012 = htobe16(0x64)); NONFAILING(*(uint16_t*)0x10000014 = htobe16(6)); NONFAILING(*(uint8_t*)0x10000016 = 1); NONFAILING(*(uint8_t*)0x10000017 = 0x89); NONFAILING(*(uint16_t*)0x10000018 = htobe16(0)); NONFAILING(*(uint32_t*)0x1000001a = htobe32(3)); NONFAILING(*(uint32_t*)0x1000001e = htobe32(0xfff)); NONFAILING(*(uint8_t*)0x10000022 = 0x44); NONFAILING(*(uint8_t*)0x10000023 = 0xc); NONFAILING(*(uint8_t*)0x10000024 = 5); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4)); NONFAILING(*(uint32_t*)0x10000026 = htobe32(1)); NONFAILING(*(uint32_t*)0x1000002a = htobe32(0x400)); NONFAILING(*(uint8_t*)0x1000002e = 0x94); NONFAILING(*(uint8_t*)0x1000002f = 6); NONFAILING(*(uint32_t*)0x10000030 = htobe32(3)); NONFAILING(memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29)); struct csum_inet csum_1; csum_inet_init(&csum_1); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40)); NONFAILING(*(uint16_t*)0x10000018 = csum_inet_digest(&csum_1)); break; case 11: NONFAILING(memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54)); 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; } :406:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor729767840 -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 (1.31s) csource_test.go:123: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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; } :386:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor264489426 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/4 (1.73s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (; iter < 10; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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; } :374:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor242974985 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/8 (1.40s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:setuid Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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 wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, WUNTRACED) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_setuid(void) { int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); char pwbuf[1024]; struct passwd *pw, pwres; if (getpwnam_r("nobody", &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 || !pw) exit(1); if (setgroups(0, NULL)) exit(1); if (setgid(pw->pw_gid)) exit(1); if (setuid(pw->pw_uid)) exit(1); loop(); exit(1); } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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_setuid(); return 0; } :397:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor292223615 -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 (1.75s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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; } :376:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor213206051 -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.68s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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; } :376:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor171778342 -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/5 (1.91s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs: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: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: 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() { 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; } 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); 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; } :374:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor268950740 -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 (2.12s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:true NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: r0 = fcntl$dupfd(0xffffffffffffff9c, 0x11, 0xffffffffffffffff) fchflags(r0, 0x485) ioctl$DIOCSETTIMEOUT(r0, 0xc008441d, &(0x7f0000000000)={0x5, 0x7}) mmap(&(0x7f0000ffa000/0x3000)=nil, 0x3000, 0x5, 0x10, r0, 0x1ff) r1 = dup2(r0, r0) pipe2(&(0x7f0000000040)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0) r3 = open(&(0x7f0000000080)='./file0\x00', 0x10000, 0x10) r4 = socket$inet6_icmp(0x1c, 0x2, 0x3a) r5 = shm_open2(&(0x7f00000000c0)='./file0\x00', 0x2, 0x23, 0x0, &(0x7f0000000100)='\x00') ppoll(&(0x7f0000000140)=[{0xffffffffffffff9c, 0xb3c58574b84befac}, {r0, 0x24}, {r1}, {r0, 0x40}, {r0, 0x2000}, {r2, 0x100}, {r3, 0x4}, {r4, 0x40}, {r5, 0x10}], 0x9, &(0x7f00000001c0)={0x5, 0x44}, &(0x7f0000000200)={0x5}, 0x8) syz_emit_ethernet(0x53, &(0x7f0000000000)={@random="0e4fd282eb78", @local, [], {@ipv4={0x800, {{0xa, 0x4, 0x2, 0x9, 0x45, 0x64, 0x6, 0x1, 0x89, 0x0, @rand_addr=0x3, @rand_addr=0xfff, {[@timestamp={0x44, 0xc, 0x5, 0x0, 0x4, [{[], 0x1}, {[], 0x400}]}, @ra={0x94, 0x6, 0x3}]}}, @generic="9e0b257edc5674959008fc1f6420d3a6c445f0adb75953f40482034502"}}}}) syz_execute_func(&(0x7f0000000080)="c4c17de67f00660f38013626ad660f380216660f5a7e65c4c17c2f0505000000c4e219924c1c00660ff1ecc4e28da67629c4c2159816") syz_extract_tcp_res(&(0x7f00000000c0), 0x5, 0x9) csource_test.go:124: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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 int tunfd = -1; #define MAX_TUN 4 #define TUN_IFACE "tap%d" #define TUN_DEVICE "/dev/tap%d" #define LOCAL_MAC "aa:aa:aa:aa:aa:aa" #define REMOTE_MAC "aa:aa:aa:aa:aa:bb" #define LOCAL_IPV4 "172.20.%d.170" #define REMOTE_IPV4 "172.20.%d.187" #define LOCAL_IPV6 "fe80::%02hxaa" #define REMOTE_IPV6 "fe80::%02hxbb" static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; va_start(args, format); char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); int rv = system(command); if (rv) { if (panic) exit(1); } } static void initialize_tun(int tun_id) { if (tun_id < 0 || tun_id >= MAX_TUN) { exit(1); } char tun_device[sizeof(TUN_DEVICE)]; snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id); char tun_iface[sizeof(TUN_IFACE)]; snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id); execute_command(0, "ifconfig %s destroy", tun_device); tunfd = open(tun_device, O_RDWR | O_NONBLOCK); if ((tunfd < 0) && (errno == ENOENT)) { execute_command(0, "kldload -q if_tap"); tunfd = open(tun_device, O_RDWR | O_NONBLOCK); } if (tunfd == -1) { printf("tun: can't open %s: errno=%d\n", tun_device, errno); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; char local_mac[sizeof(LOCAL_MAC)]; snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC); execute_command(1, "ifconfig %s ether %s", tun_iface, local_mac); char local_ipv4[sizeof(LOCAL_IPV4)]; snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id); execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4); char remote_mac[sizeof(REMOTE_MAC)]; char remote_ipv4[sizeof(REMOTE_IPV4)]; snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC); snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, tun_id); execute_command(0, "arp -s %s %s", remote_ipv4, remote_mac); char local_ipv6[sizeof(LOCAL_IPV6)]; snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, tun_id); execute_command(1, "ifconfig %s inet6 %s", tun_iface, local_ipv6); char remote_ipv6[sizeof(REMOTE_IPV6)]; snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, tun_id); execute_command(0, "ndp -s %s%%%s %s", remote_ipv6, tun_iface, remote_mac); } static long syz_emit_ethernet(volatile long a0, volatile long a1) { if (tunfd < 0) return (uintptr_t)-1; size_t length = a0; const char* data = (char*)a1; return write(tunfd, data, length); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; exit(1); } return rv; } struct tcp_resources { uint32_t seq; uint32_t ack; }; static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile long a2) { if (tunfd < 0) return (uintptr_t)-1; char data[1000]; int rv = read_tun(&data[0], sizeof(data)); if (rv == -1) return (uintptr_t)-1; size_t length = rv; if (length < sizeof(struct ether_header)) return (uintptr_t)-1; struct ether_header* ethhdr = (struct ether_header*)&data[0]; struct tcphdr* tcphdr = 0; if (ethhdr->ether_type == htons(ETHERTYPE_IP)) { if (length < sizeof(struct ether_header) + sizeof(struct ip)) return (uintptr_t)-1; struct ip* iphdr = (struct ip*)&data[sizeof(struct ether_header)]; if (iphdr->ip_p != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + iphdr->ip_hl * 4 + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + iphdr->ip_hl * 4]; } else { if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr)) return (uintptr_t)-1; struct ip6_hdr* ipv6hdr = (struct ip6_hdr*)&data[sizeof(struct ether_header)]; if (ipv6hdr->ip6_nxt != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr) + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + sizeof(struct ip6_hdr)]; } struct tcp_resources* res = (struct tcp_resources*)a0; res->seq = htonl(ntohl(tcphdr->th_seq) + (uint32_t)a1); res->ack = htonl(ntohl(tcphdr->th_ack) + (uint32_t)a2); return 0; } static void sandbox_common() { 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(); initialize_tun(procid); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 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, 45); 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_fcntl, 0xffffff9c, 0x11, -1); if (res != -1) r[0] = res; break; case 1: syscall(SYS_fchflags, (intptr_t)r[0], 0x485); break; case 2: *(uint32_t*)0x10000000 = 5; *(uint32_t*)0x10000004 = 7; syscall(SYS_ioctl, (intptr_t)r[0], 0xc008441d, 0x10000000); break; case 3: syscall(SYS_mmap, 0x10ffa000, 0x3000, 5, 0x10, (intptr_t)r[0], 0x1ff); break; case 4: res = syscall(SYS_dup2, (intptr_t)r[0], (intptr_t)r[0]); if (res != -1) r[1] = res; break; case 5: res = syscall(SYS_pipe2, 0x10000040, 0); if (res != -1) r[2] = *(uint32_t*)0x10000044; break; case 6: memcpy((void*)0x10000080, "./file0\000", 8); res = syscall(SYS_open, 0x10000080, 0x10000, 0x10); if (res != -1) r[3] = res; break; case 7: res = syscall(SYS_socket, 0x1c, 2, 0x3a); if (res != -1) r[4] = res; break; case 8: memcpy((void*)0x100000c0, "./file0\000", 8); memcpy((void*)0x10000100, "\000", 1); res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); if (res != -1) r[5] = res; break; case 9: *(uint32_t*)0x10000140 = 0xffffff9c; *(uint16_t*)0x10000144 = 0xefac; *(uint16_t*)0x10000146 = 0; *(uint32_t*)0x10000148 = r[0]; *(uint16_t*)0x1000014c = 0x24; *(uint16_t*)0x1000014e = 0; *(uint32_t*)0x10000150 = r[1]; *(uint16_t*)0x10000154 = 0; *(uint16_t*)0x10000156 = 0; *(uint32_t*)0x10000158 = r[0]; *(uint16_t*)0x1000015c = 0x40; *(uint16_t*)0x1000015e = 0; *(uint32_t*)0x10000160 = r[0]; *(uint16_t*)0x10000164 = 0x2000; *(uint16_t*)0x10000166 = 0; *(uint32_t*)0x10000168 = r[2]; *(uint16_t*)0x1000016c = 0x100; *(uint16_t*)0x1000016e = 0; *(uint32_t*)0x10000170 = r[3]; *(uint16_t*)0x10000174 = 4; *(uint16_t*)0x10000176 = 0; *(uint32_t*)0x10000178 = r[4]; *(uint16_t*)0x1000017c = 0x40; *(uint16_t*)0x1000017e = 0; *(uint32_t*)0x10000180 = r[5]; *(uint16_t*)0x10000184 = 0x10; *(uint16_t*)0x10000186 = 0; *(uint32_t*)0x100001c0 = 5; *(uint32_t*)0x100001c4 = 0x44; *(uint64_t*)0x10000200 = 5; syscall(SYS_ppoll, 0x10000140, 9, 0x100001c0, 0x10000200, 8); break; case 10: memcpy((void*)0x10000000, "\x0e\x4f\xd2\x82\xeb\x78", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xaa; *(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, 2, 0, 2); STORE_BY_BITMASK(uint8_t, , 0x1000000f, 9, 2, 6); *(uint16_t*)0x10000010 = htobe16(0x45); *(uint16_t*)0x10000012 = htobe16(0x64); *(uint16_t*)0x10000014 = htobe16(6); *(uint8_t*)0x10000016 = 1; *(uint8_t*)0x10000017 = 0x89; *(uint16_t*)0x10000018 = htobe16(0); *(uint32_t*)0x1000001a = htobe32(3); *(uint32_t*)0x1000001e = htobe32(0xfff); *(uint8_t*)0x10000022 = 0x44; *(uint8_t*)0x10000023 = 0xc; *(uint8_t*)0x10000024 = 5; STORE_BY_BITMASK(uint8_t, , 0x10000025, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000025, 4, 4, 4); *(uint32_t*)0x10000026 = htobe32(1); *(uint32_t*)0x1000002a = htobe32(0x400); *(uint8_t*)0x1000002e = 0x94; *(uint8_t*)0x1000002f = 6; *(uint32_t*)0x10000030 = htobe32(3); memcpy((void*)0x10000036, "\x9e\x0b\x25\x7e\xdc\x56\x74\x95\x90\x08\xfc\x1f\x64\x20\xd3\xa6\xc4\x45\xf0\xad\xb7\x59\x53\xf4\x04\x82\x03\x45\x02", 29); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000000e, 40); *(uint16_t*)0x10000018 = csum_inet_digest(&csum_1); syz_emit_ethernet(0x53, 0x10000000); break; case 11: memcpy((void*)0x10000080, "\xc4\xc1\x7d\xe6\x7f\x00\x66\x0f\x38\x01\x36\x26\xad\x66\x0f\x38\x02\x16\x66\x0f\x5a\x7e\x65\xc4\xc1\x7c\x2f\x05\x05\x00\x00\x00\xc4\xe2\x19\x92\x4c\x1c\x00\x66\x0f\xf1\xec\xc4\xe2\x8d\xa6\x76\x29\xc4\xc2\x15\x98\x16", 54); syz_execute_func(0x10000080); break; case 12: syz_extract_tcp_res(0x100000c0, 5, 9); break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :546:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x100000c0, 2, 0x23, 0, 0x10000100); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor500825165 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/2 (0.92s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/10 (1.01s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/3 (0.93s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/13 (1.13s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/1 (0.98s) csource_test.go:121: FAIL FAIL github.com/google/syzkaller/pkg/csource 14.538s ok github.com/google/syzkaller/pkg/db (cached) ok github.com/google/syzkaller/pkg/email (cached) ? github.com/google/syzkaller/pkg/gce [no test files] ? github.com/google/syzkaller/pkg/gcs [no test files] ? github.com/google/syzkaller/pkg/hash [no test files] ok github.com/google/syzkaller/pkg/host 1.535s ? github.com/google/syzkaller/pkg/html [no test files] ok github.com/google/syzkaller/pkg/ifuzz (cached) ? github.com/google/syzkaller/pkg/ifuzz/iset [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc/generated [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86 [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/generated [no test files] ok github.com/google/syzkaller/pkg/instance 1.908s ok github.com/google/syzkaller/pkg/ipc 5.519s ? 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 (cached) ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig 0.087s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 3.780s ok github.com/google/syzkaller/pkg/repro 0.247s ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 58.379s 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.597s ok github.com/google/syzkaller/pkg/vcs 11.512s ok github.com/google/syzkaller/prog (cached) ok github.com/google/syzkaller/prog/test (cached) ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux (cached) ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ok github.com/google/syzkaller/sys/openbsd (cached) ? github.com/google/syzkaller/sys/openbsd/gen [no test files] ? github.com/google/syzkaller/sys/syz-extract [no test files] ? github.com/google/syzkaller/sys/syz-sysgen [no test files] ? github.com/google/syzkaller/sys/targets [no test files] ? github.com/google/syzkaller/sys/test [no test files] ? github.com/google/syzkaller/sys/test/gen [no test files] ? github.com/google/syzkaller/sys/trusty [no test files] ? github.com/google/syzkaller/sys/trusty/gen [no test files] ? github.com/google/syzkaller/sys/windows [no test files] ? github.com/google/syzkaller/sys/windows/gen [no test files] ok github.com/google/syzkaller/syz-ci 0.283s ok github.com/google/syzkaller/syz-fuzzer (cached) ok github.com/google/syzkaller/syz-hub (cached) ok github.com/google/syzkaller/syz-hub/state (cached) ok github.com/google/syzkaller/syz-manager 0.144s ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ? github.com/google/syzkaller/tools/syz-kconf [no test files] ok github.com/google/syzkaller/tools/syz-linter 4.068s ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser (cached) ok github.com/google/syzkaller/tools/syz-trace2syz/proggen (cached) ? github.com/google/syzkaller/tools/syz-tty [no test files] ? github.com/google/syzkaller/tools/syz-upgrade [no test files] ? github.com/google/syzkaller/tools/syz-usbgen [no test files] ok github.com/google/syzkaller/vm 9.151s ? 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.086s ? 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.149s ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL