// https://syzkaller.appspot.com/bug?id=ab136f1e51bcdf545b941b75c5d4215c6c2e3353 // 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 #include 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 setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 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 = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 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); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } loop(); exit(1); } #ifndef __NR_dup #define __NR_dup 41 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_write #define __NR_write 4 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void loop(void) { intptr_t res = 0; memcpy((void*)0x200000c0, "/dev/uinput\000", 12); res = syscall(__NR_openat, 0xffffff9c, 0x200000c0, 0x802, 0); if (res != -1) r[0] = res; syscall(__NR_ioctl, (intptr_t)r[0], 0x40045567, 0x2f); syscall(__NR_ioctl, (intptr_t)r[0], 0x40045564, 3); res = syscall(__NR_dup, (intptr_t)r[0]); if (res != -1) r[1] = res; memcpy((void*)0x20000500, "syz1\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000", 80); *(uint16_t*)0x20000550 = 0; *(uint16_t*)0x20000552 = 0; *(uint16_t*)0x20000554 = 0; *(uint16_t*)0x20000556 = 0; *(uint32_t*)0x20000558 = 0; *(uint32_t*)0x2000055c = 0; *(uint32_t*)0x20000560 = 0; *(uint32_t*)0x20000564 = 0; *(uint32_t*)0x20000568 = 0; *(uint32_t*)0x2000056c = 0; *(uint32_t*)0x20000570 = 0; *(uint32_t*)0x20000574 = 0; *(uint32_t*)0x20000578 = 0; *(uint32_t*)0x2000057c = 0; *(uint32_t*)0x20000580 = 0; *(uint32_t*)0x20000584 = 0; *(uint32_t*)0x20000588 = 0; *(uint32_t*)0x2000058c = 0; *(uint32_t*)0x20000590 = 0; *(uint32_t*)0x20000594 = 0; *(uint32_t*)0x20000598 = 0; *(uint32_t*)0x2000059c = 0; *(uint32_t*)0x200005a0 = 0; *(uint32_t*)0x200005a4 = 0; *(uint32_t*)0x200005a8 = 0; *(uint32_t*)0x200005ac = 0; *(uint32_t*)0x200005b0 = 0; *(uint32_t*)0x200005b4 = 0; *(uint32_t*)0x200005b8 = 0; *(uint32_t*)0x200005bc = 0; *(uint32_t*)0x200005c0 = 0; *(uint32_t*)0x200005c4 = 0; *(uint32_t*)0x200005c8 = 0; *(uint32_t*)0x200005cc = 0; *(uint32_t*)0x200005d0 = 0; *(uint32_t*)0x200005d4 = 0; *(uint32_t*)0x200005d8 = 0; *(uint32_t*)0x200005dc = 0; *(uint32_t*)0x200005e0 = 0; *(uint32_t*)0x200005e4 = 0; *(uint32_t*)0x200005e8 = 0; *(uint32_t*)0x200005ec = 0; *(uint32_t*)0x200005f0 = 0; *(uint32_t*)0x200005f4 = 0; *(uint32_t*)0x200005f8 = 0; *(uint32_t*)0x200005fc = 0; *(uint32_t*)0x20000600 = 0; *(uint32_t*)0x20000604 = 0; *(uint32_t*)0x20000608 = 0; *(uint32_t*)0x2000060c = 0; *(uint32_t*)0x20000610 = 0; *(uint32_t*)0x20000614 = 0; *(uint32_t*)0x20000618 = 0x4008001; *(uint32_t*)0x2000061c = 0; *(uint32_t*)0x20000620 = 0; *(uint32_t*)0x20000624 = 0; *(uint32_t*)0x20000628 = 0; *(uint32_t*)0x2000062c = 0; *(uint32_t*)0x20000630 = 0; *(uint32_t*)0x20000634 = 0; *(uint32_t*)0x20000638 = 0; *(uint32_t*)0x2000063c = 0; *(uint32_t*)0x20000640 = 0; *(uint32_t*)0x20000644 = 0; *(uint32_t*)0x20000648 = 0; *(uint32_t*)0x2000064c = 0; *(uint32_t*)0x20000650 = 0; *(uint32_t*)0x20000654 = 0; *(uint32_t*)0x20000658 = 0; *(uint32_t*)0x2000065c = 0; *(uint32_t*)0x20000660 = 0; *(uint32_t*)0x20000664 = 0; *(uint32_t*)0x20000668 = 0; *(uint32_t*)0x2000066c = 0; *(uint32_t*)0x20000670 = 0; *(uint32_t*)0x20000674 = 0; *(uint32_t*)0x20000678 = 0; *(uint32_t*)0x2000067c = 0; *(uint32_t*)0x20000680 = 0; *(uint32_t*)0x20000684 = 0; *(uint32_t*)0x20000688 = 0; *(uint32_t*)0x2000068c = 0; *(uint32_t*)0x20000690 = 0; *(uint32_t*)0x20000694 = 0; *(uint32_t*)0x20000698 = 0; *(uint32_t*)0x2000069c = 0; *(uint32_t*)0x200006a0 = 0; *(uint32_t*)0x200006a4 = 0; *(uint32_t*)0x200006a8 = 0; *(uint32_t*)0x200006ac = 0; *(uint32_t*)0x200006b0 = 0; *(uint32_t*)0x200006b4 = 0; *(uint32_t*)0x200006b8 = 0; *(uint32_t*)0x200006bc = 0; *(uint32_t*)0x200006c0 = 0; *(uint32_t*)0x200006c4 = 0; *(uint32_t*)0x200006c8 = 0; *(uint32_t*)0x200006cc = 0; *(uint32_t*)0x200006d0 = 0; *(uint32_t*)0x200006d4 = 0; *(uint32_t*)0x200006d8 = 0; *(uint32_t*)0x200006dc = 0; *(uint32_t*)0x200006e0 = 0; *(uint32_t*)0x200006e4 = 0; *(uint32_t*)0x200006e8 = 0; *(uint32_t*)0x200006ec = 0; *(uint32_t*)0x200006f0 = 0; *(uint32_t*)0x200006f4 = 0; *(uint32_t*)0x200006f8 = 0; *(uint32_t*)0x200006fc = 0; *(uint32_t*)0x20000700 = 0; *(uint32_t*)0x20000704 = 0; *(uint32_t*)0x20000708 = 0; *(uint32_t*)0x2000070c = 0; *(uint32_t*)0x20000710 = 0; *(uint32_t*)0x20000714 = 0; *(uint32_t*)0x20000718 = 0; *(uint32_t*)0x2000071c = 0; *(uint32_t*)0x20000720 = 0; *(uint32_t*)0x20000724 = 0; *(uint32_t*)0x20000728 = 0; *(uint32_t*)0x2000072c = 0; *(uint32_t*)0x20000730 = 0; *(uint32_t*)0x20000734 = 0; *(uint32_t*)0x20000738 = 0; *(uint32_t*)0x2000073c = 0; *(uint32_t*)0x20000740 = 0; *(uint32_t*)0x20000744 = 0; *(uint32_t*)0x20000748 = 0; *(uint32_t*)0x2000074c = 0; *(uint32_t*)0x20000750 = 0; *(uint32_t*)0x20000754 = 0; *(uint32_t*)0x20000758 = 0; *(uint32_t*)0x2000075c = 0; *(uint32_t*)0x20000760 = 0; *(uint32_t*)0x20000764 = 0; *(uint32_t*)0x20000768 = 0; *(uint32_t*)0x2000076c = 0; *(uint32_t*)0x20000770 = 0; *(uint32_t*)0x20000774 = 0; *(uint32_t*)0x20000778 = 0; *(uint32_t*)0x2000077c = 0; *(uint32_t*)0x20000780 = 0; *(uint32_t*)0x20000784 = 0; *(uint32_t*)0x20000788 = 0; *(uint32_t*)0x2000078c = 0; *(uint32_t*)0x20000790 = 0; *(uint32_t*)0x20000794 = 0; *(uint32_t*)0x20000798 = 0; *(uint32_t*)0x2000079c = 0; *(uint32_t*)0x200007a0 = 0; *(uint32_t*)0x200007a4 = 0; *(uint32_t*)0x200007a8 = 0; *(uint32_t*)0x200007ac = 0; *(uint32_t*)0x200007b0 = 0; *(uint32_t*)0x200007b4 = 0; *(uint32_t*)0x200007b8 = 0; *(uint32_t*)0x200007bc = 0; *(uint32_t*)0x200007c0 = 0; *(uint32_t*)0x200007c4 = 0; *(uint32_t*)0x200007c8 = 0; *(uint32_t*)0x200007cc = 0; *(uint32_t*)0x200007d0 = 0; *(uint32_t*)0x200007d4 = 0; *(uint32_t*)0x200007d8 = 0; *(uint32_t*)0x200007dc = 0; *(uint32_t*)0x200007e0 = 0; *(uint32_t*)0x200007e4 = 0; *(uint32_t*)0x200007e8 = 0; *(uint32_t*)0x200007ec = 0; *(uint32_t*)0x200007f0 = 0; *(uint32_t*)0x200007f4 = 0; *(uint32_t*)0x200007f8 = 0; *(uint32_t*)0x200007fc = 0; *(uint32_t*)0x20000800 = 0; *(uint32_t*)0x20000804 = 0; *(uint32_t*)0x20000808 = 0; *(uint32_t*)0x2000080c = 0; *(uint32_t*)0x20000810 = 0; *(uint32_t*)0x20000814 = 0; *(uint32_t*)0x20000818 = 0; *(uint32_t*)0x2000081c = 0; *(uint32_t*)0x20000820 = 0; *(uint32_t*)0x20000824 = 0; *(uint32_t*)0x20000828 = 0; *(uint32_t*)0x2000082c = 0; *(uint32_t*)0x20000830 = 0; *(uint32_t*)0x20000834 = 0; *(uint32_t*)0x20000838 = 0; *(uint32_t*)0x2000083c = 0; *(uint32_t*)0x20000840 = 0; *(uint32_t*)0x20000844 = 0; *(uint32_t*)0x20000848 = 0; *(uint32_t*)0x2000084c = 0; *(uint32_t*)0x20000850 = 0; *(uint32_t*)0x20000854 = 0; *(uint32_t*)0x20000858 = 0; *(uint32_t*)0x2000085c = 0; *(uint32_t*)0x20000860 = 0; *(uint32_t*)0x20000864 = 0; *(uint32_t*)0x20000868 = 0; *(uint32_t*)0x2000086c = 0; *(uint32_t*)0x20000870 = 0; *(uint32_t*)0x20000874 = 0; *(uint32_t*)0x20000878 = 0; *(uint32_t*)0x2000087c = 0; *(uint32_t*)0x20000880 = 0; *(uint32_t*)0x20000884 = 0; *(uint32_t*)0x20000888 = 0; *(uint32_t*)0x2000088c = 0; *(uint32_t*)0x20000890 = 0; *(uint32_t*)0x20000894 = 0; *(uint32_t*)0x20000898 = 0; *(uint32_t*)0x2000089c = 0; *(uint32_t*)0x200008a0 = 0; *(uint32_t*)0x200008a4 = 0; *(uint32_t*)0x200008a8 = 0; *(uint32_t*)0x200008ac = 0; *(uint32_t*)0x200008b0 = 0; *(uint32_t*)0x200008b4 = 0; *(uint32_t*)0x200008b8 = 0; *(uint32_t*)0x200008bc = 0; *(uint32_t*)0x200008c0 = 0; *(uint32_t*)0x200008c4 = 0; *(uint32_t*)0x200008c8 = 0; *(uint32_t*)0x200008cc = 0; *(uint32_t*)0x200008d0 = 0; *(uint32_t*)0x200008d4 = 0; *(uint32_t*)0x200008d8 = 0; *(uint32_t*)0x200008dc = 0; *(uint32_t*)0x200008e0 = 0; *(uint32_t*)0x200008e4 = 0; *(uint32_t*)0x200008e8 = 0; *(uint32_t*)0x200008ec = 0; *(uint32_t*)0x200008f0 = 0; *(uint32_t*)0x200008f4 = 0; *(uint32_t*)0x200008f8 = 0; *(uint32_t*)0x200008fc = 0; *(uint32_t*)0x20000900 = 0; *(uint32_t*)0x20000904 = 0; *(uint32_t*)0x20000908 = 0; *(uint32_t*)0x2000090c = 0; *(uint32_t*)0x20000910 = 0; *(uint32_t*)0x20000914 = 0; *(uint32_t*)0x20000918 = 0; *(uint32_t*)0x2000091c = 0; *(uint32_t*)0x20000920 = 0; *(uint32_t*)0x20000924 = 0; *(uint32_t*)0x20000928 = 0; *(uint32_t*)0x2000092c = 0; *(uint32_t*)0x20000930 = 0; *(uint32_t*)0x20000934 = 0; *(uint32_t*)0x20000938 = 0; *(uint32_t*)0x2000093c = 0; *(uint32_t*)0x20000940 = 0; *(uint32_t*)0x20000944 = 0; *(uint32_t*)0x20000948 = 0; *(uint32_t*)0x2000094c = 0; *(uint32_t*)0x20000950 = 0; *(uint32_t*)0x20000954 = 0; *(uint32_t*)0x20000958 = 0; syscall(__NR_write, (intptr_t)r[1], 0x20000500, 0x45c); syscall(__NR_ioctl, (intptr_t)r[1], 0x5501, 0); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); do_sandbox_none(); return 0; }