ok github.com/google/syzkaller/dashboard/app (cached) ? github.com/google/syzkaller/dashboard/dashapi [no test files] ? github.com/google/syzkaller/executor [no test files] ok github.com/google/syzkaller/pkg/ast 1.098s ? github.com/google/syzkaller/pkg/bisect [no test files] ok github.com/google/syzkaller/pkg/build 2.593s ok github.com/google/syzkaller/pkg/compiler 6.444s ok github.com/google/syzkaller/pkg/config (cached) ? github.com/google/syzkaller/pkg/cover [no test files] --- FAIL: TestGenerate (8.86s) --- FAIL: TestGenerate/test/64_fork (0.03s) csource_test.go:72: seed=1568762212470806835 --- FAIL: TestGenerate/test/64_fork/16 (1.02s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor452199535 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/0 (1.15s) csource_test.go:110: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: failed to build program: // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_one(void) { memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); syz_errno(2); syz_mmap(0x20ffa000, 0x2000); memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); syz_compare_int(3, 6, 4, 3, 0); memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); syz_errno(0x7ff); memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); syz_compare_int(2, 0x200, 6, 0, 0); syz_errno(0x40); memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); syz_exit(0); syz_mmap(0x20ff4000, 0x6000); } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor148221561 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/30 (1.11s) csource_test.go:110: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor505342722 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/28 (0.83s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor701343620 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/29 (0.98s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { intptr_t res; switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; res = syz_compare(0x20000000, 4, 0x20000040, 8); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: res = syz_errno(2); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: res = syz_mmap(0x20ffa000, 0x2000); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); res = syz_execute_func(0x20000080); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: res = syz_compare_int(3, 6, 4, 3, 0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); res = syz_compare(0x200000c0, 4, 0x20000100, 0xd0); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); res = syz_execute_func(0x20000200); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); res = syz_execute_func(0x20000240); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: res = syz_errno(0x7ff); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); res = syz_compare(0x20000280, 2, 0x200002c0, 8); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); res = syz_compare(0x20000000, 2, 0x20000040, 8); fprintf(stderr, "### call=10 errno=%u\n", res == -1 ? errno : 0); break; case 11: res = syz_compare_int(2, 0x200, 6, 0, 0); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: res = syz_errno(0x40); fprintf(stderr, "### call=12 errno=%u\n", res == -1 ? errno : 0); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); res = syz_execute_func(0x20000080); fprintf(stderr, "### call=13 errno=%u\n", res == -1 ? errno : 0); break; case 14: res = syz_exit(0); fprintf(stderr, "### call=14 errno=%u\n", res == -1 ? errno : 0); break; case 15: res = syz_mmap(0x20ff4000, 0x6000); fprintf(stderr, "### call=15 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor035695379 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/27 (0.92s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor330096470 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/26 (1.06s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor882988221 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/25 (1.30s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:true Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) { __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); } 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; NONFAILING(((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: NONFAILING(memcpy((void*)0x20000000, "Q--\000", 4)); NONFAILING(STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10)); NONFAILING(STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10)); NONFAILING(STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10)); NONFAILING(*(uint8_t*)0x20000044 = 0x84); syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: NONFAILING(memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50)); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: NONFAILING(memcpy((void*)0x200000c0, "Q--\000", 4)); NONFAILING(memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208)); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: NONFAILING(memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50)); syz_execute_func(0x20000200); break; case 7: NONFAILING(memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50)); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: NONFAILING(memcpy((void*)0x20000280, "-\000", 2)); NONFAILING(STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8)); NONFAILING(STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12)); NONFAILING(STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20)); NONFAILING(STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16)); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: NONFAILING(memcpy((void*)0x20000000, "\373\000", 2)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16)); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: NONFAILING(memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50)); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor993903864 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/24 (1.35s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor224883191 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/23 (1.25s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor501721834 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/22 (1.08s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:false HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 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; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor223706945 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/21 (1.05s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor950436268 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/20 (0.92s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor178220315 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/15 (0.81s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor679202208 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/8 (0.87s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor835630014 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/17 (0.91s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor278181893 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/18 (1.11s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor007718527 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/19 (1.23s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor656411090 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/14 (0.71s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor981722377 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/13 (0.74s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor541338324 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/12 (0.78s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor933861411 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/10 (0.68s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox: Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); loop(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor115280678 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/9 (0.74s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor704602701 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/11 (0.85s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor644800840 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/4 (0.71s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:false RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; for (call = 0; call < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor574638599 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/7 (0.74s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0; iter < 10; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor060684218 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/6 (0.68s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor205503953 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/5 (0.74s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor148984060 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/3 (0.68s) csource_test.go:110: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor963705899 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/2 (0.77s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor419923342 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64_fork/1 (0.76s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: syz_compare(&(0x7f0000000000)='Q--\x00', 0x4, &(0x7f0000000040)=@bf1={{0x7, 0x4, 0x80000001}, 0x284}, 0x8) syz_errno(0x2) syz_mmap(&(0x7f0000ffa000/0x2000)=nil, 0x2000) syz_execute_func(&(0x7f0000000080)="d27bb10597ac724037c0ee0649e4b241107d0dc8a756dbccde6621a058d8a92ac245d2521f5138efc6d935afd0892df5b672") syz_compare_int$3(0x3, 0x6, 0x4, 0x3) syz_compare(&(0x7f00000000c0)='Q--\x00', 0x4, &(0x7f0000000100)=@blob="143f39d855505146f40703697b991378e3ddbc7d2c6211ad71897feea9bc1751ac279305311a1cb88633ec4eb1ce7b3e340a02e7e9460283c4e0bd7b8f4c2cc307d5255f2380139da40980b86ec47ee347c8ee329199a975e6dba8acc00ff7119ea62e7a21b6fe7ffc5b4409e6cb92ec961397b89e1d58445ba417180fdd4ae73db8dc98d589d2f6461f9738fc04ddc5c1b854517bf919d01d5894cb17c7fe208fa0c0f3a5e1aab52fd741c5b19b2b8104f8444f5e0bb00d1d490955796e3db35feefcbbb2e9a30119fa4576c61990c2", 0xd0) syz_execute_func(&(0x7f0000000200)="e97a9397ceb2d124512f792113752507908e525caeb0eafd474eb608b3e14e3e6466741fcae5172ff022c49dd94b9d718f71") syz_execute_func(&(0x7f0000000240)="28e9f84a5f000c671e2c9c87e3fd5fcd703405f18d067debab342c78b984c34750136a906147ffa1e335997624e15d7ee48c") syz_errno(0x7ff) syz_compare(&(0x7f0000000280)='-\x00', 0x2, &(0x7f00000002c0)=@bf3={0x80, 0x0, 0x1, 0x8001, 0x7}, 0x8) syz_compare(&(0x7f0000000000)='\xfb\x00', 0x2, &(0x7f0000000040)=@bf2={0x5, 0x8, 0xffff, 0x8e1b, 0x7}, 0x8) syz_compare_int$2(0x2, 0x200, 0x6) syz_errno(0x40) syz_execute_func(&(0x7f0000000080)="05a37987e15dd500b74c543b2543b0a6d9ec49a5287ea490c6b29dd109087dfb264b4f1f730402e94ed101a35971f1d9ef2c") syz_exit(0x100000000) syz_mmap(&(0x7f0000ff4000/0x6000)=nil, 0x6000) csource_test.go:111: 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 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) exit(1); } closedir(dp); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000000, "Q--\000", 4); STORE_BY_BITMASK(uint32_t, , 0x20000040, 7, 0, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 4, 10, 10); STORE_BY_BITMASK(uint32_t, , 0x20000040, 0x80000001, 20, 10); *(uint8_t*)0x20000044 = 0x84; syz_compare(0x20000000, 4, 0x20000040, 8); break; case 1: syz_errno(2); break; case 2: syz_mmap(0x20ffa000, 0x2000); break; case 3: memcpy((void*)0x20000080, "\xd2\x7b\xb1\x05\x97\xac\x72\x40\x37\xc0\xee\x06\x49\xe4\xb2\x41\x10\x7d\x0d\xc8\xa7\x56\xdb\xcc\xde\x66\x21\xa0\x58\xd8\xa9\x2a\xc2\x45\xd2\x52\x1f\x51\x38\xef\xc6\xd9\x35\xaf\xd0\x89\x2d\xf5\xb6\x72", 50); syz_execute_func(0x20000080); break; case 4: syz_compare_int(3, 6, 4, 3, 0); break; case 5: memcpy((void*)0x200000c0, "Q--\000", 4); memcpy((void*)0x20000100, "\x14\x3f\x39\xd8\x55\x50\x51\x46\xf4\x07\x03\x69\x7b\x99\x13\x78\xe3\xdd\xbc\x7d\x2c\x62\x11\xad\x71\x89\x7f\xee\xa9\xbc\x17\x51\xac\x27\x93\x05\x31\x1a\x1c\xb8\x86\x33\xec\x4e\xb1\xce\x7b\x3e\x34\x0a\x02\xe7\xe9\x46\x02\x83\xc4\xe0\xbd\x7b\x8f\x4c\x2c\xc3\x07\xd5\x25\x5f\x23\x80\x13\x9d\xa4\x09\x80\xb8\x6e\xc4\x7e\xe3\x47\xc8\xee\x32\x91\x99\xa9\x75\xe6\xdb\xa8\xac\xc0\x0f\xf7\x11\x9e\xa6\x2e\x7a\x21\xb6\xfe\x7f\xfc\x5b\x44\x09\xe6\xcb\x92\xec\x96\x13\x97\xb8\x9e\x1d\x58\x44\x5b\xa4\x17\x18\x0f\xdd\x4a\xe7\x3d\xb8\xdc\x98\xd5\x89\xd2\xf6\x46\x1f\x97\x38\xfc\x04\xdd\xc5\xc1\xb8\x54\x51\x7b\xf9\x19\xd0\x1d\x58\x94\xcb\x17\xc7\xfe\x20\x8f\xa0\xc0\xf3\xa5\xe1\xaa\xb5\x2f\xd7\x41\xc5\xb1\x9b\x2b\x81\x04\xf8\x44\x4f\x5e\x0b\xb0\x0d\x1d\x49\x09\x55\x79\x6e\x3d\xb3\x5f\xee\xfc\xbb\xb2\xe9\xa3\x01\x19\xfa\x45\x76\xc6\x19\x90\xc2", 208); syz_compare(0x200000c0, 4, 0x20000100, 0xd0); break; case 6: memcpy((void*)0x20000200, "\xe9\x7a\x93\x97\xce\xb2\xd1\x24\x51\x2f\x79\x21\x13\x75\x25\x07\x90\x8e\x52\x5c\xae\xb0\xea\xfd\x47\x4e\xb6\x08\xb3\xe1\x4e\x3e\x64\x66\x74\x1f\xca\xe5\x17\x2f\xf0\x22\xc4\x9d\xd9\x4b\x9d\x71\x8f\x71", 50); syz_execute_func(0x20000200); break; case 7: memcpy((void*)0x20000240, "\x28\xe9\xf8\x4a\x5f\x00\x0c\x67\x1e\x2c\x9c\x87\xe3\xfd\x5f\xcd\x70\x34\x05\xf1\x8d\x06\x7d\xeb\xab\x34\x2c\x78\xb9\x84\xc3\x47\x50\x13\x6a\x90\x61\x47\xff\xa1\xe3\x35\x99\x76\x24\xe1\x5d\x7e\xe4\x8c", 50); syz_execute_func(0x20000240); break; case 8: syz_errno(0x7ff); break; case 9: memcpy((void*)0x20000280, "-\000", 2); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x80, 0, 4); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0, 4, 8); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 1, 12, 12); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 0x8001, 24, 20); STORE_BY_BITMASK(uint64_t, htobe64, 0x200002c0, 7, 44, 16); syz_compare(0x20000280, 2, 0x200002c0, 8); break; case 10: memcpy((void*)0x20000000, "\373\000", 2); STORE_BY_BITMASK(uint64_t, , 0x20000040, 5, 0, 4); STORE_BY_BITMASK(uint64_t, , 0x20000040, 8, 4, 8); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0xffff, 12, 12); STORE_BY_BITMASK(uint64_t, , 0x20000040, 0x8e1b, 24, 20); STORE_BY_BITMASK(uint64_t, , 0x20000040, 7, 44, 16); syz_compare(0x20000000, 2, 0x20000040, 8); break; case 11: syz_compare_int(2, 0x200, 6, 0, 0); break; case 12: syz_errno(0x40); break; case 13: memcpy((void*)0x20000080, "\x05\xa3\x79\x87\xe1\x5d\xd5\x00\xb7\x4c\x54\x3b\x25\x43\xb0\xa6\xd9\xec\x49\xa5\x28\x7e\xa4\x90\xc6\xb2\x9d\xd1\x09\x08\x7d\xfb\x26\x4b\x4f\x1f\x73\x04\x02\xe9\x4e\xd1\x01\xa3\x59\x71\xf1\xd9\xef\x2c", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0); break; case 15: syz_mmap(0x20ff4000, 0x6000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor155271664 -DGOOS_test=1 -DGOARCH_64_fork=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64 (0.01s) csource_test.go:72: seed=1568762212501689220 --- FAIL: TestGenerate/test/64/0 (0.64s) csource_test.go:110: opts: {Threaded:false Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 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 long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_one(void) { *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); syscall(SYS_test, 0, 0, 0, 0, 0, 0); *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); syscall(SYS_fallback, -1); memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); syz_compare_int(2, 0x80000001, 3, 0, 0); syz_errno(0xfe); memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); syz_exit(0x67e1); syz_mmap(0x20fff000, 0x1000); } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor555595669 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/16 (0.77s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor671454863 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/30 (0.79s) csource_test.go:110: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:2 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor206493593 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/29 (0.78s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:true} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { intptr_t res; switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; res = syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; res = syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); res = syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); res = syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; res = syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: res = syscall(SYS_test, 0, 0, 0, 0, 0, 0); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; res = syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; res = syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); res = syscall(SYS_foo, 0x20000380, 0); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); break; case 9: res = syscall(SYS_fallback, -1); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); res = syz_compare(0x20000000, 2, 0x20000040, 0xe); fprintf(stderr, "### call=10 errno=%u\n", res == -1 ? errno : 0); break; case 11: res = syz_compare_int(2, 0x80000001, 3, 0, 0); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: res = syz_errno(0xfe); fprintf(stderr, "### call=12 errno=%u\n", res == -1 ? errno : 0); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); res = syz_execute_func(0x20000080); fprintf(stderr, "### call=13 errno=%u\n", res == -1 ? errno : 0); break; case 14: res = syz_exit(0x67e1); fprintf(stderr, "### call=14 errno=%u\n", res == -1 ? errno : 0); break; case 15: res = syz_mmap(0x20fff000, 0x1000); fprintf(stderr, "### call=15 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor058639522 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/28 (0.74s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor162063396 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/24 (0.62s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor726496152 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/27 (0.91s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:true Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor282203955 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/26 (0.89s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor108404982 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/25 (0.87s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:true Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) { __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; NONFAILING(((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: NONFAILING(*(uint64_t*)0x20000000 = 7); NONFAILING(*(uint8_t*)0x20000008 = 8); NONFAILING(*(uint8_t*)0x20000009 = 4); NONFAILING(*(uint8_t*)0x2000000a = 2); NONFAILING(*(uint8_t*)0x2000000b = 1); syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: NONFAILING(*(uint8_t*)0x20000040 = 4); NONFAILING(*(uint8_t*)0x20000041 = 4); NONFAILING(*(uint8_t*)0x20000042 = 7); NONFAILING(*(uint8_t*)0x20000043 = 9); NONFAILING(*(uint8_t*)0x20000044 = 7); NONFAILING(*(uint8_t*)0x20000045 = 7); NONFAILING(*(uint8_t*)0x20000046 = 9); NONFAILING(*(uint8_t*)0x20000047 = 9); NONFAILING(*(uint8_t*)0x20000048 = 9); syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: NONFAILING(memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114)); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: NONFAILING(memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66)); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: NONFAILING(*(uint16_t*)0x20000240 = 1); NONFAILING(*(uint32_t*)0x20000244 = 0x18); NONFAILING(*(uint32_t*)0x20000248 = 1); NONFAILING(*(uint32_t*)0x2000024c = 3); NONFAILING(*(uint32_t*)0x20000250 = 5); NONFAILING(*(uint32_t*)0x20000254 = 6); NONFAILING(memcpy((void*)0x20000258, "\x8f", 1)); NONFAILING(memcpy((void*)0x20000259, "\x40\x9b\x03", 3)); NONFAILING(memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5)); NONFAILING(memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6)); NONFAILING(*(uint64_t*)0x20000268 = 0x20000180); NONFAILING(memcpy((void*)0x20000180, "\xaf", 1)); NONFAILING(memcpy((void*)0x20000181, "\x80\xae\x27", 3)); NONFAILING(memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5)); NONFAILING(memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6)); NONFAILING(*(uint64_t*)0x20000270 = 0x20000200); NONFAILING(*(uint64_t*)0x20000200 = 0x200001c0); NONFAILING(memcpy((void*)0x200001c0, "\xcd", 1)); NONFAILING(memcpy((void*)0x200001c1, "\x64\x05\x7b", 3)); NONFAILING(memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5)); NONFAILING(memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6)); NONFAILING(*(uint32_t*)0x20000278 = 2); NONFAILING(*(uint32_t*)0x20000280 = 4); NONFAILING(*(uint32_t*)0x200002c0 = 0x18); syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: NONFAILING(*(uint8_t*)0x20000300 = 0); NONFAILING(*(uint8_t*)0x20000301 = 0); NONFAILING(*(uint8_t*)0x20000302 = 0xda); NONFAILING(*(uint8_t*)0x20000303 = -1); syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: NONFAILING(*(uint16_t*)0x20000340 = 1); NONFAILING(memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16)); NONFAILING(*(uint16_t*)0x20000352 = 0x80); syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: NONFAILING(sprintf((char*)0x20000380, "%020llu", (long long)0)); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: NONFAILING(memcpy((void*)0x20000000, ",\000", 2)); NONFAILING(*(uint16_t*)0x20000040 = htobe16(2)); NONFAILING(*(uint16_t*)0x20000042 = htobe16(5)); NONFAILING(*(uint16_t*)0x20000044 = htobe16(0)); NONFAILING(*(uint16_t*)0x20000046 = htobe16(3)); NONFAILING(*(uint16_t*)0x20000048 = htobe16(0x100)); NONFAILING(*(uint16_t*)0x2000004a = htobe16(2)); NONFAILING(*(uint16_t*)0x2000004c = htobe16(2)); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: NONFAILING(memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50)); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor024562141 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/22 (0.60s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:false HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 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 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; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor157262986 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/23 (0.80s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor878320663 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/21 (0.88s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor561954401 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/19 (0.75s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor789736012 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/20 (1.02s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor687330107 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/18 (0.89s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor325853022 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/17 (0.86s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor534758976 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/15 (0.89s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor944407333 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/14 (0.88s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor785890674 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/8 (1.04s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:1 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor985270431 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/12 (0.60s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor791046004 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/13 (0.87s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor318832169 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/11 (0.57s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor984343619 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/10 (0.66s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox: Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); loop(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor811906246 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/9 (0.72s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:4 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor863037805 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/4 (0.63s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:false RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; for (call = 0; call < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor686521383 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/7 (0.70s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:10 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor923378664 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/6 (0.64s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor135266650 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/2 (0.49s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor498437873 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/5 (0.56s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor855925148 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/3 (0.48s) csource_test.go:110: opts: {Threaded:true Collide:true Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor657853515 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] --- FAIL: TestGenerate/test/64/1 (0.27s) csource_test.go:110: opts: {Threaded:true Collide:false Repeat:true RepeatTimes:0 Procs:0 Sandbox:none Fault:false FaultCall:0 FaultNth:0 Leak:false EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:true HandleSegv:false Repro:false Trace:false} program: test$length17(&(0x7f0000000000)={0x7, 0x8, 0x4, 0x2, 0x1}) test$length20(&(0x7f0000000040)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9}) test$length22(&(0x7f0000000080)="0a9dcefd3d69949a70fda0e75d0cbc8bea8d1e9393c6c216a1b25a4f7d4988139276224c203fbaaf097ffb0cafb9648ba7a890e068915ec740e6c424993423143c3a33baacff18ebb3bc5232aaec3fe196a6e396840f403324b3fd704389a3c04ce6c16a2e00471a37e989994ac7bdbd5725", 0x390) test$text_x86_real(&(0x7f0000000100)="0f009100000f796f3af2670f1c3d6f0000000f20d86635200000000f22d865660fec37baa100b00eee64f30f598f00000f01fc66b9f20900000f3264660fd58b0b00", 0x42) test$length30(&(0x7f0000000240)={{{0x1, 0x18, 0x1, 0x3, 0x5, 0x6}, {"8f", "409b03", "4fbba080ad", "55de5f7ca9d1"}, &(0x7f0000000180)={"af", "80ae27", "cbf9e430e3", "c48b209b8efa"}, &(0x7f0000000200)=&(0x7f00000001c0)={"cd", "64057b", "eb836b8e76", "89bf588c4d4b"}, 0x2}, 0x4}, 0x40, &(0x7f00000002c0)=0x18, 0x2) test$res0() mutate$array2(&(0x7f0000000300)=[{}, {0x200}, {0xda}, {0xff}]) test$array2(&(0x7f0000000340)={0x1, "e09c8675992336e96310fab1a91bf51d", 0x80}) foo$fmt4(&(0x7f0000000380)) fallback$1(0xffffffffffffffff) syz_compare(&(0x7f0000000000)=',\x00', 0x2, &(0x7f0000000040)=@arr16be=[0x2, 0x5, 0x100000000, 0x3, 0x100, 0x2, 0x2], 0xe) syz_compare_int$2(0x2, 0x80000001, 0x3) syz_errno(0xfe) syz_execute_func(&(0x7f0000000080)="86cb7fd01240c8e3858c815f04601f1e527c74ac8cdbbc78a445963175c45e20e3776175a4edcab47559a1250ea6ef469a06") syz_exit(0x67e1) syz_mmap(&(0x7f0000fff000/0x1000)=nil, 0x1000) csource_test.go:111: 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 static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; 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; } static long syz_mmap(volatile long a0, volatile long a1) { return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); } static long syz_errno(volatile long v) { errno = v; return v == 0 ? 0 : -1; } static long syz_exit(volatile long status) { _exit(status); return 0; } static long syz_compare(volatile long want, volatile long want_len, volatile long got, volatile long got_len) { if (want_len != got_len) { errno = EBADF; return -1; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; return -1; } return 0; } static long syz_compare_int(volatile long n, ...) { va_list args; va_start(args, n); long v0 = va_arg(args, long); long v1 = va_arg(args, long); long v2 = va_arg(args, long); long v3 = va_arg(args, long); va_end(args); if (n < 2 || n > 4) return errno = E2BIG, -1; if (n <= 2 && v2 != 0) return errno = EFAULT, -1; if (n <= 3 && v3 != 0) return errno = EFAULT, -1; if (v0 != v1) return errno = EINVAL, -1; if (n > 2 && v0 != v2) return errno = EINVAL, -1; if (n > 3 && v0 != v3) return errno = EINVAL, -1; return 0; } static void loop(); static int do_sandbox_none(void) { loop(); return 0; } static long syz_execute_func(volatile long text) { volatile long p[8] = {0}; (void)p; ((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 < 16; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } #ifndef SYS_fallback #define SYS_fallback 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate #define SYS_mutate 0 #endif #ifndef SYS_test #define SYS_test 0 #endif void execute_call(int call) { switch (call) { case 0: *(uint64_t*)0x20000000 = 7; *(uint8_t*)0x20000008 = 8; *(uint8_t*)0x20000009 = 4; *(uint8_t*)0x2000000a = 2; *(uint8_t*)0x2000000b = 1; syscall(SYS_test, 0x20000000, 0, 0, 0, 0, 0); break; case 1: *(uint8_t*)0x20000040 = 4; *(uint8_t*)0x20000041 = 4; *(uint8_t*)0x20000042 = 7; *(uint8_t*)0x20000043 = 9; *(uint8_t*)0x20000044 = 7; *(uint8_t*)0x20000045 = 7; *(uint8_t*)0x20000046 = 9; *(uint8_t*)0x20000047 = 9; *(uint8_t*)0x20000048 = 9; syscall(SYS_test, 0x20000040, 0, 0, 0, 0, 0); break; case 2: memcpy((void*)0x20000080, "\x0a\x9d\xce\xfd\x3d\x69\x94\x9a\x70\xfd\xa0\xe7\x5d\x0c\xbc\x8b\xea\x8d\x1e\x93\x93\xc6\xc2\x16\xa1\xb2\x5a\x4f\x7d\x49\x88\x13\x92\x76\x22\x4c\x20\x3f\xba\xaf\x09\x7f\xfb\x0c\xaf\xb9\x64\x8b\xa7\xa8\x90\xe0\x68\x91\x5e\xc7\x40\xe6\xc4\x24\x99\x34\x23\x14\x3c\x3a\x33\xba\xac\xff\x18\xeb\xb3\xbc\x52\x32\xaa\xec\x3f\xe1\x96\xa6\xe3\x96\x84\x0f\x40\x33\x24\xb3\xfd\x70\x43\x89\xa3\xc0\x4c\xe6\xc1\x6a\x2e\x00\x47\x1a\x37\xe9\x89\x99\x4a\xc7\xbd\xbd\x57\x25", 114); syscall(SYS_test, 0x20000080, 0x390, 0, 0, 0, 0); break; case 3: memcpy((void*)0x20000100, "\x0f\x00\x91\x00\x00\x0f\x79\x6f\x3a\xf2\x67\x0f\x1c\x3d\x6f\x00\x00\x00\x0f\x20\xd8\x66\x35\x20\x00\x00\x00\x0f\x22\xd8\x65\x66\x0f\xec\x37\xba\xa1\x00\xb0\x0e\xee\x64\xf3\x0f\x59\x8f\x00\x00\x0f\x01\xfc\x66\xb9\xf2\x09\x00\x00\x0f\x32\x64\x66\x0f\xd5\x8b\x0b\x00", 66); syscall(SYS_test, 0x20000100, 0x42, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000240 = 1; *(uint32_t*)0x20000244 = 0x18; *(uint32_t*)0x20000248 = 1; *(uint32_t*)0x2000024c = 3; *(uint32_t*)0x20000250 = 5; *(uint32_t*)0x20000254 = 6; memcpy((void*)0x20000258, "\x8f", 1); memcpy((void*)0x20000259, "\x40\x9b\x03", 3); memcpy((void*)0x2000025c, "\x4f\xbb\xa0\x80\xad", 5); memcpy((void*)0x20000261, "\x55\xde\x5f\x7c\xa9\xd1", 6); *(uint64_t*)0x20000268 = 0x20000180; memcpy((void*)0x20000180, "\xaf", 1); memcpy((void*)0x20000181, "\x80\xae\x27", 3); memcpy((void*)0x20000184, "\xcb\xf9\xe4\x30\xe3", 5); memcpy((void*)0x20000189, "\xc4\x8b\x20\x9b\x8e\xfa", 6); *(uint64_t*)0x20000270 = 0x20000200; *(uint64_t*)0x20000200 = 0x200001c0; memcpy((void*)0x200001c0, "\xcd", 1); memcpy((void*)0x200001c1, "\x64\x05\x7b", 3); memcpy((void*)0x200001c4, "\xeb\x83\x6b\x8e\x76", 5); memcpy((void*)0x200001c9, "\x89\xbf\x58\x8c\x4d\x4b", 6); *(uint32_t*)0x20000278 = 2; *(uint32_t*)0x20000280 = 4; *(uint32_t*)0x200002c0 = 0x18; syscall(SYS_test, 0x20000240, 0x40, 0x200002c0, 2, 0, 0); break; case 5: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 6: *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0xda; *(uint8_t*)0x20000303 = -1; syscall(SYS_mutate, 0x20000300, 0, 0, 0, 0, 0, 0, 0, 0); break; case 7: *(uint16_t*)0x20000340 = 1; memcpy((void*)0x20000342, "\xe0\x9c\x86\x75\x99\x23\x36\xe9\x63\x10\xfa\xb1\xa9\x1b\xf5\x1d", 16); *(uint16_t*)0x20000352 = 0x80; syscall(SYS_test, 0x20000340, 0, 0, 0, 0, 0); break; case 8: sprintf((char*)0x20000380, "%020llu", (long long)0); syscall(SYS_foo, 0x20000380, 0); break; case 9: syscall(SYS_fallback, -1); break; case 10: memcpy((void*)0x20000000, ",\000", 2); *(uint16_t*)0x20000040 = htobe16(2); *(uint16_t*)0x20000042 = htobe16(5); *(uint16_t*)0x20000044 = htobe16(0); *(uint16_t*)0x20000046 = htobe16(3); *(uint16_t*)0x20000048 = htobe16(0x100); *(uint16_t*)0x2000004a = htobe16(2); *(uint16_t*)0x2000004c = htobe16(2); syz_compare(0x20000000, 2, 0x20000040, 0xe); break; case 11: syz_compare_int(2, 0x80000001, 3, 0, 0); break; case 12: syz_errno(0xfe); break; case 13: memcpy((void*)0x20000080, "\x86\xcb\x7f\xd0\x12\x40\xc8\xe3\x85\x8c\x81\x5f\x04\x60\x1f\x1e\x52\x7c\x74\xac\x8c\xdb\xbc\x78\xa4\x45\x96\x31\x75\xc4\x5e\x20\xe3\x77\x61\x75\xa4\xed\xca\xb4\x75\x59\xa1\x25\x0e\xa6\xef\x46\x9a\x06", 50); syz_execute_func(0x20000080); break; case 14: syz_exit(0x67e1); break; case 15: syz_mmap(0x20fff000, 0x1000); break; } } int main(void) { syz_mmap(0x20000000, 0x1000000); use_temporary_dir(); do_sandbox_none(); return 0; } c++: error: unsupported option '-fsanitize=address' for target 'amd64-unknown-openbsd6.6' compiler invocation: c++ [-o /tmp/syz-executor673443118 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=8192 -m64 -fsanitize=address] FAIL FAIL github.com/google/syzkaller/pkg/csource 31.881s ok github.com/google/syzkaller/pkg/db (cached) ok github.com/google/syzkaller/pkg/email (cached) ? github.com/google/syzkaller/pkg/gce [no test files] ? github.com/google/syzkaller/pkg/gcs [no test files] ? github.com/google/syzkaller/pkg/hash [no test files] ok github.com/google/syzkaller/pkg/host 0.275s ? github.com/google/syzkaller/pkg/html [no test files] ok github.com/google/syzkaller/pkg/ifuzz (cached) ? github.com/google/syzkaller/pkg/ifuzz/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/generated [no test files] ok github.com/google/syzkaller/pkg/instance 3.246s ok github.com/google/syzkaller/pkg/ipc 22.013s ? github.com/google/syzkaller/pkg/ipc/ipcconfig [no test files] ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig 0.189s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 11.213s ok github.com/google/syzkaller/pkg/repro 2.041s ? github.com/google/syzkaller/pkg/rpctype [no test files] ok github.com/google/syzkaller/pkg/runtest 0.149s 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/vcs (cached) ok github.com/google/syzkaller/prog 69.631s ok github.com/google/syzkaller/prog/test 2.169s ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ok github.com/google/syzkaller/sys/linux 1.057s ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ok github.com/google/syzkaller/sys/openbsd 0.085s ? 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 2.800s ? github.com/google/syzkaller/syz-fuzzer [no test files] ok github.com/google/syzkaller/syz-hub 0.713s ok github.com/google/syzkaller/syz-hub/state (cached) ? github.com/google/syzkaller/syz-manager [no test files] ? github.com/google/syzkaller/tools/syz-benchcmp [no test files] ? github.com/google/syzkaller/tools/syz-bisect [no test files] ? github.com/google/syzkaller/tools/syz-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-env [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-imagegen [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-repro [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-stress [no test files] ? github.com/google/syzkaller/tools/syz-symbolize [no test files] ? github.com/google/syzkaller/tools/syz-testbuild [no test files] ? github.com/google/syzkaller/tools/syz-trace2syz [no test files] ok github.com/google/syzkaller/tools/syz-trace2syz/parser 0.151s ok github.com/google/syzkaller/tools/syz-trace2syz/proggen 1.410s ? 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 15.825s ? 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] ? github.com/google/syzkaller/vm/isolated [no test files] ? 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]