// https://syzkaller.appspot.com/bug?id=4522c4fb3896c243a66d4bda935f828e80899c2c // autogenerated by syzkaller (http://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 #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t 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 { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); #define CLONE_NEWCGROUP 0x02000000 if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(CLONE_NEWCGROUP)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid < 0) fail("sandbox fork failed"); if (pid) return pid; sandbox_common(); if (unshare(CLONE_NEWNET)) { } loop(); doexit(1); } static void test(); void loop() { while (1) { test(); } } struct thread_t { int created, running, call; pthread_t th; }; 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 (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } uint64_t r[1] = {0xffffffffffffffff}; uint64_t procid; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20265ff7, "/dev/sg#", 9); res = syz_open_dev(0x20265ff7, 0, 2); if (res != -1) r[0] = res; break; case 1: syscall(__NR_read, r[0], 0x20000000, 0x9a); break; case 2: *(uint16_t*)0x200006c0 = 0; *(uint16_t*)0x200006c2 = htobe16(0x88f8); *(uint16_t*)0x200006c4 = htobe16(-1); *(uint16_t*)0x200006c6 = htobe16(0x108); *(uint8_t*)0x200006c8 = 0; *(uint8_t*)0x200006c9 = 5; *(uint32_t*)0x200006ca = htobe32(-1); *(uint8_t*)0x200006ce = 0; *(uint8_t*)0x200006cf = 0; *(uint8_t*)0x200006d0 = 0; *(uint8_t*)0x200006d1 = 0; *(uint8_t*)0x200006d2 = 0; *(uint8_t*)0x200006d3 = 0; *(uint16_t*)0x200006d4 = htobe16(-1); *(uint32_t*)0x200006d6 = htobe32(-1); *(uint8_t*)0x200006da = 0; *(uint8_t*)0x200006db = 0; *(uint8_t*)0x200006dc = 0; *(uint8_t*)0x200006dd = 0; *(uint8_t*)0x200006de = 0; *(uint8_t*)0x200006df = 0; *(uint16_t*)0x200006e0 = htobe16(3); memcpy((void*)0x200006e2, "\xc1\xd0\x9f\xb2\xab\xa8\xfd\x23\xcc\x72\x9b\xff\xb3\x7a\x4d\x96" "\x60\xb6\x9f\x0b\x7c\x64\x18\x77\x9e\x4d\x5c\x9b\x19\x23\x97\x03" "\x62\xbc\x23\xa7\xb3\x00\x92\x94\xd9\x50\x10\x5b\x03\x02\x11\xe3" "\xa6\x4c\x62\xdd\xe9\x83\xcf\xbb\xde\x09\xeb\xa8\x73\xca\x94\x51" "\x04\xdd\x3e\xab\x8a\x25\xb9\xd9\xcd\x6b\x6b\x2a\x2e\x51\x5b\x6c" "\x07\x45\x2a\xb2\x75\xcf\xfc\x24\x95\x37\xcb\x1c\x36\x9e\x91\x98" "\x5b\x2e\x1e\xe7\x02\x7d\xe3\x65\x9a\xa4\x0c\xba\x3c\x2a\x3e\xef" "\x5b\xc1\xee\x32\xdf\xde\x10\xd8\x1c\xb6\xdf\x65\xa4\x6e\x31\xcd" "\x75\xa1\x1b\x90\xd6\x82\xa5\xfd\xcb\x40\x26\x22\x64\xc2\x5b\x2a" "\xca\xb8\x54\x72\xe8\xea\x8b\x92\xa8\xa8\x41\xf2\x77\x05\x06\xcb" "\xd3\xa9\xff\xea\xa2\x22\xcd\x47\x03\xa1\x1e\x6b\x1b\xd9\xb6\xf1" "\x20\xde\x14\xc1\x63\x1c\x20\x05\x81\xc4\x9e\x59\x63\xd9\x64\x67" "\x8c\xba\x6c\x17\xce\xc0\x4d\x26\x3c\xc2\xf0\x69\x80\x7d\x2b\xc4" "\x90\x60\x45\x52\xa2\x01\xb1\xd2\x5e\x27\xc3\x66\x58\xd9\xfc\x8c" "\x5b\xfb\xa9\xca\x93\xbe\xbb\xe7\xe1\xa5", 234); syscall(__NR_write, r[0], 0x200006c0, 0x10c); break; } } void test() { execute(3); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { int pid = do_sandbox_none(); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } } } } sleep(1000000); return 0; }