// https://syzkaller.appspot.com/bug?id=91321d64651784af4a63f05a545a7737bde6913e // 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 void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 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 { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) 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) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 7; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[3] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // openat$dm_control arguments: [ // fd: const = 0xffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6d 61 70 70 65 72 2f 63 6f 6e 74 72 6f 6c // 00} (length 0x14) // } // flags: open_flags = 0x2 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_dm_ctl memcpy((void*)0x2000000001c0, "/dev/mapper/control\000", 20); res = syscall(__NR_openat, /*fd=*/0xffffff9cul, /*file=*/0x2000000001c0ul, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; break; case 1: // ioctl$DM_DEV_CREATE arguments: [ // fd: fd_dm_ctl (resource) // cmd: const = 0xc138fd03 (4 bytes) // arg: ptr[inout, dm_ioctl_t[dm_id_create, void, const[0, int32], // const[0, int32]]] { // dm_ioctl_t[dm_id_create, void, const[0, int32], const[0, int32]] { // version_major: const = 0x4 (4 bytes) // version_minor: const = 0x0 (4 bytes) // version_patch: const = 0x0 (4 bytes) // data_size: bytesize = 0x138 (4 bytes) // data_start: offsetof = 0x138 (4 bytes) // target_count: const = 0x0 (4 bytes) // open_count: const = 0x0 (4 bytes) // flags: dm_ioctl_flags = 0x0 (4 bytes) // event_nr: const = 0x0 (4 bytes) // padding: const = 0x0 (4 bytes) // id: dm_id_create { // dev: dm_dev_number (resource) // name: dm_dev_name { // prefix: buffer: {73 79 7a} (length 0x3) // proc: proc = 0x0 (1 bytes) // slot: buffer: {31 00} (length 0x2) // pad = 0x0 (122 bytes) // } // uuid: union dm_dev_uuid_opt { // none: const = 0x0 (1 bytes) // } // } // data: buffer: {} (length 0x0) // } // } // ] *(uint32_t*)0x200000000200 = 4; *(uint32_t*)0x200000000204 = 0; *(uint32_t*)0x200000000208 = 0; *(uint32_t*)0x20000000020c = 0x138; *(uint32_t*)0x200000000210 = 0x138; *(uint32_t*)0x200000000214 = 0; *(uint32_t*)0x200000000218 = 0; *(uint32_t*)0x20000000021c = 0; *(uint32_t*)0x200000000220 = 0; *(uint32_t*)0x200000000224 = 0; memcpy((void*)0x200000000230, "syz", 3); *(uint8_t*)0x200000000233 = 0x61; memcpy((void*)0x200000000234, "1\000", 2); *(uint8_t*)0x2000000002b0 = 0; res = syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd03, /*arg=*/0x200000000200ul); if (res != -1) r[1] = *(uint64_t*)0x200000000228; break; case 2: // ioctl$DM_TABLE_LOAD arguments: [ // fd: fd_dm_ctl (resource) // cmd: const = 0xc138fd09 (4 bytes) // arg: ptr[inout, dm_ioctl_t[dm_id_lookup, array[dm_target, 1], // len[data, int32], const[0, int32]]] { // dm_ioctl_t[dm_id_lookup, array[dm_target, 1], len[data, int32], // const[0, int32]] { // version_major: const = 0x4 (4 bytes) // version_minor: const = 0x0 (4 bytes) // version_patch: const = 0x0 (4 bytes) // data_size: bytesize = 0x1d8 (4 bytes) // data_start: offsetof = 0x138 (4 bytes) // target_count: len = 0x1 (4 bytes) // open_count: const = 0x0 (4 bytes) // flags: dm_ioctl_flags = 0x0 (4 bytes) // event_nr: const = 0x0 (4 bytes) // padding: const = 0x0 (4 bytes) // id: union dm_id_lookup { // by_name: dm_id_by_name { // dev: dm_dev_number (resource) // name: dm_dev_name { // prefix: buffer: {73 79 7a} (length 0x3) // proc: proc = 0x0 (1 bytes) // slot: buffer: {31 00} (length 0x2) // pad = 0x0 (122 bytes) // } // pad = 0x0 (136 bytes) // } // } // data: array[dm_target] { // union dm_target { // crypt: dm_target_spec_t[dm_target_crypt, dm_crypt_params] { // sector_start: const = 0x0 (8 bytes) // length: dm_lengths = 0x2000 (8 bytes) // status: const = 0x0 (4 bytes) // next: bytesize = 0xa0 (4 bytes) // target_type: buffer: {63 72 79 70 74 00 00 00 00 00 00 00 00 // 00 00 00} (length 0x10) params: dm_crypt_params { // cipher: buffer: {61 65 73 2d 78 74 73 2d 70 6c 61 69 6e 36 // 34} (length 0xf) sp0: const = 0x20 (1 bytes) key: union // dm_crypt_key { // fixed: buffer: {30 31 32 33 34 35 36 37 38 39 61 62 63 // 64 65 66 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 // 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 30 31 32 // 33 34 35 36 37 38 39 61 62 63 64 65 66} (length 0x40) // } // sp1: const = 0x20 (1 bytes) // iv_off: buffer: {30} (length 0x1) // sp2: const = 0x20 (1 bytes) // dev: dm_dev_off { // dev: union dm_dev { // ram: dm_dev_proc_t["/dev/ram", 2] { // prefix: buffer: {2f 64 65 76 2f 72 61 6d} (length // 0x8) id: proc = 0x1 (1 bytes) // } // } // sp: const = 0x20 (1 bytes) // off: buffer: {30} (length 0x1) // } // opts: buffer: {20 31 20 69 6e 74 65 67 72 69 74 79 3a 38 // 3a 6e 6f 6e 65} (length 0x13) // } // z: const = 0x0 (1 bytes) // } // } // } // } // } // ] *(uint32_t*)0x200000000840 = 4; *(uint32_t*)0x200000000844 = 0; *(uint32_t*)0x200000000848 = 0; *(uint32_t*)0x20000000084c = 0x1d8; *(uint32_t*)0x200000000850 = 0x138; *(uint32_t*)0x200000000854 = 1; *(uint32_t*)0x200000000858 = 0; *(uint32_t*)0x20000000085c = 0; *(uint32_t*)0x200000000860 = 0; *(uint32_t*)0x200000000864 = 0; memcpy((void*)0x200000000870, "syz", 3); *(uint8_t*)0x200000000873 = 0x61; memcpy((void*)0x200000000874, "1\000", 2); *(uint64_t*)0x200000000978 = 0; *(uint64_t*)0x200000000980 = 0x2000; *(uint32_t*)0x200000000988 = 0; *(uint32_t*)0x20000000098c = 0xa0; memcpy((void*)0x200000000990, "crypt\000\000\000\000\000\000\000\000\000\000\000", 16); memcpy((void*)0x2000000009a0, "aes-xts-plain64", 15); *(uint8_t*)0x2000000009af = 0x20; memcpy((void*)0x2000000009b0, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", 64); *(uint8_t*)0x2000000009f0 = 0x20; memset((void*)0x2000000009f1, 48, 1); *(uint8_t*)0x2000000009f2 = 0x20; memcpy((void*)0x2000000009f3, "/dev/ram", 8); *(uint8_t*)0x2000000009fb = 0x31; *(uint8_t*)0x2000000009fc = 0x20; memset((void*)0x2000000009fd, 48, 1); memcpy((void*)0x2000000009fe, " 1 integrity:8:none", 19); *(uint8_t*)0x200000000a11 = 0; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd09, /*arg=*/0x200000000840ul); break; case 3: // ioctl$DM_DEV_SUSPEND arguments: [ // fd: fd_dm_ctl (resource) // cmd: const = 0xc138fd06 (4 bytes) // arg: ptr[inout, dm_ioctl_t[dm_id_lookup, void, const[0, int32], // const[0, int32]]] { // dm_ioctl_t[dm_id_lookup, void, const[0, int32], const[0, int32]] { // version_major: const = 0x4 (4 bytes) // version_minor: const = 0x0 (4 bytes) // version_patch: const = 0x0 (4 bytes) // data_size: bytesize = 0x138 (4 bytes) // data_start: offsetof = 0x138 (4 bytes) // target_count: const = 0x0 (4 bytes) // open_count: const = 0x0 (4 bytes) // flags: dm_ioctl_flags = 0x0 (4 bytes) // event_nr: const = 0x0 (4 bytes) // padding: const = 0x0 (4 bytes) // id: union dm_id_lookup { // by_name: dm_id_by_name { // dev: dm_dev_number (resource) // name: dm_dev_name { // prefix: buffer: {73 79 7a} (length 0x3) // proc: proc = 0x0 (1 bytes) // slot: buffer: {31 00} (length 0x2) // pad = 0x0 (122 bytes) // } // pad = 0x0 (136 bytes) // } // } // data: buffer: {} (length 0x0) // } // } // ] *(uint32_t*)0x200000000500 = 4; *(uint32_t*)0x200000000504 = 0; *(uint32_t*)0x200000000508 = 0; *(uint32_t*)0x20000000050c = 0x138; *(uint32_t*)0x200000000510 = 0x138; *(uint32_t*)0x200000000514 = 0; *(uint32_t*)0x200000000518 = 0; *(uint32_t*)0x20000000051c = 0; *(uint32_t*)0x200000000520 = 0; *(uint32_t*)0x200000000524 = 0; memcpy((void*)0x200000000530, "syz", 3); *(uint8_t*)0x200000000533 = 0x61; memcpy((void*)0x200000000534, "1\000", 2); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd06, /*arg=*/0x200000000500ul); break; case 4: // mknodat$dm arguments: [ // dirfd: const = 0xffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2e 2f 64 6d 30 00} (length 0x6) // } // mode: const = 0x6180 (8 bytes) // dev: dm_dev_number (resource) // ] memcpy((void*)0x200000000640, "./dm0\000", 6); syscall(__NR_mknodat, /*dirfd=*/0xffffff9cul, /*file=*/0x200000000640ul, /*mode=*/0x6180ul, /*dev=*/r[1]); break; case 5: // openat$dm_dev arguments: [ // fd: const = 0xffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2e 2f 64 6d 30 00} (length 0x6) // } // flags: dm_open_flags = 0x2 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_dm memcpy((void*)0x200000000680, "./dm0\000", 6); res = syscall(__NR_openat, /*fd=*/0xffffff9cul, /*file=*/0x200000000680ul, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[2] = res; break; case 6: // pwrite64 arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {01 02 03 04 05 06 07 08} (length 0x8) // } // count: len = 0x8 (8 bytes) // pos: intptr = 0x0 (8 bytes) // ] memcpy((void*)0x2000000006c0, "\x01\x02\x03\x04\x05\x06\x07\x08", 8); syscall(__NR_pwrite64, /*fd=*/r[2], /*buf=*/0x2000000006c0ul, /*count=*/8ul, /*pos=*/0ul); break; } } 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; loop(); return 0; }