ok github.com/google/syzkaller/dashboard/app 0.169s ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 1.045s ok github.com/google/syzkaller/pkg/ast 1.880s ok github.com/google/syzkaller/pkg/bisect 55.315s ok github.com/google/syzkaller/pkg/build 1.833s ? github.com/google/syzkaller/pkg/cmdprof [no test files] ok github.com/google/syzkaller/pkg/compiler 11.287s ok github.com/google/syzkaller/pkg/config (cached) ? github.com/google/syzkaller/pkg/cover [no test files] --- FAIL: TestGenerate (7.56s) --- FAIL: TestGenerate/freebsd/386 (0.76s) csource_test.go:67: seed=1603704406815308003 --- FAIL: TestGenerate/freebsd/386/0 (0.63s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); syz_execute_func(0x10000080); } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :280:16: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor219623260 -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.09s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :435:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor279356683 -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.21s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :406:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor770907886 -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.20s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23 + procid*4); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21 + procid*4); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :437:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor673027664 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/3 (1.19s) csource_test.go:123: opts: {Threaded:true Collide:false Repeat:false 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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 loop(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :355:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor387676674 -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.25s) 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 UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :437:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor177258869 -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.26s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :435:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor376841081 -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.27s) 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 UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23 + procid*4); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21 + procid*4); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :447:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor555640175 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/13 (1.42s) 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 UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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) { fprintf(stderr, "### start\n"); int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; res = syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; res = syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[6] = res; break; case 8: res = syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); break; case 9: *(uint32_t*)0x10000540 = 0x10; res = syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); (void)res; break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); res = -1; errno = EFAULT; res = syz_execute_func(0x10000080); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: (void)res; break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :443:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor232665107 -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 (1.42s) csource_test.go:123: opts: {Threaded:true Collide:true 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 UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: getsockopt$inet6_sctp_SCTP_AUTH_ACTIVE_KEY(0xffffffffffffff9c, 0x84, 0x15, &(0x7f0000000000)={0x0, 0x9}, &(0x7f0000000040)=0x8) getsockopt$inet_sctp_SCTP_LOCAL_AUTH_CHUNKS(0xffffffffffffff9c, 0x84, 0x103, &(0x7f0000000080)={r0, 0x3b, "53b8e962562cf71daf963416d507faa3e1c08e0ab2d8a54d139995ecbc5f44a45f045dc55f69fc461c285b00a9ea47cf0dc519d70f73ba107df18f"}, &(0x7f0000000100)=0x43) getsockopt$inet6_sctp_SCTP_ENABLE_STREAM_RESET(0xffffffffffffffff, 0x84, 0x900, &(0x7f0000000140)={r1}, &(0x7f0000000180)=0x8) freebsd10_pipe(&(0x7f00000001c0)={0xffffffffffffffff, 0xffffffffffffffff}) getsockopt$inet_sctp_SCTP_PEER_ADDR_THLDS(0xffffffffffffff9c, 0x84, 0x23, &(0x7f0000000200)={@in6={{0x1c, 0x1c, 0x3, 0x49cc, @empty, 0x20000000}}, r0, 0x0, 0x6}, &(0x7f00000002c0)=0x88) getsockopt$inet_sctp_SCTP_CONTEXT(0xffffffffffffff9c, 0x84, 0x1a, &(0x7f0000000300)={r1, 0x401}, 0xffffffffffffffff) getsockopt$inet6_sctp_SCTP_STATUS(r3, 0x84, 0x100, &(0x7f0000000340)={r4, 0x8, 0x2, 0x3, 0x9, 0x3, 0x2, 0x9, {@in={{0x10, 0x2, 0x1, @rand_addr=0x4}}, r5, 0x9, 0x9, 0x8, 0x200, 0x3ff}}, &(0x7f0000000400)=0xb8) r6 = shm_open2(&(0x7f0000000440)='./file0\x00', 0x800, 0x124, 0x3, &(0x7f0000000480)='\x00') dup2(r6, r2) getsockname(0xffffffffffffffff, &(0x7f0000000500)=@in={0x10, 0x2, 0xffffffffffffffff, @rand_addr}, &(0x7f0000000540)=0x10) syz_emit_ethernet(0x6f, &(0x7f0000000000)={@random="acddb77d34e5", @remote, [{[{0x88a8, 0x1, 0x0, 0x4}], {0x8100, 0x2, 0x1}}], {@generic={0xe02a, "6d0786b7bed42761ca732258d8acc6564175925480dbf6bff00dfdcc740a84769c4755cf82a2061a6ce1349dfeccdd14208d6d32222933ddc5d111aeb5f1c5f333255dc7f742a35577ae84bdf554acc4c5e3f2c1d9b344c7d2"}}}) syz_execute_func(&(0x7f0000000080)="660fe23c7e99c4c1145ffc0fbbdfc4e1fd7fa086f56055f30f0128360f2af8c4e37d042105c4c1edf672bfc4c2e13f4f0d") syz_extract_tcp_res(&(0x7f00000000c0), 0x10000, 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)))) 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; 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[7] = {0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x10000000 = 0; *(uint16_t*)0x10000004 = 9; *(uint32_t*)0x10000040 = 8; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x15, 0x10000000, 0x10000040); if (res != -1) r[0] = *(uint32_t*)0x10000000; break; case 1: *(uint32_t*)0x10000080 = r[0]; *(uint32_t*)0x10000084 = 0x3b; memcpy((void*)0x10000088, "\x53\xb8\xe9\x62\x56\x2c\xf7\x1d\xaf\x96\x34\x16\xd5\x07\xfa\xa3\xe1\xc0\x8e\x0a\xb2\xd8\xa5\x4d\x13\x99\x95\xec\xbc\x5f\x44\xa4\x5f\x04\x5d\xc5\x5f\x69\xfc\x46\x1c\x28\x5b\x00\xa9\xea\x47\xcf\x0d\xc5\x19\xd7\x0f\x73\xba\x10\x7d\xf1\x8f", 59); *(uint32_t*)0x10000100 = 0x43; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x103, 0x10000080, 0x10000100); if (res != -1) r[1] = *(uint32_t*)0x10000080; break; case 2: *(uint32_t*)0x10000140 = r[1]; *(uint32_t*)0x10000144 = 0; *(uint32_t*)0x10000180 = 8; syscall(SYS_getsockopt, -1, 0x84, 0x900, 0x10000140, 0x10000180); break; case 3: res = syscall(SYS_freebsd10_pipe, 0x100001c0); if (res != -1) { r[2] = *(uint32_t*)0x100001c0; r[3] = *(uint32_t*)0x100001c4; } break; case 4: *(uint8_t*)0x10000200 = 0x1c; *(uint8_t*)0x10000201 = 0x1c; *(uint16_t*)0x10000202 = htobe16(0x4e23); *(uint32_t*)0x10000204 = 0x49cc; *(uint8_t*)0x10000208 = 0; *(uint8_t*)0x10000209 = 0; *(uint8_t*)0x1000020a = 0; *(uint8_t*)0x1000020b = 0; *(uint8_t*)0x1000020c = 0; *(uint8_t*)0x1000020d = 0; *(uint8_t*)0x1000020e = 0; *(uint8_t*)0x1000020f = 0; *(uint8_t*)0x10000210 = 0; *(uint8_t*)0x10000211 = 0; *(uint8_t*)0x10000212 = 0; *(uint8_t*)0x10000213 = 0; *(uint8_t*)0x10000214 = 0; *(uint8_t*)0x10000215 = 0; *(uint8_t*)0x10000216 = 0; *(uint8_t*)0x10000217 = 0; *(uint32_t*)0x10000218 = 0x20000000; *(uint64_t*)0x1000021c = 0; *(uint64_t*)0x10000224 = 0; *(uint64_t*)0x1000022c = 0; *(uint64_t*)0x10000234 = 0; *(uint64_t*)0x1000023c = 0; *(uint64_t*)0x10000244 = 0; *(uint64_t*)0x1000024c = 0; *(uint64_t*)0x10000254 = 0; *(uint64_t*)0x1000025c = 0; *(uint64_t*)0x10000264 = 0; *(uint64_t*)0x1000026c = 0; *(uint64_t*)0x10000274 = 0; *(uint32_t*)0x1000027c = r[0]; *(uint16_t*)0x10000280 = 0; *(uint16_t*)0x10000282 = 6; *(uint16_t*)0x10000284 = 0; *(uint32_t*)0x100002c0 = 0x88; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x23, 0x10000200, 0x100002c0); if (res != -1) r[4] = *(uint32_t*)0x1000027c; break; case 5: *(uint32_t*)0x10000300 = r[1]; *(uint32_t*)0x10000304 = 0x401; res = syscall(SYS_getsockopt, 0xffffff9c, 0x84, 0x1a, 0x10000300, -1); if (res != -1) r[5] = *(uint32_t*)0x10000300; break; case 6: *(uint32_t*)0x10000340 = r[4]; *(uint32_t*)0x10000344 = 8; *(uint32_t*)0x10000348 = 2; *(uint16_t*)0x1000034c = 3; *(uint16_t*)0x1000034e = 9; *(uint16_t*)0x10000350 = 3; *(uint16_t*)0x10000352 = 2; *(uint32_t*)0x10000354 = 9; *(uint8_t*)0x10000358 = 0x10; *(uint8_t*)0x10000359 = 2; *(uint16_t*)0x1000035a = htobe16(0x4e21); *(uint32_t*)0x1000035c = htobe32(4); *(uint8_t*)0x10000360 = 0; *(uint8_t*)0x10000361 = 0; *(uint8_t*)0x10000362 = 0; *(uint8_t*)0x10000363 = 0; *(uint8_t*)0x10000364 = 0; *(uint8_t*)0x10000365 = 0; *(uint8_t*)0x10000366 = 0; *(uint8_t*)0x10000367 = 0; *(uint64_t*)0x10000368 = 0; *(uint64_t*)0x10000370 = 0; *(uint64_t*)0x10000378 = 0; *(uint64_t*)0x10000380 = 0; *(uint64_t*)0x10000388 = 0; *(uint64_t*)0x10000390 = 0; *(uint64_t*)0x10000398 = 0; *(uint64_t*)0x100003a0 = 0; *(uint64_t*)0x100003a8 = 0; *(uint64_t*)0x100003b0 = 0; *(uint64_t*)0x100003b8 = 0; *(uint64_t*)0x100003c0 = 0; *(uint64_t*)0x100003c8 = 0; *(uint64_t*)0x100003d0 = 0; *(uint64_t*)0x100003d8 = 0; *(uint32_t*)0x100003e0 = r[5]; *(uint32_t*)0x100003e4 = 9; *(uint32_t*)0x100003e8 = 9; *(uint32_t*)0x100003ec = 8; *(uint32_t*)0x100003f0 = 0x200; *(uint32_t*)0x100003f4 = 0x3ff; *(uint32_t*)0x10000400 = 0xb8; syscall(SYS_getsockopt, (intptr_t)r[3], 0x84, 0x100, 0x10000340, 0x10000400); break; case 7: memcpy((void*)0x10000440, "./file0\000", 8); memcpy((void*)0x10000480, "\000", 1); res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); if (res != -1) r[6] = res; break; case 8: syscall(SYS_dup2, (intptr_t)r[6], (intptr_t)r[2]); break; case 9: *(uint32_t*)0x10000540 = 0x10; syscall(SYS_getsockname, -1, 0x10000500, 0x10000540); break; case 10: memcpy((void*)0x10000000, "\xac\xdd\xb7\x7d\x34\xe5", 6); *(uint8_t*)0x10000006 = 0xaa; *(uint8_t*)0x10000007 = 0xaa; *(uint8_t*)0x10000008 = 0xaa; *(uint8_t*)0x10000009 = 0xaa; *(uint8_t*)0x1000000a = 0xaa; *(uint8_t*)0x1000000b = 0xbb; *(uint16_t*)0x1000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 4, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x10000012, 2, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x10000012, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x10000012, 0, 4, 12); *(uint16_t*)0x10000014 = htobe16(0xe02a); memcpy((void*)0x10000016, "\x6d\x07\x86\xb7\xbe\xd4\x27\x61\xca\x73\x22\x58\xd8\xac\xc6\x56\x41\x75\x92\x54\x80\xdb\xf6\xbf\xf0\x0d\xfd\xcc\x74\x0a\x84\x76\x9c\x47\x55\xcf\x82\xa2\x06\x1a\x6c\xe1\x34\x9d\xfe\xcc\xdd\x14\x20\x8d\x6d\x32\x22\x29\x33\xdd\xc5\xd1\x11\xae\xb5\xf1\xc5\xf3\x33\x25\x5d\xc7\xf7\x42\xa3\x55\x77\xae\x84\xbd\xf5\x54\xac\xc4\xc5\xe3\xf2\xc1\xd9\xb3\x44\xc7\xd2", 89); break; case 11: memcpy((void*)0x10000080, "\x66\x0f\xe2\x3c\x7e\x99\xc4\xc1\x14\x5f\xfc\x0f\xbb\xdf\xc4\xe1\xfd\x7f\xa0\x86\xf5\x60\x55\xf3\x0f\x01\x28\x36\x0f\x2a\xf8\xc4\xe3\x7d\x04\x21\x05\xc4\xc1\xed\xf6\x72\xbf\xc4\xc2\xe1\x3f\x4f\x0d", 49); 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; } :443:17: error: use of undeclared identifier 'SYS_shm_open2' res = syscall(SYS_shm_open2, 0x10000440, 0x800, 0x124, 3, 0x10000480); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor289545348 -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.23s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/10 (1.43s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/1 (1.15s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/9 (0.86s) csource_test.go:121: --- FAIL: TestGenerate/freebsd/386/8 (1.00s) csource_test.go:121: FAIL FAIL github.com/google/syzkaller/pkg/csource 15.167s ok github.com/google/syzkaller/pkg/db 3.720s 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.808s ? github.com/google/syzkaller/pkg/html [no test files] ok github.com/google/syzkaller/pkg/ifuzz (cached) ? github.com/google/syzkaller/pkg/ifuzz/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/generated [no test files] ok github.com/google/syzkaller/pkg/instance 3.672s ok github.com/google/syzkaller/pkg/ipc 7.635s ? 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.093s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 7.876s ok github.com/google/syzkaller/pkg/repro 1.733s ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 63.824s 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.421s ok github.com/google/syzkaller/pkg/vcs 10.555s ok github.com/google/syzkaller/prog 14.980s ok github.com/google/syzkaller/prog/test 0.973s ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux 0.219s ? 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 0.095s ? 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 1.461s ok github.com/google/syzkaller/syz-fuzzer 0.816s ok github.com/google/syzkaller/syz-hub 0.163s ok github.com/google/syzkaller/syz-hub/state 0.062s ? github.com/google/syzkaller/syz-manager [no test files] ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ? github.com/google/syzkaller/tools/syz-kconf [no test files] ok github.com/google/syzkaller/tools/syz-linter (cached) ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser 0.068s ok github.com/google/syzkaller/tools/syz-trace2syz/proggen 0.724s ? 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.955s ? github.com/google/syzkaller/vm/adb [no test files] ? github.com/google/syzkaller/vm/bhyve [no test files] ? github.com/google/syzkaller/vm/gce [no test files] ? github.com/google/syzkaller/vm/gvisor [no test files] ok github.com/google/syzkaller/vm/isolated (cached) ? github.com/google/syzkaller/vm/kvm [no test files] ? github.com/google/syzkaller/vm/odroid [no test files] ? github.com/google/syzkaller/vm/qemu [no test files] ok github.com/google/syzkaller/vm/vmimpl (cached) ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL