ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/executor 1.086s ok github.com/google/syzkaller/pkg/ast 3.511s 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 27.515s ? 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 (11.24s) --- FAIL: TestGenerate/openbsd/amd64 (0.50s) csource_test.go:52: seed=1633099714002840323 --- FAIL: TestGenerate/openbsd/amd64/0 (2.26s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); syscall(SYS_setuid, 0); memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); 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; } :175:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :173:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2051833877 -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 (2.36s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :287:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :285:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor1852337597 -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 (2.00s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :324:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :322:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2684734728 -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.44s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :314:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :312:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor666486873 -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 (2.70s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); res = syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); res = syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); res = syscall(SYS_lchown, 0x20000100ul, 0, 0); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: res = syscall(SYS_setuid, 0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; res = syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); res = syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); res = syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); (void)res; break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); res = -1; errno = EFAULT; res = syz_execute_func(0x20000100); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: (void)res; break; case 13: res = -1; errno = EFAULT; res = syz_open_pts(); fprintf(stderr, "### call=13 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; } :313:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :311:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor4098218816 -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.74s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :335:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :333:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor657984185 -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.71s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :312:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :310:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor3321113925 -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/11 (2.45s) 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:false HandleSegv:false Repro:false Trace:false LegacyOptions:{Fault:false FaultCall:0 FaultNth:0}} program: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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 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 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)))) #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++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { 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; } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: syz_open_pts(); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); setup_fault(); do_sandbox_none(); return 0; } :260:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :258:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor3854842484 -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/10 (2.48s) csource_test.go:118: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none Leak:false NetInjection:true 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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 #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)))) #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 int tunfd = -1; #define MAX_TUN 4 #define TUN_IFACE "tap%d" #define TUN_DEVICE "/dev/tap%d" #define LOCAL_MAC "aa:aa:aa:aa:aa:aa" #define REMOTE_MAC "aa:aa:aa:aa:aa:bb" #define LOCAL_IPV4 "172.20.%d.170" #define REMOTE_IPV4 "172.20.%d.187" #define LOCAL_IPV6 "fe80::%02hxaa" #define REMOTE_IPV6 "fe80::%02hxbb" static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; va_start(args, format); char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); int rv = system(command); if (rv) { if (panic) exit(1); } } static void initialize_tun(int tun_id) { if (tun_id < 0 || tun_id >= MAX_TUN) exit(1); char tun_device[sizeof(TUN_DEVICE)]; snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id); char tun_iface[sizeof(TUN_IFACE)]; snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id); execute_command(0, "ifconfig %s destroy", tun_iface); tunfd = open(tun_device, O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open %s: errno=%d\n", tun_device, errno); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; char local_mac[sizeof(LOCAL_MAC)]; snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC); execute_command(1, "ifconfig %s lladdr %s", tun_iface, local_mac); char local_ipv4[sizeof(LOCAL_IPV4)]; snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id); execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4); char remote_mac[sizeof(REMOTE_MAC)]; char remote_ipv4[sizeof(REMOTE_IPV4)]; snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC); snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, tun_id); execute_command(0, "arp -s %s %s", remote_ipv4, remote_mac); char local_ipv6[sizeof(LOCAL_IPV6)]; snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, tun_id); execute_command(1, "ifconfig %s inet6 %s", tun_iface, local_ipv6); char remote_ipv6[sizeof(REMOTE_IPV6)]; snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, tun_id); execute_command(0, "ndp -s %s%%%s %s", remote_ipv6, tun_iface, remote_mac); } static long syz_emit_ethernet(volatile long a0, volatile long a1) { if (tunfd < 0) return (uintptr_t)-1; size_t length = a0; const char* data = (char*)a1; return write(tunfd, data, length); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; exit(1); } return rv; } struct tcp_resources { uint32_t seq; uint32_t ack; }; static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile long a2) { if (tunfd < 0) return (uintptr_t)-1; char data[1000]; int rv = read_tun(&data[0], sizeof(data)); if (rv == -1) return (uintptr_t)-1; size_t length = rv; if (length < sizeof(struct ether_header)) return (uintptr_t)-1; struct ether_header* ethhdr = (struct ether_header*)&data[0]; struct tcphdr* tcphdr = 0; if (ethhdr->ether_type == htons(ETHERTYPE_IP)) { if (length < sizeof(struct ether_header) + sizeof(struct ip)) return (uintptr_t)-1; struct ip* iphdr = (struct ip*)&data[sizeof(struct ether_header)]; if (iphdr->ip_p != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + iphdr->ip_hl * 4 + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + iphdr->ip_hl * 4]; } else { if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr)) return (uintptr_t)-1; struct ip6_hdr* ipv6hdr = (struct ip6_hdr*)&data[sizeof(struct ether_header)]; if (ipv6hdr->ip6_nxt != IPPROTO_TCP) return (uintptr_t)-1; if (length < sizeof(struct ether_header) + sizeof(struct ip6_hdr) + sizeof(struct tcphdr)) return (uintptr_t)-1; tcphdr = (struct tcphdr*)&data[sizeof(struct ether_header) + sizeof(struct ip6_hdr)]; } struct tcp_resources* res = (struct tcp_resources*)a0; res->seq = htonl(ntohl(tcphdr->th_seq) + (uint32_t)a1); res->ack = htonl(ntohl(tcphdr->th_ack) + (uint32_t)a2); return 0; } static void sandbox_common() { 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(); initialize_tun(procid); loop(); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); syz_emit_ethernet(0xe8, 0x20000000); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: syz_extract_tcp_res(0x20000140, 9, 0); break; case 13: 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; } :479:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :477:3: note: previous statement is here if (current_time_ms() - start < 5000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor1640421966 -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 (2.33s) 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: getsockname$unix(0xffffffffffffff9c, &(0x7f0000000000)=@file={0x0, ""/24}, &(0x7f0000000040)=0x1a) (fail_nth: 1) r0 = open$dir(&(0x7f0000000080)='./file0\x00', 0x80, 0x1) faccessat(r0, &(0x7f00000000c0)='./file0\x00', 0x70, 0x0) lchown(&(0x7f0000000100)='./file0\x00', 0x0, 0x0) setuid(0x0) r1 = openat$pf(0xffffffffffffff9c, &(0x7f0000000140), 0x80, 0x0) ioctl$BIOCSRTIMEOUT(r1, 0x8010426d, &(0x7f0000000180)={0x8, 0x8c}) linkat(r0, &(0x7f00000001c0)='./file0\x00', r1, &(0x7f0000000200)='./file0\x00', 0x6c682d7c5351a05a) r2 = open(&(0x7f0000000240)='./file0\x00', 0x8000, 0x24) readlinkat(r2, &(0x7f0000000280)='./file0\x00', &(0x7f00000002c0)=""/4096, 0x1000) syz_emit_ethernet(0xe8, &(0x7f0000000000)={@local, @local, [{[{0x88a8, 0x6, 0x1, 0x3}], {0x8100, 0x5, 0x0, 0x2}}], {@generic={0x80f3, "fb8c821c887dd90c974b0567a674eed293597eeaae633b3932958b9da98d3c56a83e7175bb7aa469547492cb58279cae1dda33593f10b34b40a9cbe9f816a05aa72f587baf6eaa5cebe0fc499ca7d718417e992d16c838a87785f6c77f64902103ee540314e6f2aee3b990b6bce62304f2de32d6635f75869551bab5ab86ef680d981ba80c5d461cba7c8e9bc3f586a82adb5975dcc1f06efa27547662eab4f4fd67105448d0203eb4c75e54a379393910e126d982f20d2766a53dac3e34c26ecb09362bf1d77eef60921fc189f53fbc08cc"}}}) syz_execute_func(&(0x7f0000000100)="479d0fbabc6f00000000008fa968901d7f80bf6c660fe28c8f3fd0065bc4a105f330440fb19f20d8c07d44804ae50040d9f0420fec9d0ba358a68f4978d67200") syz_extract_tcp_res(&(0x7f0000000140), 0x9, 0x0) 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)))) #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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000040 = 0x1a; inject_fault(1); syscall(SYS_getsockname, 0xffffff9c, 0x20000000ul, 0x20000040ul); break; case 1: memcpy((void*)0x20000080, "./file0\000", 8); res = syscall(SYS_open, 0x20000080ul, 0x80ul, 1ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x200000c0, "./file0\000", 8); syscall(SYS_faccessat, r[0], 0x200000c0ul, 0x70ul, 0ul); break; case 3: memcpy((void*)0x20000100, "./file0\000", 8); syscall(SYS_lchown, 0x20000100ul, 0, 0); break; case 4: syscall(SYS_setuid, 0); break; case 5: memcpy((void*)0x20000140, "/dev/pf\000", 8); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000140ul, 0x80ul, 0ul); if (res != -1) r[1] = res; break; case 6: *(uint64_t*)0x20000180 = 8; *(uint64_t*)0x20000188 = 0x8c; syscall(SYS_ioctl, r[1], 0x8010426dul, 0x20000180ul); break; case 7: memcpy((void*)0x200001c0, "./file0\000", 8); memcpy((void*)0x20000200, "./file0\000", 8); syscall(SYS_linkat, r[0], 0x200001c0ul, r[1], 0x20000200ul, 0x6c682d7c5351a05aul); break; case 8: memcpy((void*)0x20000240, "./file0\000", 8); res = syscall(SYS_open, 0x20000240ul, 0x8000ul, 0x24ul); if (res != -1) r[2] = res; break; case 9: memcpy((void*)0x20000280, "./file0\000", 8); syscall(SYS_readlinkat, r[2], 0x20000280ul, 0x200002c0ul, 0x1000ul); break; case 10: memset((void*)0x20000000, 170, 5); *(uint8_t*)0x20000005 = 0xaa; memset((void*)0x20000006, 170, 5); *(uint8_t*)0x2000000b = 0xaa; *(uint16_t*)0x2000000c = htobe16(0x88a8); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 6, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 1, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000e, 3, 4, 12); *(uint16_t*)0x20000010 = htobe16(0x8100); STORE_BY_BITMASK(uint16_t, , 0x20000012, 5, 0, 3); STORE_BY_BITMASK(uint16_t, , 0x20000012, 0, 3, 1); STORE_BY_BITMASK(uint16_t, , 0x20000012, 2, 4, 12); *(uint16_t*)0x20000014 = htobe16(0x80f3); memcpy((void*)0x20000016, "\xfb\x8c\x82\x1c\x88\x7d\xd9\x0c\x97\x4b\x05\x67\xa6\x74\xee\xd2\x93\x59\x7e\xea\xae\x63\x3b\x39\x32\x95\x8b\x9d\xa9\x8d\x3c\x56\xa8\x3e\x71\x75\xbb\x7a\xa4\x69\x54\x74\x92\xcb\x58\x27\x9c\xae\x1d\xda\x33\x59\x3f\x10\xb3\x4b\x40\xa9\xcb\xe9\xf8\x16\xa0\x5a\xa7\x2f\x58\x7b\xaf\x6e\xaa\x5c\xeb\xe0\xfc\x49\x9c\xa7\xd7\x18\x41\x7e\x99\x2d\x16\xc8\x38\xa8\x77\x85\xf6\xc7\x7f\x64\x90\x21\x03\xee\x54\x03\x14\xe6\xf2\xae\xe3\xb9\x90\xb6\xbc\xe6\x23\x04\xf2\xde\x32\xd6\x63\x5f\x75\x86\x95\x51\xba\xb5\xab\x86\xef\x68\x0d\x98\x1b\xa8\x0c\x5d\x46\x1c\xba\x7c\x8e\x9b\xc3\xf5\x86\xa8\x2a\xdb\x59\x75\xdc\xc1\xf0\x6e\xfa\x27\x54\x76\x62\xea\xb4\xf4\xfd\x67\x10\x54\x48\xd0\x20\x3e\xb4\xc7\x5e\x54\xa3\x79\x39\x39\x10\xe1\x26\xd9\x82\xf2\x0d\x27\x66\xa5\x3d\xac\x3e\x34\xc2\x6e\xcb\x09\x36\x2b\xf1\xd7\x7e\xef\x60\x92\x1f\xc1\x89\xf5\x3f\xbc\x08\xcc", 210); break; case 11: memcpy((void*)0x20000100, "\x47\x9d\x0f\xba\xbc\x6f\x00\x00\x00\x00\x00\x8f\xa9\x68\x90\x1d\x7f\x80\xbf\x6c\x66\x0f\xe2\x8c\x8f\x3f\xd0\x06\x5b\xc4\xa1\x05\xf3\x30\x44\x0f\xb1\x9f\x20\xd8\xc0\x7d\x44\x80\x4a\xe5\x00\x40\xd9\xf0\x42\x0f\xec\x9d\x0b\xa3\x58\xa6\x8f\x49\x78\xd6\x72\x00", 64); syz_execute_func(0x20000100); break; case 12: break; case 13: 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; } :312:4: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation] kill_and_wait(pid, &status); ^ :310:3: note: previous statement is here if (current_time_ms() - start < 15000) ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor675007007 -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/4 (2.58s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/2 (2.07s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/6 (2.35s) csource_test.go:116: --- FAIL: TestGenerate/openbsd/amd64/1 (1.77s) csource_test.go:116: FAIL FAIL github.com/google/syzkaller/pkg/csource 24.575s 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.157s 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 30.568s 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.416s ? 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