? github.com/google/syzkaller/dashboard/dashapi [no test files] ok github.com/google/syzkaller/dashboard/app 0.273s ok github.com/google/syzkaller/executor 12.017s ok github.com/google/syzkaller/pkg/asset 0.739s ok github.com/google/syzkaller/pkg/ast 1.525s ok github.com/google/syzkaller/pkg/auth (cached) ? github.com/google/syzkaller/pkg/debugtracer [no test files] ? github.com/google/syzkaller/pkg/gcs [no test files] ? github.com/google/syzkaller/pkg/hash [no test files] ? github.com/google/syzkaller/pkg/html/pages [no test files] ? github.com/google/syzkaller/pkg/ifuzz/iset [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86 [no test files] ? github.com/google/syzkaller/pkg/ifuzz/powerpc/generated [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/gen [no test files] ? github.com/google/syzkaller/pkg/ifuzz/x86/generated [no test files] ? github.com/google/syzkaller/pkg/ipc/ipcconfig [no test files] ? github.com/google/syzkaller/pkg/kcidb [no test files] ? github.com/google/syzkaller/pkg/report/crash [no test files] ? github.com/google/syzkaller/pkg/rpctype [no test files] ? github.com/google/syzkaller/pkg/stats/syzbotstats [no test files] ? github.com/google/syzkaller/pkg/testutil [no test files] ? github.com/google/syzkaller/pkg/tools [no test files] ? github.com/google/syzkaller/sys [no test files] ? github.com/google/syzkaller/sys/akaros [no test files] ? github.com/google/syzkaller/sys/akaros/gen [no test files] ? github.com/google/syzkaller/sys/darwin [no test files] ? github.com/google/syzkaller/sys/darwin/gen [no test files] ? github.com/google/syzkaller/sys/freebsd [no test files] ? github.com/google/syzkaller/sys/freebsd/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia [no test files] ? github.com/google/syzkaller/sys/fuchsia/fidlgen [no test files] ? github.com/google/syzkaller/sys/fuchsia/gen [no test files] ? github.com/google/syzkaller/sys/fuchsia/layout [no test files] ? github.com/google/syzkaller/sys/linux/gen [no test files] ? github.com/google/syzkaller/sys/netbsd/gen [no test files] ? 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] ? github.com/google/syzkaller/syz-runner [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-build [no test files] ? github.com/google/syzkaller/tools/syz-check [no test files] ? github.com/google/syzkaller/tools/syz-cover [no test files] ? github.com/google/syzkaller/tools/syz-crush [no test files] ? github.com/google/syzkaller/tools/syz-db [no test files] ? github.com/google/syzkaller/tools/syz-execprog [no test files] ? github.com/google/syzkaller/tools/syz-expand [no test files] ? github.com/google/syzkaller/tools/syz-fillreports [no test files] ? github.com/google/syzkaller/tools/syz-fmt [no test files] ? github.com/google/syzkaller/tools/syz-hubtool [no test files] ? github.com/google/syzkaller/tools/syz-kcidb [no test files] ? github.com/google/syzkaller/tools/syz-lore [no test files] ? github.com/google/syzkaller/tools/syz-make [no test files] ? github.com/google/syzkaller/tools/syz-minconfig [no test files] ? github.com/google/syzkaller/tools/syz-mutate [no test files] ? github.com/google/syzkaller/tools/syz-prog2c [no test files] ? github.com/google/syzkaller/tools/syz-query-subsystems [no test files] ? github.com/google/syzkaller/tools/syz-reporter [no test files] ? github.com/google/syzkaller/tools/syz-showprio [no test files] ? github.com/google/syzkaller/tools/syz-runtest [no test files] ? github.com/google/syzkaller/tools/syz-repro [no test files] ? github.com/google/syzkaller/tools/syz-reprolist [no test files] ? github.com/google/syzkaller/tools/syz-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] ? 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] ? github.com/google/syzkaller/vm/adb [no test files] ? github.com/google/syzkaller/vm/bhyve [no test files] ? github.com/google/syzkaller/vm/cuttlefish [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/kvm [no test files] ? github.com/google/syzkaller/vm/odroid [no test files] ? github.com/google/syzkaller/vm/proxyapp/mocks [no test files] ? github.com/google/syzkaller/vm/proxyapp/proxyrpc [no test files] ? github.com/google/syzkaller/vm/qemu [no test files] ? github.com/google/syzkaller/vm/starnix [no test files] ? github.com/google/syzkaller/vm/vmm [no test files] ? github.com/google/syzkaller/vm/vmware [no test files] ok github.com/google/syzkaller/pkg/bisect 228.084s ok github.com/google/syzkaller/pkg/bisect/minimize (cached) ok github.com/google/syzkaller/pkg/build 11.322s ok github.com/google/syzkaller/pkg/compiler 23.845s ok github.com/google/syzkaller/pkg/config (cached) ok github.com/google/syzkaller/pkg/corpus 1.226s ok github.com/google/syzkaller/pkg/cover 0.381s ok github.com/google/syzkaller/pkg/cover/backend 1.703s --- FAIL: TestGenerate (55.69s) --- FAIL: TestGenerate/test/64 (0.01s) testutil.go:33: seed=1712063175961773625 testutil.go:33: seed=1712063175967823790 --- FAIL: TestGenerate/test/64/0 (1.45s) csource_test.go:150: opts: {Threaded:false Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } static void execute_one(void); static void loop(void) { execute_one(); } void execute_one(void) { *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); syscall(SYS_test, 0, 0, 0, 0, 0, 0); *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); syz_errno(/*v=*/1); memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); syz_exit(/*status=*/1); syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); syz_sleep_ms(/*ms=*/3); syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :164:2: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor498204232 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/2 (1.63s) csource_test.go:150: opts: {Threaded:true Repeat:false RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); 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: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :310:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor3729921540 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/10 (2.51s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:false HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); do_sandbox_none(); return 0; } :303:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor1576447446 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/5 (2.63s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:4 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif static 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; } :318:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor146061292 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/3 (2.78s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:10 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :316:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2565925912 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/1 (2.61s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :316:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2842851232 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/4 (3.31s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:1 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :316:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2626895069 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/9 (2.27s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:9223372036854775807 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :316:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor2516870548 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/13 (1.19s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:true LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { fprintf(stderr, "### start\n"); int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); res = syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); fprintf(stderr, "### call=0 errno=%u\n", res == -1 ? errno : 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; res = syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); fprintf(stderr, "### call=1 errno=%u\n", res == -1 ? errno : 0); break; case 2: res = syscall(SYS_csource7, /*flag=BIT_0*/1ul); fprintf(stderr, "### call=2 errno=%u\n", res == -1 ? errno : 0); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; res = syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); fprintf(stderr, "### call=3 errno=%u\n", res == -1 ? errno : 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; res = syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); fprintf(stderr, "### call=4 errno=%u\n", res == -1 ? errno : 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); res = syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); fprintf(stderr, "### call=5 errno=%u\n", res == -1 ? errno : 0); break; case 6: res = syscall(SYS_test, 0, 0, 0, 0, 0, 0); fprintf(stderr, "### call=6 errno=%u\n", res == -1 ? errno : 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; res = syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); fprintf(stderr, "### call=7 errno=%u\n", res == -1 ? errno : 0); break; case 8: *(uint8_t*)0x200002c0 = 7; res = syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); fprintf(stderr, "### call=8 errno=%u\n", res == -1 ? errno : 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; res = syscall(SYS_mutate_union, /*p=*/0x20000300ul); fprintf(stderr, "### call=9 errno=%u\n", res == -1 ? errno : 0); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); res = -1; errno = EFAULT; res = syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); fprintf(stderr, "### call=10 errno=%u\n", res == -1 ? errno : 0); break; case 11: res = -1; errno = EFAULT; res = syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); fprintf(stderr, "### call=11 errno=%u\n", res == -1 ? errno : 0); break; case 12: res = -1; errno = EFAULT; res = syz_errno(/*v=*/1); fprintf(stderr, "### call=12 errno=%u\n", res == -1 ? errno : 0); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); res = -1; errno = EFAULT; res = syz_execute_func(/*text=*/0x20000080); fprintf(stderr, "### call=13 errno=%u\n", res == -1 ? errno : 0); break; case 14: res = -1; errno = EFAULT; res = syz_exit(/*status=*/1); fprintf(stderr, "### call=14 errno=%u\n", res == -1 ? errno : 0); break; case 15: res = -1; errno = EFAULT; res = syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); fprintf(stderr, "### call=15 errno=%u\n", res == -1 ? errno : 0); break; case 16: res = -1; errno = EFAULT; res = syz_sleep_ms(/*ms=*/3); fprintf(stderr, "### call=16 errno=%u\n", res == -1 ? errno : 0); break; case 17: res = -1; errno = EFAULT; res = syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); fprintf(stderr, "### call=17 errno=%u\n", res == -1 ? errno : 0); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :318:9: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] res = syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor1767427623 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/8 (3.99s) csource_test.go:150: opts: {Threaded:true Repeat:true RepeatTimes:0 Procs:0 Slowdown:1 Sandbox:none SandboxArg:-9223372036854775808 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:false Repro:false Trace:false LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}} program: test$length3(&(0x7f0000000000)={0x0, 0x4, 0x2}) (fail_nth: 1) test$length17(&(0x7f0000000040)={0x20, 0x8, 0x4, 0x2, 0x1}) (async) csource7(0x1) (rerun: 4) test$align4(&(0x7f0000000080)={{0xe6}, 0x3}) test$length30(&(0x7f0000000180)={{{0x7, 0x18, 0x1, 0x3, 0x5, 0x6}, {"db", "7fef52", "ccf9b67f7b", "9373f2011213"}, &(0x7f00000000c0)={'$', "de0437", "ad45da7b68", "cff792ae5c04"}, &(0x7f0000000140)=&(0x7f0000000100)={'F', "996c14", "64b97b10d9", "638842fc12ec"}, 0x2}, 0x4}, 0x40, &(0x7f0000000200)=0x18, 0x2) foo$fmt1(&(0x7f0000000240)=0x1) test$missing_resource() mutate_array(0x2, 0x72c5d72, &(0x7f0000000280)=[0x0, 0x1, 0x1, 0x1, 0x0, 0x0]) test$length28(&(0x7f00000002c0)=@f1=0x7, 0x2a) mutate_union(&(0x7f0000000300)=@f2=0x22) syz_compare(&(0x7f0000000000)='@.\x00', 0x3, &(0x7f0000000040)=@bf11={0x8, {0x8, 0x1, 0x3f, 0x8, 0x8}}, 0x8) syz_compare_int$2(0x2, 0x3, 0x7) syz_errno(0x1) syz_execute_func(&(0x7f0000000080)="e7be8add0ef5a3980713642837016a86ffdab1643872152ef6a56b951e6c660c15f38d8b6030af52db9321555e8dea2f41f1") syz_exit(0x1) syz_mmap(&(0x7f0000ffe000/0x2000)=nil, 0x2000) syz_sleep_ms(0x3) syz_test_fuzzer1(0x6, 0x1, 0x3) csource_test.go:151: 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 #ifndef SYS_csource7 #define SYS_csource7 0 #endif #ifndef SYS_foo #define SYS_foo 0 #endif #ifndef SYS_mutate_array #define SYS_mutate_array 0 #endif #ifndef SYS_mutate_union #define SYS_mutate_union 0 #endif #ifndef SYS_test #define SYS_test 0 #endif 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 int inject_fault(int nth) { return 0; } static void setup_fault() { } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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_sleep_ms(volatile long ms) { sleep_ms(ms); 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; goto error; } if (memcmp((void*)want, (void*)got, want_len)) { errno = EINVAL; goto error; } return 0; error: return -1; } 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 void fake_crash(const char* name) { exit(1); exit(1); } static long syz_test_fuzzer1(volatile long a, volatile long b, volatile long c) { if (a == 1 && b == 1 && c == 1) fake_crash("first bug"); if (a == 1 && b == 2 && c == 3) fake_crash("second bug"); return 0; } static long syz_execute_func(volatile long text) { ((void (*)(void))(text))(); return 0; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 18; 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 (call == 1) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); static void loop(void) { execute_one(); } void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000000 = 0; *(uint16_t*)0x20000004 = 4; *(uint16_t*)0x20000006 = 2; inject_fault(1); syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); break; case 1: *(uint64_t*)0x20000040 = 0x20; *(uint8_t*)0x20000048 = 8; *(uint8_t*)0x20000049 = 4; *(uint8_t*)0x2000004a = 2; *(uint8_t*)0x2000004b = 1; syscall(SYS_test, /*a0=*/0x20000040ul, 0, 0, 0, 0, 0); break; case 2: syscall(SYS_csource7, /*flag=BIT_0*/1ul); { int i; for(i = 0; i < 4; i++) { syscall(SYS_csource7, /*flag=BIT_0*/1ul); } } break; case 3: *(uint8_t*)0x20000080 = 0xe6; *(uint16_t*)0x20000081 = 0; *(uint8_t*)0x20000084 = 3; syscall(SYS_test, /*a0=*/0x20000080ul, 0, 0, 0, 0, 0); break; case 4: *(uint16_t*)0x20000180 = 7; *(uint32_t*)0x20000184 = 0x18; *(uint32_t*)0x20000188 = 1; *(uint32_t*)0x2000018c = 3; *(uint32_t*)0x20000190 = 5; *(uint32_t*)0x20000194 = 6; memset((void*)0x20000198, 219, 1); memcpy((void*)0x20000199, "\x7f\xef\x52", 3); memcpy((void*)0x2000019c, "\xcc\xf9\xb6\x7f\x7b", 5); memcpy((void*)0x200001a1, "\x93\x73\xf2\x01\x12\x13", 6); *(uint64_t*)0x200001a8 = 0x200000c0; memset((void*)0x200000c0, 36, 1); memcpy((void*)0x200000c1, "\xde\x04\x37", 3); memcpy((void*)0x200000c4, "\xad\x45\xda\x7b\x68", 5); memcpy((void*)0x200000c9, "\xcf\xf7\x92\xae\x5c\x04", 6); *(uint64_t*)0x200001b0 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000100; memset((void*)0x20000100, 70, 1); memcpy((void*)0x20000101, "\x99\x6c\x14", 3); memcpy((void*)0x20000104, "\x64\xb9\x7b\x10\xd9", 5); memcpy((void*)0x20000109, "\x63\x88\x42\xfc\x12\xec", 6); *(uint32_t*)0x200001b8 = 2; *(uint32_t*)0x200001c0 = 4; *(uint32_t*)0x20000200 = 0x18; syscall(SYS_test, /*a0=*/0x20000180ul, /*a1=*/0x40, /*a2=*/0x20000200ul, /*a3=*/2, 0, 0); break; case 5: sprintf((char*)0x20000240, "0x%016llx", (long long)1); syscall(SYS_foo, /*a=*/0x20000240ul, 0, 0); break; case 6: syscall(SYS_test, 0, 0, 0, 0, 0, 0); break; case 7: *(uint32_t*)0x20000280 = 0; *(uint32_t*)0x20000284 = 1; *(uint32_t*)0x20000288 = 1; *(uint32_t*)0x2000028c = 1; *(uint32_t*)0x20000290 = 0; *(uint32_t*)0x20000294 = 0; syscall(SYS_mutate_array, /*i1=*/2ul, /*i2=*/0x72c5d72ul, /*vec=*/0x20000280ul); break; case 8: *(uint8_t*)0x200002c0 = 7; syscall(SYS_test, /*a0=*/0x200002c0ul, /*a1=*/0x2a, 0, 0, 0, 0); break; case 9: *(uint8_t*)0x20000300 = 0x22; syscall(SYS_mutate_union, /*p=*/0x20000300ul); break; case 10: memcpy((void*)0x20000000, "@.\000", 3); *(uint8_t*)0x20000040 = 8; *(uint8_t*)0x20000044 = 8; *(uint8_t*)0x20000045 = 1; *(uint8_t*)0x20000046 = 0x3f; STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 24, 4); STORE_BY_BITMASK(uint32_t, , 0x20000044, 8, 28, 4); syz_compare(/*want=*/0x20000000, /*want_len=*/3, /*got=*/0x20000040, /*got_len=*/8); break; case 11: syz_compare_int(/*n=*/2, /*v0=*/3, /*v1=*/7, 0, 0); break; case 12: syz_errno(/*v=*/1); break; case 13: memcpy((void*)0x20000080, "\xe7\xbe\x8a\xdd\x0e\xf5\xa3\x98\x07\x13\x64\x28\x37\x01\x6a\x86\xff\xda\xb1\x64\x38\x72\x15\x2e\xf6\xa5\x6b\x95\x1e\x6c\x66\x0c\x15\xf3\x8d\x8b\x60\x30\xaf\x52\xdb\x93\x21\x55\x5e\x8d\xea\x2f\x41\xf1", 50); syz_execute_func(/*text=*/0x20000080); break; case 14: syz_exit(/*status=*/1); break; case 15: syz_mmap(/*addr=*/0x20ffe000, /*len=*/0x2000); break; case 16: syz_sleep_ms(/*ms=*/3); break; case 17: syz_test_fuzzer1(/*a=*/6, /*b=*/1, /*c=*/3); break; } } int main(void) { syz_mmap(/*addr=*/0x20000000, /*len=*/0x1000000); setup_fault(); use_temporary_dir(); do_sandbox_none(); return 0; } :316:3: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] syscall(SYS_test, /*a0=*/0x20000000ul, 0, 0, 0, 0, 0); ^ 1 error generated. compiler invocation: c++ [-o /tmp/syz-executor3100264432 -DGOOS_test=1 -DGOARCH_64=1 -DHOSTGOOS_openbsd=1 -x c - -m64 -lutil -O2 -pthread -Wall -Werror -Wparentheses -Wunused-const-variable -Wframe-larger-than=16384 -Wno-array-bounds -Wno-unused-but-set-variable -Wno-unused-command-line-argument -no-pie -fno-exceptions] --- FAIL: TestGenerate/test/64/single_syz_compare (2.87s) csource_test.go:148: --- FAIL: TestGenerate/test/64/14 (2.58s) csource_test.go:148: --- FAIL: TestGenerate/test/64/6 (2.57s) csource_test.go:148: --- FAIL: TestGenerate/test/64/12 (2.89s) csource_test.go:148: --- FAIL: TestGenerate/test/64/7 (3.40s) csource_test.go:148: FAIL FAIL github.com/google/syzkaller/pkg/csource 80.624s ok github.com/google/syzkaller/pkg/db (cached) ok github.com/google/syzkaller/pkg/email (cached) ok github.com/google/syzkaller/pkg/email/lore (cached) ok github.com/google/syzkaller/pkg/fuzzer 179.118s ok github.com/google/syzkaller/pkg/gce 0.404s ok github.com/google/syzkaller/pkg/host 13.952s ok github.com/google/syzkaller/pkg/html (cached) ok github.com/google/syzkaller/pkg/ifuzz (cached) ok github.com/google/syzkaller/pkg/image (cached) ok github.com/google/syzkaller/pkg/instance 14.321s ok github.com/google/syzkaller/pkg/ipc 46.962s ok github.com/google/syzkaller/pkg/kconfig (cached) ok github.com/google/syzkaller/pkg/kd (cached) ok github.com/google/syzkaller/pkg/log (cached) ok github.com/google/syzkaller/pkg/mgrconfig 19.276s ok github.com/google/syzkaller/pkg/osutil (cached) ok github.com/google/syzkaller/pkg/report 28.624s ok github.com/google/syzkaller/pkg/repro 21.704s ok github.com/google/syzkaller/pkg/runtest 144.175s ok github.com/google/syzkaller/pkg/serializer (cached) ok github.com/google/syzkaller/pkg/signal (cached) ok github.com/google/syzkaller/pkg/stats (cached) ok github.com/google/syzkaller/pkg/subsystem (cached) ok github.com/google/syzkaller/pkg/subsystem/linux (cached) ok github.com/google/syzkaller/pkg/subsystem/lists (cached) ok github.com/google/syzkaller/pkg/symbolizer (cached) ok github.com/google/syzkaller/pkg/tool (cached) ok github.com/google/syzkaller/pkg/vcs (cached) ok github.com/google/syzkaller/prog (cached) ok github.com/google/syzkaller/prog/test (cached) ok github.com/google/syzkaller/sys/linux (cached) ok github.com/google/syzkaller/sys/netbsd (cached) ok github.com/google/syzkaller/sys/openbsd (cached) ok github.com/google/syzkaller/syz-ci 85.546s ok github.com/google/syzkaller/syz-fuzzer 1.511s ok github.com/google/syzkaller/syz-hub 1.145s ok github.com/google/syzkaller/syz-hub/state 1.551s ok github.com/google/syzkaller/syz-manager 35.370s ok github.com/google/syzkaller/syz-verifier 19.886s ok github.com/google/syzkaller/tools/syz-kconf (cached) ok github.com/google/syzkaller/tools/syz-linter (cached) ok github.com/google/syzkaller/tools/syz-testbed 11.803s ok github.com/google/syzkaller/tools/syz-trace2syz/parser (cached) ok github.com/google/syzkaller/tools/syz-trace2syz/proggen (cached) ok github.com/google/syzkaller/vm 27.208s ok github.com/google/syzkaller/vm/isolated 9.434s ok github.com/google/syzkaller/vm/proxyapp 17.081s ok github.com/google/syzkaller/vm/vmimpl 15.824s FAIL