// https://syzkaller.appspot.com/bug?id=432bab1ba2256ad6b034ad222e0101c65d8b2163 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { unsigned long nb = a1; char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(nb % 10); nb /= 10; } return open(buf, a2 & ~O_CREAT, 0); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; install_segv_handler(); use_temporary_dir(); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // mode: open_mode = 0x0 (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000540, "./sys\000", 6)); syscall(__NR_mkdir, /*path=*/0x200000000540ul, /*mode=*/0ul); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // type: ptr[in, buffer] { // buffer: {73 79 73 66 73 00} (length 0x6) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] NONFAILING(memcpy((void*)0x200000000000, "./sys\000", 6)); NONFAILING(memcpy((void*)0x200000000040, "sysfs\000", 6)); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000000ul, /*type=*/0x200000000040ul, /*flags=*/0ul, /*data=*/0ul); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 2f 62 75 73 2f 70 63 69 2f 64 65 76 69 63 65 // 73 2f 30 30 30 30 3a 30 30 3a 30 31 2e 30 2f 72 65 6d 6f 76 65 00} // (length 0x2a) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000080, "./sys/bus/pci/devices/0000:00:01.0/remove\000", 42)); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; // syz_open_dev$dri arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 64 72 69 2f 63 61 72 64 23 00} (length 0xf) // } // id: intptr = 0xd21 (8 bytes) // flags: open_flags = 0x0 (8 bytes) // ] // returns fd_dri NONFAILING(memcpy((void*)0x2000000008c0, "/dev/dri/card#\000", 15)); res = -1; NONFAILING( res = syz_open_dev(/*dev=*/0x2000000008c0, /*id=*/0xd21, /*flags=*/0)); if (res != -1) r[1] = res; // ioctl$DRM_IOCTL_MODE_GETRESOURCES arguments: [ // fd: fd_dri (resource) // cmd: const = 0xc04064a0 (4 bytes) // arg: ptr[inout, drm_mode_card_res] { // drm_mode_card_res { // fbid: nil // crtcid: ptr[out, array[drm_crtc_id]] { // array[drm_crtc_id] { // drm_crtc_id (resource) // } // } // connid: nil // encid: nil // nfbid: len = 0x0 (4 bytes) // ncrtcid: len = 0x1 (4 bytes) // nconnid: len = 0x0 (4 bytes) // nencid: len = 0x0 (4 bytes) // maxw: const = 0x0 (4 bytes) // maxh: const = 0x0 (4 bytes) // minw: const = 0x0 (4 bytes) // minh: const = 0x0 (4 bytes) // } // } // ] NONFAILING(*(uint64_t*)0x2000000001c0 = 0); NONFAILING(*(uint64_t*)0x2000000001c8 = 0x2000000000c0); NONFAILING(*(uint64_t*)0x2000000001d0 = 0); NONFAILING(*(uint64_t*)0x2000000001d8 = 0); NONFAILING(*(uint32_t*)0x2000000001e0 = 0); NONFAILING(*(uint32_t*)0x2000000001e4 = 1); NONFAILING(*(uint32_t*)0x2000000001e8 = 0); NONFAILING(*(uint32_t*)0x2000000001ec = 0); NONFAILING(*(uint32_t*)0x2000000001f0 = 0); NONFAILING(*(uint32_t*)0x2000000001f4 = 0); NONFAILING(*(uint32_t*)0x2000000001f8 = 0); NONFAILING(*(uint32_t*)0x2000000001fc = 0); res = syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0xc04064a0, /*arg=*/0x2000000001c0ul); if (res != -1) NONFAILING(r[2] = *(uint32_t*)0x2000000000c0); // ioctl$DRM_IOCTL_MODE_GETCRTC arguments: [ // fd: fd_dri (resource) // cmd: const = 0xc06864a1 (4 bytes) // arg: ptr[inout, drm_mode_crtc$DRM_IOCTL_MODE_GETCRTC] { // drm_mode_crtc$DRM_IOCTL_MODE_GETCRTC { // set_connectors_ptr: nil // count_connectors: len = 0x0 (4 bytes) // crtc_id: drm_crtc_id (resource) // fb_id: drm_fb_id (resource) // x: int32 = 0x0 (4 bytes) // y: int32 = 0x0 (4 bytes) // gamma_size: int32 = 0x0 (4 bytes) // mode_valid: int32 = 0x0 (4 bytes) // mode: drm_mode_modeinfo { // clock: int32 = 0x0 (4 bytes) // hdisplay: int16 = 0x0 (2 bytes) // hsync_start: int16 = 0x0 (2 bytes) // hsync_end: int16 = 0x0 (2 bytes) // htotal: int16 = 0x0 (2 bytes) // hskew: int16 = 0x0 (2 bytes) // vdisplay: int16 = 0x0 (2 bytes) // vsync_start: int16 = 0x0 (2 bytes) // vsync_end: int16 = 0x0 (2 bytes) // vtotal: int16 = 0x0 (2 bytes) // vscan: int16 = 0x0 (2 bytes) // vrefresh: int32 = 0x0 (4 bytes) // flags: int32 = 0x0 (4 bytes) // type: int32 = 0x0 (4 bytes) // name: buffer: (DirOut) // } // } // } // ] NONFAILING(*(uint64_t*)0x200000001380 = 0); NONFAILING(*(uint32_t*)0x200000001388 = 0); NONFAILING(*(uint32_t*)0x20000000138c = r[2]); res = syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0xc06864a1, /*arg=*/0x200000001380ul); if (res != -1) NONFAILING(r[3] = *(uint32_t*)0x200000001390); // ioctl$DRM_IOCTL_MODE_GETFB2 arguments: [ // fd: fd_dri (resource) // cmd: const = 0xc06864ce (4 bytes) // arg: ptr[inout, drm_mode_fb_cmd2$DRM_IOCTL_MODE_GETFB2] { // drm_mode_fb_cmd2$DRM_IOCTL_MODE_GETFB2 { // fb_id: drm_fb_id (resource) // width: int32 = 0x8002 (4 bytes) // height: int32 = 0x7fff (4 bytes) // pixel_format: int32 = 0x0 (4 bytes) // flags: drm_mode_fb_flags = 0x0 (4 bytes) // handles: array[drm_gem_handle] { // drm_gem_handle (resource) // drm_gem_handle (resource) // drm_gem_handle (resource) // drm_gem_handle (resource) // } // pitches: array[int32] { // int32 = 0x2 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // } // offsets: array[int32] { // int32 = 0x0 (4 bytes) // int32 = 0x4 (4 bytes) // int32 = 0xfffffffe (4 bytes) // int32 = 0x5e8 (4 bytes) // } // pad = 0x0 (4 bytes) // modifier: array[int64] { // int64 = 0x0 (8 bytes) // int64 = 0x0 (8 bytes) // int64 = 0x0 (8 bytes) // int64 = 0x0 (8 bytes) // } // } // } // ] NONFAILING(*(uint32_t*)0x2000000012c0 = r[3]); NONFAILING(*(uint32_t*)0x2000000012c4 = 0x8002); NONFAILING(*(uint32_t*)0x2000000012c8 = 0x7fff); NONFAILING(*(uint32_t*)0x2000000012cc = 0); NONFAILING(*(uint32_t*)0x2000000012d0 = 0); NONFAILING(*(uint32_t*)0x2000000012e4 = 2); NONFAILING(*(uint32_t*)0x2000000012e8 = 0); NONFAILING(*(uint32_t*)0x2000000012ec = 0); NONFAILING(*(uint32_t*)0x2000000012f0 = 0); NONFAILING(*(uint32_t*)0x2000000012f4 = 0); NONFAILING(*(uint32_t*)0x2000000012f8 = 4); NONFAILING(*(uint32_t*)0x2000000012fc = 0xfffffffe); NONFAILING(*(uint32_t*)0x200000001300 = 0x5e8); NONFAILING(*(uint64_t*)0x200000001308 = 0); NONFAILING(*(uint64_t*)0x200000001310 = 0); NONFAILING(*(uint64_t*)0x200000001318 = 0); NONFAILING(*(uint64_t*)0x200000001320 = 0); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0xc06864ce, /*arg=*/0x2000000012c0ul); // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {31} (length 0x1) // } // count: len = 0x1 (8 bytes) // ] NONFAILING(memset((void*)0x2000000000c0, 49, 1)); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x2000000000c0ul, /*count=*/1ul); return 0; }