// https://syzkaller.appspot.com/bug?id=61035e9fe792a27fab0b660ab9ea53b69252c876 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_bpf #define __NR_bpf 321 #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 bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 73 65 63 00} (length 0x6) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000000, "./sec\000", 6); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000000ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 73 65 63 00} (length 0x6) // } // type: ptr[in, buffer] { // buffer: {73 65 63 75 72 69 74 79 66 73 00} (length 0xb) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000040, "./sec\000", 6); memcpy((void*)0x200000000080, "securityfs\000", 11); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000040ul, /*type=*/0x200000000080ul, /*flags=*/0ul, /*data=*/0ul); // openat arguments: [ // fd: fd_dir (resource) // file: nil // flags: open_flags = 0x0 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0ul, /*flags=*/0, /*mode=*/0); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 73 65 63 2f 69 6d 61 2f 62 69 6e 61 72 79 5f 72 75 6e // 74 69 6d 65 5f 6d 65 61 73 75 72 65 6d 65 6e 74 73 00} (length 0x26) // } // flags: open_flags = 0x0 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x200000001180, "./sec/ima/binary_runtime_measurements\000", 38); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000001180ul, /*flags=*/0, /*mode=*/0); if (res != -1) r[0] = res; // close arguments: [ // fd: fd (resource) // ] syscall(__NR_close, /*fd=*/r[0]); // openat$dm_control arguments: [ // fd: const = 0xffffffffffffff9c (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 = 0x883 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_dm_ctl memcpy((void*)0x2000000001c0, "/dev/mapper/control\000", 20); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x2000000001c0ul, /*flags=O_NONBLOCK|O_EXCL|O_RDWR|O_WRONLY*/ 0x883, /*mode=*/0); if (res != -1) r[1] = res; // 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[1], /*cmd=*/0xc138fd03, /*arg=*/0x200000000200ul); if (res != -1) r[2] = *(uint64_t*)0x200000000228; // bpf$PROG_LOAD arguments: [ // cmd: const = 0x5 (8 bytes) // arg: nil // size: len = 0x0 (8 bytes) // ] // returns fd_bpf_prog syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0ul, /*size=*/0ul); // 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 = 0x1b0 (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_dev: dm_id_by_dev { // dev: dm_dev_number (resource) // pad = 0x0 (264 bytes) // } // } // data: array[dm_target] { // union dm_target { // snapshot: dm_target_spec_t[dm_target_snapshot, // dm_snapshot_params] { // sector_start: const = 0x0 (8 bytes) // length: dm_lengths = 0x888 (8 bytes) // status: const = 0x0 (4 bytes) // next: bytesize = 0x0 (4 bytes) // target_type: buffer: {73 6e 61 70 73 68 6f 74 2d 6d 65 72 67 // 65 00 00} (length 0x10) params: dm_snapshot_params { // origin: 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) // } // } // sp0: const = 0x20 (1 bytes) // cow: 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) // } // } // sp1: const = 0x20 (1 bytes) // pers: buffer: {70} (length 0x1) // sp2: const = 0x20 (1 bytes) // chunk: buffer: {37} (length 0x1) // feat: buffer: {20 31 20 64 69 73 63 61 72 64 5f 7a 65 72 6f // 65 73 5f 63 6f 77} (length 0x15) // } // z: const = 0x0 (1 bytes) // } // } // } // } // } // ] *(uint32_t*)0x200000001640 = 4; *(uint32_t*)0x200000001644 = 0; *(uint32_t*)0x200000001648 = 0; *(uint32_t*)0x20000000164c = 0x1b0; *(uint32_t*)0x200000001650 = 0x138; *(uint32_t*)0x200000001654 = 1; *(uint32_t*)0x200000001658 = 0; *(uint32_t*)0x20000000165c = 0; *(uint32_t*)0x200000001660 = 0; *(uint32_t*)0x200000001664 = 0; *(uint64_t*)0x200000001668 = r[2]; *(uint64_t*)0x200000001778 = 0; *(uint64_t*)0x200000001780 = 0x888; *(uint32_t*)0x200000001788 = 0; *(uint32_t*)0x20000000178c = 0; memcpy((void*)0x200000001790, "snapshot-merge\000\000", 16); memcpy((void*)0x2000000017a0, "/dev/ram", 8); *(uint8_t*)0x2000000017a8 = 0x31; *(uint8_t*)0x2000000017a9 = 0x20; memcpy((void*)0x2000000017aa, "/dev/ram", 8); *(uint8_t*)0x2000000017b2 = 0x31; *(uint8_t*)0x2000000017b3 = 0x20; memset((void*)0x2000000017b4, 112, 1); *(uint8_t*)0x2000000017b5 = 0x20; memset((void*)0x2000000017b6, 55, 1); memcpy((void*)0x2000000017b7, " 1 discard_zeroes_cow", 21); *(uint8_t*)0x2000000017cc = 0; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd09, /*arg=*/0x200000001640ul); } 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; }