// https://syzkaller.appspot.com/bug?id=5a34035b13d7f4215357b46093ca6d5c45c93f93 // 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 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 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); } } 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // openat$sysfs arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // dir: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 6b 65 72 6e 65 6c 2f 61 64 64 72 65 73 73 5f // 62 69 74 73} (length 0x18) // } // flags: open_flags = 0x41180 (4 bytes) // mode: open_mode = 0x142 (2 bytes) // ] // returns fd memcpy((void*)0x200000000140, "/sys/kernel/address_bits", 24); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*dir=*/0x200000000140ul, /*flags=O_NOCTTY|O_NOATIME|O_EXCL|0x1000*/ 0x41180, /*mode=S_IWOTH|S_IXUSR|S_IRUSR*/ 0x142); if (res != -1) r[0] = res; // syz_open_dev$loop arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6c 6f 6f 70 23 00} (length 0xb) // } // id: intptr = 0x18bdb (8 bytes) // flags: open_flags = 0x325967a866143452 (8 bytes) // ] // returns fd_loop memcpy((void*)0x200000000100, "/dev/loop#\000", 11); res = -1; res = syz_open_dev( /*dev=*/0x200000000100, /*id=*/0x18bdb, /*flags=O_SYNC|O_NOATIME|O_CREAT|FASYNC|O_APPEND|0x325967a866000012*/ 0x325967a866143452); if (res != -1) r[1] = res; // ioctl$LOOP_CONFIGURE arguments: [ // fd: fd_loop (resource) // cmd: const = 0x4c0a (4 bytes) // arg: ptr[in, loop_config] { // loop_config { // fd: fd_loop (resource) // block_size: int32 = 0x0 (4 bytes) // info: loop_info64 { // lo_device: const = 0x2a00 (8 bytes) // lo_inode: const = 0x80010000 (8 bytes) // lo_rdevice: const = 0x0 (8 bytes) // lo_offset: int64 = 0x1 (8 bytes) // lo_sizelimit: int64 = 0x0 (8 bytes) // lo_number: const = 0x0 (4 bytes) // lo_enc_type: lo_encrypt_type = 0x0 (4 bytes) // lo_enc_key_size: int32 = 0x14 (4 bytes) // lo_flags: lo_flags = 0xd (4 bytes) // lo_file_name: buffer: {fe e8 a2 ab 78 fc 97 9f d1 e0 0d 96 07 20 // 00 00 1e a8 9d e2 b7 fb 00 00 e6 00 80 b8 78 5d 96 00 01 00 00 00 // 00 00 00 00 00 00 00 7e ff f1 00 00 40 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00} (length 0x40) lo_crypt_name: buffer: {28 09 e8 // db e1 08 59 89 48 22 4a d5 4a fa c1 1d 87 53 97 bd b2 2d 00 00 b4 // 20 a1 a9 3c 52 7d 3d 45 8d d4 99 28 61 ac 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x40) // lo_enc_key: buffer: {f4 bd 00 00 00 80 19 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x20) // lo_init: array[int64] { // int64 = 0x8 (8 bytes) // int64 = 0xffffffff9673e35d (8 bytes) // } // } // reserved: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00} (length 0x40) // } // } // ] *(uint32_t*)0x2000000002c0 = r[0]; *(uint32_t*)0x2000000002c4 = 0; *(uint64_t*)0x2000000002c8 = 0x2a00; *(uint64_t*)0x2000000002d0 = 0x80010000; *(uint64_t*)0x2000000002d8 = 0; *(uint64_t*)0x2000000002e0 = 1; *(uint64_t*)0x2000000002e8 = 0; *(uint32_t*)0x2000000002f0 = 0; *(uint32_t*)0x2000000002f4 = 0; *(uint32_t*)0x2000000002f8 = 0x14; *(uint32_t*)0x2000000002fc = 0xd; memcpy((void*)0x200000000300, "\xfe\xe8\xa2\xab\x78\xfc\x97\x9f\xd1\xe0\x0d\x96\x07\x20\x00\x00\x1e" "\xa8\x9d\xe2\xb7\xfb\x00\x00\xe6\x00\x80\xb8\x78\x5d\x96\x00\x01\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7e\xff\xf1\x00\x00\x40\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64); memcpy((void*)0x200000000340, "\x28\x09\xe8\xdb\xe1\x08\x59\x89\x48\x22\x4a\xd5\x4a\xfa\xc1\x1d\x87" "\x53\x97\xbd\xb2\x2d\x00\x00\xb4\x20\xa1\xa9\x3c\x52\x7d\x3d\x45\x8d" "\xd4\x99\x28\x61\xac\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64); memcpy((void*)0x200000000380, "\xf4\xbd\x00\x00\x00\x80\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32); *(uint64_t*)0x2000000003a0 = 8; *(uint64_t*)0x2000000003a8 = 0xffffffff9673e35d; memset((void*)0x2000000003b0, 0, 64); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4c0a, /*arg=*/0x2000000002c0ul); // ioctl$LOOP_CHANGE_FD arguments: [ // fd: fd_loop (resource) // cmd: const = 0x4c06 (4 bytes) // arg: fd (resource) // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4c06, /*arg=*/r[0]); } 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; }