ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 0.998s ok github.com/google/syzkaller/pkg/ast 3.087s ok github.com/google/syzkaller/pkg/auth (cached) ok github.com/google/syzkaller/pkg/bisect (cached) ok github.com/google/syzkaller/pkg/build (cached) ok github.com/google/syzkaller/pkg/compiler 29.207s ? github.com/google/syzkaller/pkg/config [no test files] ok github.com/google/syzkaller/pkg/cover (cached) ok github.com/google/syzkaller/pkg/cover/backend (cached) --- FAIL: TestGenerate (7.11s) --- FAIL: TestGenerate/openbsd/amd64 (0.01s) csource_test.go:52: seed=1633544681684673594 --- FAIL: TestGenerate/openbsd/amd64/0 (1.36s) csource_test.go:118: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { if (setsid() == -1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); syz_open_pts(); } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :106:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :111:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :124:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor2772847697 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/5 (1.45s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:1 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor1069387048 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/13 (1.46s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor290075738 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/6 (1.48s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20 + procid*4); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :198:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :203:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :216:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor4173336492 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/15 (1.52s) csource_test.go:118: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:true Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long procid; static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; int collide = 0; again: for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20 + procid*4); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :198:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :203:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :216:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor1227855232 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/9 (1.57s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:setuid Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, WUNTRACED) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_setuid(void) { int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); char pwbuf[1024]; struct passwd *pw, pwres; if (getpwnam_r("nobody", &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 || !pw) exit(1); if (setgroups(0, NULL)) exit(1); if (setgid(pw->pw_gid)) exit(1); if (setuid(pw->pw_uid)) exit(1); loop(); exit(1); } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_setuid(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor590973177 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/7 (1.62s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:10 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 500); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 15000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor480224545 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/8 (1.66s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox: Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); loop(); return 0; } :195:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :200:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :213:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor1655155806 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/14 (1.72s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:true LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { fprintf(stderr, "### start\n"); int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); res = syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); res = syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: res = syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; res = syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; res = syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; res = syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); res = -1; errno = EFAULT; res = syz_execute_func(0x200001c0); fprintf(stderr, "### call=10 errno=%u\n", res == -1 ? errno : 0); break; case 11: res = -1; errno = EFAULT; res = syz_open_pts(); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor1914516105 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/2 (1.74s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/4 (1.74s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: r0 = socket(0x18, 0x4, 0x1) (fail_nth: 1) pwrite(r0, &(0x7f0000000000)="c0dfea571b53ba4d1739fb64e4546aaea4b137428e987e2a10ae2f9319d2a11d0bb2222052edb8dcc4fec8af6529894887bf8ae59c6d44ff79405f14ecfe2de2914a712e03182570edc3700d0566277a7adeb1871b7b48c88b96e6983efee994a5e04c6d5d9d4d2d0c3d49717bc5e72a52cc49f54ef6f285c6d681d41ec1b41ffac25d5175a3fcad0f3ee614045aa9513beccee99e11651462d5769314a9d8279c63e8c09d828e85ae90ebeeb649b77ec51f27d769c6cc0edfca07c1e1d9a24f7639e7f5ce9a869555bd26457d221dae19f62bd319f8fd89705860e0bf5a62bee8c035557ce1bf81c1a14021369f8b5eede69f018e", 0xf5, 0x0, 0x8a5) sendto(r0, &(0x7f0000000100)="ee45e106f7be18bc4dd51edfba844cf169c276e11e8139fce8a1f79b3e2276ca909cc399745eced193eb30d3850416d7ba01098f9c85f192cedc0ad60c62436c3b8698384100b2a8c7eeea998e", 0x4d, 0x400, &(0x7f0000000180)=@un=@file={0x1, './file0\x00'}, 0xa) ioctl$BIOCGETIF(0xffffffffffffffff, 0x4020426b, &(0x7f00000001c0)={""/16, @ifru_dstaddr=@in}) r1 = openat$wsmuxmouse(0xffffffffffffff9c, &(0x7f0000000200), 0x10, 0x0) ioctl$BIOCSHDRCMPLT(r1, 0x80044275, &(0x7f0000000240)=0x1) r2 = openat(r1, &(0x7f0000000280)='./file0\x00', 0x800, 0x20) bind(r2, &(0x7f00000002c0)=@in6={0x18, 0x0, 0x400, 0x4}, 0xc) r3 = accept$unix(r2, &(0x7f0000000300)=@file={0x0, ""/4096}, &(0x7f0000001340)=0x1002) getsockopt$sock_int(r3, 0xffff, 0x200, &(0x7f0000001380), &(0x7f00000013c0)=0x4) syz_emit_ethernet(0x1ac, &(0x7f0000000000)={@broadcast, @remote, [{[{0x88a8, 0x1, 0x0, 0x2}], {0x8100, 0x2, 0x0, 0x3}}], {@ipv6={0x86dd, {0x8, 0x6, "5d35eb", 0x16e, 0x1, 0x0, @remote={0xfe, 0x80, '\x00', 0x0}, @ipv4, {[@hopopts={0x2, 0x23, '\x00', [@pad1, @generic={0x4, 0xdf, "8be9d2915b000be4f55da5d47f42fc49eb4fa62d2fd5e4ef831a04843a40c7400e06db5ad86cfcd59b5c4405e3cc849ff2bfe6048b6254d416e12c4e4a4c8feb845aa0b8a48c37fd8ebdaec983e65946e557710f1a8f469a2d5cf5b9a71dfa1217c35af6280eec0d3031334b27237a77ec6cebce27a86baf239f27da6acb7b27d1105a26fbf70ac4196004541b5225a6f1056e7c52da8a30787b2442f40f9bc605063829372b868a696469c7dcedb3a9849d386785abae54b3fec17a2cc850144129530c300b9d1e091d5b24294012f21a5b25003149769f7c1fe133ea6a58"}, @generic={0x1f, 0x34, "9136d6c5e517b1e0c3712975eff07ca293cfd880c54d01f215d8b8d0cba263fc46846a958ca3af5066213e90b7a17d2e01a3779b"}, @ra={0x5, 0x2, 0x401}]}], @udp={{0x1, 0x3, 0x8}, {"514203c5b990bca9008fc87d9bf9a29c61f94a2ba5e45ad4f1165ddea8a9d6d7cb67f681cdf99a7d3066619876bd4985d2ad9c694ed0d7c2095b39909053"}}}}}}}) syz_execute_func(&(0x7f00000001c0)="c4837904de5d8f8978015b79c4e3355de6b7c421225e5a7cc442092bdef30fa7c8c461d176926cd70000447f30c403315d55c5f7c4c21db8b387c93752") syz_extract_tcp_res(&(0x7f0000000200), 0x5, 0x5d) syz_open_pts() csource_test.go:119: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i = 0; for (; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += le16toh((uint16_t)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 14; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (; iter < 10; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: inject_fault(1); res = syscall(SYS_socket, 0x18ul, 4ul, 1); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\xc0\xdf\xea\x57\x1b\x53\xba\x4d\x17\x39\xfb\x64\xe4\x54\x6a\xae\xa4\xb1\x37\x42\x8e\x98\x7e\x2a\x10\xae\x2f\x93\x19\xd2\xa1\x1d\x0b\xb2\x22\x20\x52\xed\xb8\xdc\xc4\xfe\xc8\xaf\x65\x29\x89\x48\x87\xbf\x8a\xe5\x9c\x6d\x44\xff\x79\x40\x5f\x14\xec\xfe\x2d\xe2\x91\x4a\x71\x2e\x03\x18\x25\x70\xed\xc3\x70\x0d\x05\x66\x27\x7a\x7a\xde\xb1\x87\x1b\x7b\x48\xc8\x8b\x96\xe6\x98\x3e\xfe\xe9\x94\xa5\xe0\x4c\x6d\x5d\x9d\x4d\x2d\x0c\x3d\x49\x71\x7b\xc5\xe7\x2a\x52\xcc\x49\xf5\x4e\xf6\xf2\x85\xc6\xd6\x81\xd4\x1e\xc1\xb4\x1f\xfa\xc2\x5d\x51\x75\xa3\xfc\xad\x0f\x3e\xe6\x14\x04\x5a\xa9\x51\x3b\xec\xce\xe9\x9e\x11\x65\x14\x62\xd5\x76\x93\x14\xa9\xd8\x27\x9c\x63\xe8\xc0\x9d\x82\x8e\x85\xae\x90\xeb\xee\xb6\x49\xb7\x7e\xc5\x1f\x27\xd7\x69\xc6\xcc\x0e\xdf\xca\x07\xc1\xe1\xd9\xa2\x4f\x76\x39\xe7\xf5\xce\x9a\x86\x95\x55\xbd\x26\x45\x7d\x22\x1d\xae\x19\xf6\x2b\xd3\x19\xf8\xfd\x89\x70\x58\x60\xe0\xbf\x5a\x62\xbe\xe8\xc0\x35\x55\x7c\xe1\xbf\x81\xc1\xa1\x40\x21\x36\x9f\x8b\x5e\xed\xe6\x9f\x01\x8e", 245); syscall(SYS_pwrite, r[0], 0x20000000ul, 0xf5ul, 0ul, 0x8a5ul); break; case 2: memcpy((void*)0x20000100, "\xee\x45\xe1\x06\xf7\xbe\x18\xbc\x4d\xd5\x1e\xdf\xba\x84\x4c\xf1\x69\xc2\x76\xe1\x1e\x81\x39\xfc\xe8\xa1\xf7\x9b\x3e\x22\x76\xca\x90\x9c\xc3\x99\x74\x5e\xce\xd1\x93\xeb\x30\xd3\x85\x04\x16\xd7\xba\x01\x09\x8f\x9c\x85\xf1\x92\xce\xdc\x0a\xd6\x0c\x62\x43\x6c\x3b\x86\x98\x38\x41\x00\xb2\xa8\xc7\xee\xea\x99\x8e", 77); *(uint16_t*)0x20000180 = 1; memcpy((void*)0x20000182, "./file0\000", 8); syscall(SYS_sendto, r[0], 0x20000100ul, 0x4dul, 0x400ul, 0x20000180ul, 0xaul); break; case 3: syscall(SYS_ioctl, -1, 0x4020426bul, 0x200001c0ul); break; case 4: memcpy((void*)0x20000200, "/dev/wsmouse\000", 13); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000200ul, 0x10ul, 0ul); if (res != -1) r[1] = res; break; case 5: *(uint32_t*)0x20000240 = 1; syscall(SYS_ioctl, r[1], 0x80044275ul, 0x20000240ul); break; case 6: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_openat, r[1], 0x20000280ul, 0x800ul, 0x20ul); if (res != -1) r[2] = res; break; case 7: *(uint16_t*)0x200002c0 = 0x18; *(uint16_t*)0x200002c2 = htobe16(0x4e20); *(uint32_t*)0x200002c4 = 0x400; *(uint32_t*)0x200002c8 = 4; syscall(SYS_bind, r[2], 0x200002c0ul, 0xcul); break; case 8: *(uint32_t*)0x20001340 = 0x1002; res = syscall(SYS_accept, r[2], 0x20000300ul, 0x20001340ul); if (res != -1) r[3] = res; break; case 9: *(uint32_t*)0x200013c0 = 4; syscall(SYS_getsockopt, r[3], 0xffff, 0x200, 0x20001380ul, 0x200013c0ul); break; case 10: memcpy((void*)0x200001c0, "\xc4\x83\x79\x04\xde\x5d\x8f\x89\x78\x01\x5b\x79\xc4\xe3\x35\x5d\xe6\xb7\xc4\x21\x22\x5e\x5a\x7c\xc4\x42\x09\x2b\xde\xf3\x0f\xa7\xc8\xc4\x61\xd1\x76\x92\x6c\xd7\x00\x00\x44\x7f\x30\xc4\x03\x31\x5d\x55\xc5\xf7\xc4\xc2\x1d\xb8\xb3\x87\xc9\x37\x52", 61); syz_execute_func(0x200001c0); break; case 11: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :196:13: error: unused function 'csum_inet_init' [-Werror,-Wunused-function] static void csum_inet_init(struct csum_inet* csum) ^ :201:13: error: unused function 'csum_inet_update' [-Werror,-Wunused-function] static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) ^ :214:17: error: unused function 'csum_inet_digest' [-Werror,-Wunused-function] static uint16_t csum_inet_digest(struct csum_inet* csum) ^ 3 errors generated. compiler invocation: c++ [-o /tmp/syz-executor1320808414 -DGOOS_openbsd=1 -DGOARCH_amd64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -static -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384] --- FAIL: TestGenerate/openbsd/amd64/1 (1.46s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/3 (1.46s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/11 (1.49s) csource_test.go:116: FAIL FAIL github.com/google/syzkaller/pkg/csource 16.000s 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 (cached) ? 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 (cached) ok github.com/google/syzkaller/pkg/ipc (cached) ? 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.277s 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 (cached) ok github.com/google/syzkaller/pkg/serializer (cached) ? github.com/google/syzkaller/pkg/signal [no test files] ok github.com/google/syzkaller/pkg/symbolizer (cached) ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs (cached) ok github.com/google/syzkaller/prog (cached) ok github.com/google/syzkaller/prog/test (cached) ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/darwin [no test files] ? github.com/google/syzkaller/sys/darwin/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux (cached) ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ok github.com/google/syzkaller/sys/openbsd (cached) ? github.com/google/syzkaller/sys/openbsd/gen [no test files] ? github.com/google/syzkaller/sys/syz-extract [no test files] ? github.com/google/syzkaller/sys/syz-sysgen [no test files] ? github.com/google/syzkaller/sys/targets [no test files] ? github.com/google/syzkaller/sys/test [no test files] ? github.com/google/syzkaller/sys/test/gen [no test files] ? github.com/google/syzkaller/sys/trusty [no test files] ? github.com/google/syzkaller/sys/trusty/gen [no test files] ? github.com/google/syzkaller/sys/windows [no test files] ? github.com/google/syzkaller/sys/windows/gen [no test files] ok github.com/google/syzkaller/syz-ci (cached) ok github.com/google/syzkaller/syz-fuzzer (cached) ok github.com/google/syzkaller/syz-hub (cached) ok github.com/google/syzkaller/syz-hub/state (cached) ok github.com/google/syzkaller/syz-manager (cached) ? github.com/google/syzkaller/syz-runner [no test files] ok github.com/google/syzkaller/syz-verifier 1.464s ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-build [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ok github.com/google/syzkaller/tools/syz-kconf (cached) ok github.com/google/syzkaller/tools/syz-linter (cached) ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser (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