// https://syzkaller.appspot.com/bug?id=b7640dae2467568f05425b289a1f004faa2dc292 // 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 #ifndef __NR_execveat #define __NR_execveat 322 #endif #ifndef __NR_memfd_create #define __NR_memfd_create 319 #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 (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); 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; memcpy((void*)0x20000040, "/dev/vhost-net\000", 15); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x20000040ul, /*flags=*/2ul, /*mode=*/0ul); if (res != -1) r[0] = res; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xaf01, /*v=*/0ul); memcpy((void*)0x20000400, "\243\237n\264dR\004i5\002\254\316\341\210\235[@8\327\316\037 " "9I\177\025\035\223=\265\347\\\'L\346\322\216\274)" "JtTDq\201\317\201\272\3451\365 " "\310\020>\311\\\205\027L\277\317\221\337M\363\002^T*\000\002\271~" "B\237\254l\0353\006o\370\026H\252*" "\002\367\373\006\361\203\222\250\302\313\256\260\264\223\270\004\361" "\231\302yY+\331y\212\325b\350\"q\0330)" "\314m\254z\301\255d\2336a\363\335s\273\210\377\b\205\263s\000\016\274" "fvi\205\374.|\324h\354\202o\216\223\021\301\324\256\005\027=" "\331R\320\324\220\317\233\334\256V\210\224\237\343\357qi\355\250w\276" "\320\320-tBl\236+\323\355\316\237\203\206\371\022\026Ts\200\023]" "C\373`\302`\367\032\000\000\000\000\000\000\000k\256\313\032." "\302\217\321x4]PZ\236\325Y\360L\244\274\204\366\004L\3770\213\\*\371," "\266\r\227\355y\340\212\342\214k\306S\303g\271\032\370\217 " "\235\000u7\330\'\361E\244(Q\200Fy\265\344q\311\377 " "\330\235\255\021\370m\323\274\236\020D\177!\312\016v\025h$" "\001\335\345\316\370*\263\001\205\a\344qv&\234\254\232N~" "o\345\211\325\a\237\f\037\302e/" "\215\036\n\320_\275!^\2446\270j\300x\n\333\341\243\326\256;\r\222@" "\245I\210Z1F\360\032t\t\320\212\004m\006\363BL\377S\236Y\364\260U " "\370\3200\210y\353X\222\325\273\241h7\363\340\017\275\002\344%" "\371\261\207\212M\376G\262L\275\222-\315\037\364\341,\267G|" "\354\"\242\253\366\204\340\3171\232", 440); res = syscall(__NR_memfd_create, /*name=*/0x20000400ul, /*flags=*/0ul); if (res != -1) r[1] = res; memcpy((void*)0x20000140, "\x7f\x45\x4c\x46\x60\x00\x00\x2e\xd8\xe4\xf9\x77\x65\xce\x27\xb9\x03" "\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\xb7\x38\x00\x00\x00\x00\x00" "\x35\xf4\xc3\x84\x22\xa3\xbc\x82\x20\x00\x05\x00\x00\x00\x04\x02\x03" "\x00\xb3\x00\x00\x00\x00\x00\x2a\x00\x24\x00\xb3\xd7\xc5\x2e\xbf\x31" "\xa8\xd5\xc8\xc3\xc6\xcb\x00\x00\x00\x09\xe5\x00\xd5\xff\xff\xff\x05" "\xff\xff\xff\x03\x00\x4f\x9e\xf4", 93); syscall(__NR_write, /*fd=*/r[1], /*data=*/0x20000140ul, /*len=*/0xd8ul); memset((void*)0x20000000, 0, 1); syscall(__NR_execveat, /*dirfd=*/r[1], /*file=*/0x20000000ul, /*argv=*/0ul, /*envp=*/0ul, /*flags=*/0x1000ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); loop(); return 0; }