ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 0.956s ok github.com/google/syzkaller/pkg/ast 2.491s ok github.com/google/syzkaller/pkg/bisect 56.704s ok github.com/google/syzkaller/pkg/build 0.182s ok github.com/google/syzkaller/pkg/compiler 9.555s ok github.com/google/syzkaller/pkg/config (cached) ok github.com/google/syzkaller/pkg/cover (cached) ? github.com/google/syzkaller/pkg/cover/backend [no test files] --- FAIL: TestGenerate (5.37s) --- FAIL: TestGenerate/freebsd/386 (0.79s) csource_test.go:52: seed=1613746188035203034 --- FAIL: TestGenerate/freebsd/386/12 (0.33s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:true Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (sig == SIGBUS) { valid = 1; } if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) ({ int ok = 1; __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } else ok = 0; __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); ok; }) static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: NONFAILING(*(uint32_t*)0x100000c0 = 0); syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: NONFAILING(memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32)); NONFAILING(*(uint32_t*)0x10000120 = 4); syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: NONFAILING(*(uint8_t*)0x10000140 = 0xa); NONFAILING(*(uint8_t*)0x10000141 = 0); NONFAILING(memcpy((void*)0x10000142, "./file0\000", 8)); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: NONFAILING(*(uint32_t*)0x10000180 = 0x74ce); syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: NONFAILING(memcpy((void*)0x100001c0, "./file0/file0\000", 14)); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: NONFAILING(*(uint64_t*)0x10000200 = 0x5e43b474); NONFAILING(*(uint64_t*)0x10000240 = 9); syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: NONFAILING(*(uint32_t*)0x100002c0 = 4); syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: NONFAILING(*(uint8_t*)0x10000000 = 0xaa); NONFAILING(*(uint8_t*)0x10000001 = 0xaa); NONFAILING(*(uint8_t*)0x10000002 = 0xaa); NONFAILING(*(uint8_t*)0x10000003 = 0xaa); NONFAILING(*(uint8_t*)0x10000004 = 0xaa); NONFAILING(*(uint8_t*)0x10000005 = 0xbb); NONFAILING(*(uint8_t*)0x10000006 = 0xaa); NONFAILING(*(uint8_t*)0x10000007 = 0xaa); NONFAILING(*(uint8_t*)0x10000008 = 0xaa); NONFAILING(*(uint8_t*)0x10000009 = 0xaa); NONFAILING(*(uint8_t*)0x1000000a = 0xaa); NONFAILING(*(uint8_t*)0x1000000b = 0xbb); NONFAILING(*(uint16_t*)0x1000000c = htobe16(0x8100)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12)); NONFAILING(*(uint16_t*)0x10000010 = htobe16(0x86dd)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4)); NONFAILING(memcpy((void*)0x10000013, "\x62\x2b\xff", 3)); NONFAILING(*(uint16_t*)0x10000016 = htobe16(0xaf)); NONFAILING(*(uint8_t*)0x10000018 = 0x17); NONFAILING(*(uint8_t*)0x10000019 = 0); NONFAILING(memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16)); NONFAILING(*(uint8_t*)0x1000002a = -1); NONFAILING(*(uint8_t*)0x1000002b = 2); NONFAILING(*(uint8_t*)0x1000002c = 0); NONFAILING(*(uint8_t*)0x1000002d = 0); NONFAILING(*(uint8_t*)0x1000002e = 0); NONFAILING(*(uint8_t*)0x1000002f = 0); NONFAILING(*(uint8_t*)0x10000030 = 0); NONFAILING(*(uint8_t*)0x10000031 = 0); NONFAILING(*(uint8_t*)0x10000032 = 0); NONFAILING(*(uint8_t*)0x10000033 = 0); NONFAILING(*(uint8_t*)0x10000034 = 0); NONFAILING(*(uint8_t*)0x10000035 = 0); NONFAILING(*(uint8_t*)0x10000036 = 0); NONFAILING(*(uint8_t*)0x10000037 = 0); NONFAILING(*(uint8_t*)0x10000038 = 0); NONFAILING(*(uint8_t*)0x10000039 = 1); NONFAILING(*(uint8_t*)0x1000003a = 0x35); NONFAILING(*(uint8_t*)0x1000003b = 4); NONFAILING(*(uint8_t*)0x1000003c = 0); NONFAILING(*(uint8_t*)0x1000003d = 0); NONFAILING(*(uint8_t*)0x1000003e = 0); NONFAILING(*(uint8_t*)0x1000003f = 0); NONFAILING(*(uint8_t*)0x10000040 = 0); NONFAILING(*(uint8_t*)0x10000041 = 0); NONFAILING(*(uint8_t*)0x10000042 = 0xc2); NONFAILING(*(uint8_t*)0x10000043 = 4); NONFAILING(*(uint32_t*)0x10000044 = htobe32(0x26e16850)); NONFAILING(*(uint8_t*)0x10000048 = 4); NONFAILING(*(uint8_t*)0x10000049 = 1); NONFAILING(*(uint8_t*)0x1000004a = 7); NONFAILING(*(uint8_t*)0x1000004b = 1); NONFAILING(*(uint8_t*)0x1000004c = 0xa); NONFAILING(*(uint8_t*)0x1000004d = 0); NONFAILING(*(uint8_t*)0x1000004e = 0); NONFAILING(*(uint8_t*)0x1000004f = 0); NONFAILING(*(uint8_t*)0x10000050 = 0); NONFAILING(*(uint8_t*)0x10000051 = 0); NONFAILING(*(uint8_t*)0x10000052 = 0); NONFAILING(*(uint8_t*)0x10000053 = 0); NONFAILING(*(uint8_t*)0x10000054 = 0); NONFAILING(*(uint8_t*)0x10000055 = 0); NONFAILING(*(uint8_t*)0x10000056 = 0); NONFAILING(*(uint8_t*)0x10000057 = 0xc2); NONFAILING(*(uint8_t*)0x10000058 = 4); NONFAILING(*(uint32_t*)0x10000059 = htobe32(5)); NONFAILING(*(uint8_t*)0x1000005d = 1); NONFAILING(*(uint8_t*)0x1000005e = 8); NONFAILING(*(uint8_t*)0x1000005f = 0); NONFAILING(*(uint8_t*)0x10000060 = 0); NONFAILING(*(uint8_t*)0x10000061 = 0); NONFAILING(*(uint8_t*)0x10000062 = 0); NONFAILING(*(uint8_t*)0x10000063 = 0); NONFAILING(*(uint8_t*)0x10000064 = 0); NONFAILING(*(uint8_t*)0x10000065 = 0); NONFAILING(*(uint8_t*)0x10000066 = 0); NONFAILING(*(uint8_t*)0x1000006a = 0xb8); NONFAILING(*(uint8_t*)0x1000006b = 4); NONFAILING(*(uint8_t*)0x1000006c = 0); NONFAILING(*(uint8_t*)0x1000006d = 0); NONFAILING(*(uint8_t*)0x1000006e = 0); NONFAILING(*(uint8_t*)0x1000006f = 0); NONFAILING(*(uint8_t*)0x10000070 = 0); NONFAILING(*(uint8_t*)0x10000071 = 0); NONFAILING(*(uint8_t*)0x10000072 = 1); NONFAILING(*(uint8_t*)0x10000073 = 9); NONFAILING(*(uint8_t*)0x10000074 = 0); NONFAILING(*(uint8_t*)0x10000075 = 0); NONFAILING(*(uint8_t*)0x10000076 = 0); NONFAILING(*(uint8_t*)0x10000077 = 0); NONFAILING(*(uint8_t*)0x10000078 = 0); NONFAILING(*(uint8_t*)0x10000079 = 0); NONFAILING(*(uint8_t*)0x1000007a = 0); NONFAILING(*(uint8_t*)0x1000007b = 0); NONFAILING(*(uint8_t*)0x1000007c = 0); NONFAILING(*(uint8_t*)0x1000007d = 0); NONFAILING(*(uint8_t*)0x1000007e = 1); NONFAILING(*(uint8_t*)0x1000007f = 0); NONFAILING(*(uint8_t*)0x10000080 = 1); NONFAILING(*(uint8_t*)0x10000081 = 4); NONFAILING(*(uint8_t*)0x10000082 = 0); NONFAILING(*(uint8_t*)0x10000083 = 0); NONFAILING(*(uint8_t*)0x10000084 = 0); NONFAILING(*(uint8_t*)0x10000085 = 0); NONFAILING(*(uint8_t*)0x10000086 = 0); NONFAILING(*(uint8_t*)0x10000087 = 1); NONFAILING(*(uint8_t*)0x10000088 = 0); NONFAILING(*(uint8_t*)0x10000089 = 0xc2); NONFAILING(*(uint8_t*)0x1000008a = 4); NONFAILING(*(uint32_t*)0x1000008b = htobe32(3)); NONFAILING(*(uint8_t*)0x1000008f = 5); NONFAILING(*(uint8_t*)0x10000090 = 2); NONFAILING(*(uint16_t*)0x10000091 = htobe16(3)); NONFAILING(*(uint8_t*)0x1000009a = 0x70); NONFAILING(*(uint8_t*)0x1000009b = 0); NONFAILING(*(uint8_t*)0x1000009c = 0x80); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5)); NONFAILING(*(uint32_t*)0x1000009e = 0x64); NONFAILING(*(uint16_t*)0x100000a2 = htobe16(0x4e20)); NONFAILING(*(uint16_t*)0x100000a4 = htobe16(0x4e20)); NONFAILING(*(uint32_t*)0x100000a6 = 0x41424344); NONFAILING(*(uint32_t*)0x100000aa = 0x41424344); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4)); NONFAILING(*(uint8_t*)0x100000af = 0); NONFAILING(*(uint16_t*)0x100000b0 = htobe16(0x401)); NONFAILING(*(uint16_t*)0x100000b2 = htobe16(0)); NONFAILING(*(uint16_t*)0x100000b4 = htobe16(0xb0)); NONFAILING(*(uint8_t*)0x100000b6 = 1); NONFAILING(*(uint8_t*)0x100000b7 = 0); NONFAILING(*(uint8_t*)0x100000b8 = 0xe); NONFAILING(memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12)); NONFAILING(*(uint8_t*)0x100000c5 = 4); NONFAILING(*(uint8_t*)0x100000c6 = 2); NONFAILING(*(uint8_t*)0x100000c7 = 1); NONFAILING(*(uint8_t*)0x100000c8 = 0x13); NONFAILING(*(uint8_t*)0x100000c9 = 0x12); NONFAILING(memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16)); NONFAILING(*(uint8_t*)0x100000da = 0); NONFAILING(memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11)); struct csum_inet csum_1; csum_inet_init(&csum_1); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16)); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16)); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); NONFAILING(csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71)); NONFAILING(*(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1)); break; case 11: NONFAILING(memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61)); NONFAILING(syz_execute_func(0x10000100)); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; } :401:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor048915143 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/0 (0.36s) csource_test.go:108: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { if (setsid() == -1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; syscall(SYS___semctl, -1, 4, 4, 0x10000000); res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :216:10: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor103664392 -DGOOS_freebsd=1 -DGOARCH_386=1 -DHOSTGOOS_freebsd=1 -x c - -m32 -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -static -lc++ -Wno-overflow] --- FAIL: TestGenerate/freebsd/386/9 (0.45s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:setuid Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, WUNTRACED) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_setuid(void) { int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); char pwbuf[1024]; struct passwd *pw, pwres; if (getpwnam_r("nobody", &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 || !pw) exit(1); if (setgroups(0, NULL)) exit(1); if (setgid(pw->pw_gid)) exit(1); if (setuid(pw->pw_uid)) exit(1); loop(); exit(1); } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_setuid(); return 0; } :392:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor171309946 -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 (0.91s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:false RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :288:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor067554449 -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.11s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (; iter < 10; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :369:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor378849980 -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.05s) csource_test.go:108: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :377:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor176519088 -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.15s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:10 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 500); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 15000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); break; case 12: break; } } int main(void) { syscall(SYS_mmap, 0x10000000, 0x1000000, 7, 0x1012, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; } :369:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor957629262 -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.03s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { fprintf(stderr, "### start\n"); int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS___semctl, -1, 4, 4, 0x10000000); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: res = syscall(SYS_socket, 2, 2, 1); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; res = syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; res = syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); res = syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; res = syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; res = syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; res = syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20); *(uint16_t*)0x100000a4 = htobe16(0x4e20); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); (void)res; break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); res = -1; errno = EFAULT; res = syz_execute_func(0x10000100); 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; } :377:17: error: use of undeclared identifier 'SYS_copy_file_range' res = syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor353702997 -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.16s) csource_test.go:108: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20 + procid*4); *(uint16_t*)0x100000a4 = htobe16(0x4e20 + procid*4); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); 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; } :371:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor372629739 -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.08s) csource_test.go:106: --- FAIL: TestGenerate/freebsd/386/15 (1.08s) csource_test.go:108: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Slowdown:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: __semctl$GETPID(0xffffffffffffffff, 0x4, 0x4, &(0x7f0000000000)=""/119) r0 = socket$inet_icmp(0x2, 0x2, 0x1) getsockopt$inet_tcp_buf(r0, 0x6, 0x401, &(0x7f0000000080), &(0x7f00000000c0)) setsockopt$inet_tcp_TCP_FUNCTION_BLK(0xffffffffffffffff, 0x6, 0x2000, &(0x7f0000000100)={'rack\x00', 0x4}, 0x24) bindat(0xffffffffffffff9c, r0, &(0x7f0000000140)=@un=@file={0xa, 0x0, './file0\x00'}, 0xa) cap_ioctls_limit(0xffffffffffffff9c, &(0x7f0000000180)=[0x74ce]) r1 = openat(0xffffffffffffff9c, &(0x7f00000001c0)='./file0/file0\x00', 0x10000, 0x2) copy_file_range(r1, &(0x7f0000000200)=0x5e43b474, 0xffffffffffffff9c, &(0x7f0000000240)=0x9, 0x9, 0x0) r2 = socket$inet6(0x1c, 0x3, 0x93) getsockopt$inet6_sctp_SCTP_RECVRCVINFO(r2, 0x84, 0x1f, &(0x7f0000000280), &(0x7f00000002c0)=0x4) syz_emit_ethernet(0xe9, &(0x7f0000000000)={@remote, @remote, [{[], {0x8100, 0x3, 0x1, 0x3}}], {@ipv6={0x86dd, {0xa, 0x6, "622bff", 0xaf, 0x17, 0x0, @rand_addr="8cb1110077c671014969e421a40f5724", @mcast2, {[@dstopts={0x35, 0x4, [], [@jumbo={0xc2, 0x4, 0x26e16850}, @enc_lim={0x4, 0x1, 0x7}, @padn={0x1, 0xa, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @jumbo={0xc2, 0x4, 0x5}, @padn={0x1, 0x8, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}]}, @dstopts={0x793f83ef5092cdb8, 0x4, [], [@padn={0x1, 0x9, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}, @pad1, @padn={0x1, 0x4, [0x0, 0x0, 0x0, 0x0]}, @pad1, @jumbo={0xc2, 0x4, 0x3}, @ra={0x5, 0x2, 0x3}]}, @fragment={0x70, 0x0, 0x80, 0x0, 0x0, 0x1e, 0x64}], @tcp={{0x0, 0x0, 0x41424344, 0x41424344, 0x1, 0x0, 0xf, 0x0, 0x401, 0x0, 0xb0, {[@nop, @generic={0x0, 0xe, "9c77de45e59574d6ed6124af"}, @sack_perm={0x4, 0x2}, @nop, @md5sig={0x13, 0x12, "bfb8350d726099a64778c11dd1cdac8f"}, @eol]}}, {"c55f3756448788d832af78"}}}}}}}) syz_execute_func(&(0x7f0000000100)="18a7ac96715ac4c16971f198f28e1ca465f20f78dbed00c4e2c59ca89c9500000f0db00c9e0000db57ffc4e1a1c2e4cec4c39d6a18f5c4c2612f6cd365") syz_extract_tcp_res(&(0x7f0000000140), 0xe6, 0x6) csource_test.go:109: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; int collide = 0; again: for (call = 0; call < 13; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS___semctl, -1, 4, 4, 0x10000000); break; case 1: res = syscall(SYS_socket, 2, 2, 1); if (res != -1) r[0] = res; break; case 2: *(uint32_t*)0x100000c0 = 0; syscall(SYS_getsockopt, (intptr_t)r[0], 6, 0x401, 0x10000080, 0x100000c0); break; case 3: memcpy((void*)0x10000100, "rack\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x10000120 = 4; syscall(SYS_setsockopt, -1, 6, 0x2000, 0x10000100, 0x24); break; case 4: *(uint8_t*)0x10000140 = 0xa; *(uint8_t*)0x10000141 = 0; memcpy((void*)0x10000142, "./file0\000", 8); syscall(SYS_bindat, 0xffffff9c, (intptr_t)r[0], 0x10000140, 0xa); break; case 5: *(uint32_t*)0x10000180 = 0x74ce; syscall(SYS_cap_ioctls_limit, 0xffffff9c, 0x10000180); break; case 6: memcpy((void*)0x100001c0, "./file0/file0\000", 14); res = syscall(SYS_openat, 0xffffff9c, 0x100001c0, 0x10000, 2); if (res != -1) r[1] = res; break; case 7: *(uint64_t*)0x10000200 = 0x5e43b474; *(uint64_t*)0x10000240 = 9; syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); break; case 8: res = syscall(SYS_socket, 0x1c, 3, 0x93); if (res != -1) r[2] = res; break; case 9: *(uint32_t*)0x100002c0 = 4; syscall(SYS_getsockopt, (intptr_t)r[2], 0x84, 0x1f, 0x10000280, 0x100002c0); break; case 10: *(uint8_t*)0x10000000 = 0xaa; *(uint8_t*)0x10000001 = 0xaa; *(uint8_t*)0x10000002 = 0xaa; *(uint8_t*)0x10000003 = 0xaa; *(uint8_t*)0x10000004 = 0xaa; *(uint8_t*)0x10000005 = 0xbb; *(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(0x8100); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x1000000e, 3, 4, 12); *(uint16_t*)0x10000010 = htobe16(0x86dd); STORE_BY_BITMASK(uint8_t, , 0x10000012, 0xa, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x10000012, 6, 4, 4); memcpy((void*)0x10000013, "\x62\x2b\xff", 3); *(uint16_t*)0x10000016 = htobe16(0xaf); *(uint8_t*)0x10000018 = 0x17; *(uint8_t*)0x10000019 = 0; memcpy((void*)0x1000001a, "\x8c\xb1\x11\x00\x77\xc6\x71\x01\x49\x69\xe4\x21\xa4\x0f\x57\x24", 16); *(uint8_t*)0x1000002a = -1; *(uint8_t*)0x1000002b = 2; *(uint8_t*)0x1000002c = 0; *(uint8_t*)0x1000002d = 0; *(uint8_t*)0x1000002e = 0; *(uint8_t*)0x1000002f = 0; *(uint8_t*)0x10000030 = 0; *(uint8_t*)0x10000031 = 0; *(uint8_t*)0x10000032 = 0; *(uint8_t*)0x10000033 = 0; *(uint8_t*)0x10000034 = 0; *(uint8_t*)0x10000035 = 0; *(uint8_t*)0x10000036 = 0; *(uint8_t*)0x10000037 = 0; *(uint8_t*)0x10000038 = 0; *(uint8_t*)0x10000039 = 1; *(uint8_t*)0x1000003a = 0x35; *(uint8_t*)0x1000003b = 4; *(uint8_t*)0x1000003c = 0; *(uint8_t*)0x1000003d = 0; *(uint8_t*)0x1000003e = 0; *(uint8_t*)0x1000003f = 0; *(uint8_t*)0x10000040 = 0; *(uint8_t*)0x10000041 = 0; *(uint8_t*)0x10000042 = 0xc2; *(uint8_t*)0x10000043 = 4; *(uint32_t*)0x10000044 = htobe32(0x26e16850); *(uint8_t*)0x10000048 = 4; *(uint8_t*)0x10000049 = 1; *(uint8_t*)0x1000004a = 7; *(uint8_t*)0x1000004b = 1; *(uint8_t*)0x1000004c = 0xa; *(uint8_t*)0x1000004d = 0; *(uint8_t*)0x1000004e = 0; *(uint8_t*)0x1000004f = 0; *(uint8_t*)0x10000050 = 0; *(uint8_t*)0x10000051 = 0; *(uint8_t*)0x10000052 = 0; *(uint8_t*)0x10000053 = 0; *(uint8_t*)0x10000054 = 0; *(uint8_t*)0x10000055 = 0; *(uint8_t*)0x10000056 = 0; *(uint8_t*)0x10000057 = 0xc2; *(uint8_t*)0x10000058 = 4; *(uint32_t*)0x10000059 = htobe32(5); *(uint8_t*)0x1000005d = 1; *(uint8_t*)0x1000005e = 8; *(uint8_t*)0x1000005f = 0; *(uint8_t*)0x10000060 = 0; *(uint8_t*)0x10000061 = 0; *(uint8_t*)0x10000062 = 0; *(uint8_t*)0x10000063 = 0; *(uint8_t*)0x10000064 = 0; *(uint8_t*)0x10000065 = 0; *(uint8_t*)0x10000066 = 0; *(uint8_t*)0x1000006a = 0xb8; *(uint8_t*)0x1000006b = 4; *(uint8_t*)0x1000006c = 0; *(uint8_t*)0x1000006d = 0; *(uint8_t*)0x1000006e = 0; *(uint8_t*)0x1000006f = 0; *(uint8_t*)0x10000070 = 0; *(uint8_t*)0x10000071 = 0; *(uint8_t*)0x10000072 = 1; *(uint8_t*)0x10000073 = 9; *(uint8_t*)0x10000074 = 0; *(uint8_t*)0x10000075 = 0; *(uint8_t*)0x10000076 = 0; *(uint8_t*)0x10000077 = 0; *(uint8_t*)0x10000078 = 0; *(uint8_t*)0x10000079 = 0; *(uint8_t*)0x1000007a = 0; *(uint8_t*)0x1000007b = 0; *(uint8_t*)0x1000007c = 0; *(uint8_t*)0x1000007d = 0; *(uint8_t*)0x1000007e = 1; *(uint8_t*)0x1000007f = 0; *(uint8_t*)0x10000080 = 1; *(uint8_t*)0x10000081 = 4; *(uint8_t*)0x10000082 = 0; *(uint8_t*)0x10000083 = 0; *(uint8_t*)0x10000084 = 0; *(uint8_t*)0x10000085 = 0; *(uint8_t*)0x10000086 = 0; *(uint8_t*)0x10000087 = 1; *(uint8_t*)0x10000088 = 0; *(uint8_t*)0x10000089 = 0xc2; *(uint8_t*)0x1000008a = 4; *(uint32_t*)0x1000008b = htobe32(3); *(uint8_t*)0x1000008f = 5; *(uint8_t*)0x10000090 = 2; *(uint16_t*)0x10000091 = htobe16(3); *(uint8_t*)0x1000009a = 0x70; *(uint8_t*)0x1000009b = 0; *(uint8_t*)0x1000009c = 0x80; STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, , 0x1000009d, 0x1e, 3, 5); *(uint32_t*)0x1000009e = 0x64; *(uint16_t*)0x100000a2 = htobe16(0x4e20 + procid*4); *(uint16_t*)0x100000a4 = htobe16(0x4e20 + procid*4); *(uint32_t*)0x100000a6 = 0x41424344; *(uint32_t*)0x100000aa = 0x41424344; STORE_BY_BITMASK(uint8_t, , 0x100000ae, 1, 0, 1); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0, 1, 3); STORE_BY_BITMASK(uint8_t, , 0x100000ae, 0xf, 4, 4); *(uint8_t*)0x100000af = 0; *(uint16_t*)0x100000b0 = htobe16(0x401); *(uint16_t*)0x100000b2 = htobe16(0); *(uint16_t*)0x100000b4 = htobe16(0xb0); *(uint8_t*)0x100000b6 = 1; *(uint8_t*)0x100000b7 = 0; *(uint8_t*)0x100000b8 = 0xe; memcpy((void*)0x100000b9, "\x9c\x77\xde\x45\xe5\x95\x74\xd6\xed\x61\x24\xaf", 12); *(uint8_t*)0x100000c5 = 4; *(uint8_t*)0x100000c6 = 2; *(uint8_t*)0x100000c7 = 1; *(uint8_t*)0x100000c8 = 0x13; *(uint8_t*)0x100000c9 = 0x12; memcpy((void*)0x100000ca, "\xbf\xb8\x35\x0d\x72\x60\x99\xa6\x47\x78\xc1\x1d\xd1\xcd\xac\x8f", 16); *(uint8_t*)0x100000da = 0; memcpy((void*)0x100000de, "\xc5\x5f\x37\x56\x44\x87\x88\xd8\x32\xaf\x78", 11); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x1000001a, 16); csum_inet_update(&csum_1, (const uint8_t*)0x1000002a, 16); uint32_t csum_1_chunk_2 = 0x47000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 4); uint32_t csum_1_chunk_3 = 0x6000000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 4); csum_inet_update(&csum_1, (const uint8_t*)0x100000a2, 71); *(uint16_t*)0x100000b2 = csum_inet_digest(&csum_1); break; case 11: memcpy((void*)0x10000100, "\x18\xa7\xac\x96\x71\x5a\xc4\xc1\x69\x71\xf1\x98\xf2\x8e\x1c\xa4\x65\xf2\x0f\x78\xdb\xed\x00\xc4\xe2\xc5\x9c\xa8\x9c\x95\x00\x00\x0f\x0d\xb0\x0c\x9e\x00\x00\xdb\x57\xff\xc4\xe1\xa1\xc2\xe4\xce\xc4\xc3\x9d\x6a\x18\xf5\xc4\xc2\x61\x2f\x6c\xd3\x65", 61); syz_execute_func(0x10000100); 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; } :381:11: error: use of undeclared identifier 'SYS_copy_file_range' syscall(SYS_copy_file_range, (intptr_t)r[1], 0x10000200, 0xffffff9c, 0x10000240, 9ull, 0); ^ 1 error generated. compiler invocation: clang [-o /tmp/syz-executor484205903 -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.13s) csource_test.go:106: --- FAIL: TestGenerate/freebsd/386/8 (0.95s) csource_test.go:106: --- FAIL: TestGenerate/freebsd/386/11 (1.16s) csource_test.go:106: --- FAIL: TestGenerate/freebsd/386/1 (1.19s) csource_test.go:106: --- FAIL: TestGenerate/freebsd/386/10 (1.16s) csource_test.go:106: FAIL FAIL github.com/google/syzkaller/pkg/csource 9.172s ok github.com/google/syzkaller/pkg/db (cached) ? github.com/google/syzkaller/pkg/debugtracer [no test files] ok github.com/google/syzkaller/pkg/email (cached) ? github.com/google/syzkaller/pkg/gce [no test files] ? github.com/google/syzkaller/pkg/gcs [no test files] ? github.com/google/syzkaller/pkg/hash [no test files] ok github.com/google/syzkaller/pkg/host 0.996s ? github.com/google/syzkaller/pkg/html [no test files] ok github.com/google/syzkaller/pkg/ifuzz (cached) ? github.com/google/syzkaller/pkg/ifuzz/iset [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc/generated [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86 [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/generated [no test files] ok github.com/google/syzkaller/pkg/instance 1.045s ok github.com/google/syzkaller/pkg/ipc 3.704s ? github.com/google/syzkaller/pkg/ipc/ipcconfig [no test files] ? github.com/google/syzkaller/pkg/kcidb [no test files] ok github.com/google/syzkaller/pkg/kconfig 0.037s ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig (cached) ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report (cached) ok github.com/google/syzkaller/pkg/repro (cached) ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 52.339s 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.368s ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs 8.909s ok github.com/google/syzkaller/prog (cached) ok github.com/google/syzkaller/prog/test (cached) ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux (cached) ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ok github.com/google/syzkaller/sys/openbsd (cached) ? github.com/google/syzkaller/sys/openbsd/gen [no test files] ? github.com/google/syzkaller/sys/syz-extract [no test files] ? github.com/google/syzkaller/sys/syz-sysgen [no test files] ? github.com/google/syzkaller/sys/targets [no test files] ? github.com/google/syzkaller/sys/test [no test files] ? github.com/google/syzkaller/sys/test/gen [no test files] ? github.com/google/syzkaller/sys/trusty [no test files] ? github.com/google/syzkaller/sys/trusty/gen [no test files] ? github.com/google/syzkaller/sys/windows [no test files] ? github.com/google/syzkaller/sys/windows/gen [no test files] ok github.com/google/syzkaller/syz-ci (cached) ok github.com/google/syzkaller/syz-fuzzer (cached) ok github.com/google/syzkaller/syz-hub (cached) ok github.com/google/syzkaller/syz-hub/state (cached) ok github.com/google/syzkaller/syz-manager 1.002s ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-build [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ? github.com/google/syzkaller/tools/syz-kconf [no test files] ok github.com/google/syzkaller/tools/syz-linter 1.941s ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser (cached) ok github.com/google/syzkaller/tools/syz-trace2syz/proggen (cached) ? github.com/google/syzkaller/tools/syz-tty [no test files] ? github.com/google/syzkaller/tools/syz-upgrade [no test files] ? github.com/google/syzkaller/tools/syz-usbgen [no test files] ok github.com/google/syzkaller/vm (cached) ? github.com/google/syzkaller/vm/adb [no test files] ? github.com/google/syzkaller/vm/bhyve [no test files] ? github.com/google/syzkaller/vm/gce [no test files] ? github.com/google/syzkaller/vm/gvisor [no test files] ok github.com/google/syzkaller/vm/isolated (cached) ? github.com/google/syzkaller/vm/kvm [no test files] ? github.com/google/syzkaller/vm/odroid [no test files] ? github.com/google/syzkaller/vm/qemu [no test files] ok github.com/google/syzkaller/vm/vmimpl (cached) ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] FAIL