// https://syzkaller.appspot.com/bug?id=ffb3b968582af45169155ae8f13d408eef7673bd // 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 static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } 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 void reset_flags(const char* filename) { struct stat st; if (lstat(filename, &st)) exit(1); st.st_flags &= ~(SF_NOUNLINK | UF_NOUNLINK | SF_IMMUTABLE | UF_IMMUTABLE | SF_APPEND | UF_APPEND); if (lchflags(filename, st.st_flags)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) { if (errno == EPERM) { reset_flags(filename); reset_flags(dir); if (unlink(filename) == 0) continue; } exit(1); } } closedir(dp); while (rmdir(dir)) { if (errno == EPERM) { reset_flags(dir); if (rmdir(dir) == 0) break; } exit(1); } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); 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; } remove_dir(cwdbuf); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // openat$pass arguments: [ // fd: const = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 70 61 73 73 30 00} (length 0xb) // } // flags: open_flags = 0x2 (4 bytes) // mode: const = 0x0 (4 bytes) // ] // returns fd_pass memcpy((void*)0x10000040, "/dev/pass0\000", 11); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000040, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; // ioctl$CAMIOCOMMAND arguments: [ // fd: fd_pass (resource) // cmd: const = 0xc4e01a02 (4 bytes) // arg: ptr[inout, ccb] { // union ccb { // ccg: ccb_calc_geometry { // ccb_h: ccb_hdr { // pinfo: cam_pinfo { // priority: int32 = 0x5 (4 bytes) // generation: int32 = 0xde7 (4 bytes) // index: int32 = 0xe00 (4 bytes) // } // xpt_links: union camq_entry { // prev: const = 0x0 (4 bytes) // } // sim_links: union camq_entry { // next: const = 0x0 (4 bytes) // } // periph_links: union camq_entry { // prev: const = 0x0 (4 bytes) // } // retry_count: int16 = 0xcc6d (2 bytes) // alloc_flags: int16 = 0x81 (2 bytes) // cbfcnp: intptr = 0x7ffffffe (4 bytes) // func_code: ccb_hdr_func_codes = 0x18 (4 bytes) // status: int32 = 0x7fff (4 bytes) // path: const = 0x0 (4 bytes) // path_id: int32 = 0x2 (4 bytes) // target_id: int32 = 0x401 (4 bytes) // target_lun: int64 = 0x2 (8 bytes) // flags: int32 = 0x7 (4 bytes) // xflags: int32 = 0x222 (4 bytes) // periph_priv: union ccb_ppriv_area { // entries: array[ccb_priv_entry] { // union ccb_priv_entry { // field: intptr = 0x5 (4 bytes) // } // union ccb_priv_entry { // field: intptr = 0x100000001 (4 bytes) // } // } // } // sim_priv: union ccb_spriv_area { // entries: array[ccb_priv_entry] { // union ccb_priv_entry { // field: intptr = 0xff (4 bytes) // } // union ccb_priv_entry { // field: intptr = 0x91d (4 bytes) // } // } // } // qos: union ccb_qos_area { // etime: nil // } // timeout: int32 = 0x8 (4 bytes) // softtimeout: timeval { // sec: intptr = 0x2 (4 bytes) // usec: intptr = 0x6fc (4 bytes) // } // } // block_size: int32 = 0xffffff4f (4 bytes) // volume_size: int64 = 0x7 (8 bytes) // cylinders: int32 = 0x7a6 (4 bytes) // heads: int8 = 0x4 (1 bytes) // secs_per_track: int8 = 0x8 (1 bytes) // pad = 0x0 (2 bytes) // } // } // } // ] *(uint32_t*)0x10000080 = 5; *(uint32_t*)0x10000084 = 0xde7; *(uint32_t*)0x10000088 = 0xe00; *(uint32_t*)0x1000008c = 0; *(uint32_t*)0x10000090 = 0; *(uint32_t*)0x10000094 = 0; *(uint16_t*)0x10000098 = 0xcc6d; *(uint16_t*)0x1000009a = 0x81; *(uint32_t*)0x1000009c = 0x7ffffffe; *(uint32_t*)0x100000a0 = 0x18; *(uint32_t*)0x100000a4 = 0x7fff; *(uint32_t*)0x100000a8 = 0; *(uint32_t*)0x100000ac = 2; *(uint32_t*)0x100000b0 = 0x401; *(uint64_t*)0x100000b4 = 2; *(uint32_t*)0x100000bc = 7; *(uint32_t*)0x100000c0 = 0x222; *(uint32_t*)0x100000c4 = 5; *(uint32_t*)0x100000c8 = 1; *(uint32_t*)0x100000cc = 0xff; *(uint32_t*)0x100000d0 = 0x91d; *(uint32_t*)0x100000d4 = 0; *(uint32_t*)0x100000d8 = 8; *(uint32_t*)0x100000dc = 2; *(uint32_t*)0x100000e0 = 0x6fc; *(uint32_t*)0x100000e4 = 0xffffff4f; *(uint64_t*)0x100000e8 = 7; *(uint32_t*)0x100000f0 = 0x7a6; *(uint8_t*)0x100000f4 = 4; *(uint8_t*)0x100000f5 = 8; syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc4e01a02, /*arg=*/0x10000080); } int main(void) { syscall(SYS_mmap, /*addr=*/0x10000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x1012, /*fd=*/(intptr_t)-1, /*offset=*/0); const char* reason; (void)reason; use_temporary_dir(); loop(); return 0; }