// https://syzkaller.appspot.com/bug?id=3c1f47967b7cbd399d3ba3e65f297a29aa1c5f92 // 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 #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 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); } #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) \ (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) #define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ if ((bf_off) == 0 && (bf_len) == 0) { \ *(type*)(addr) = (type)(val); \ } else { \ type new_val = *(type*)(addr); \ new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ *(type*)(addr) = new_val; \ } struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i; for (i = 0; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += (uint16_t)data[length - 1]; while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } static uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } 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 unshare(CLONE_NEWNS); unshare(CLONE_NEWIPC); unshare(CLONE_NEWCGROUP); unshare(CLONE_NEWNET); unshare(CLONE_NEWUTS); unshare(CLONE_SYSVSEM); } static int do_sandbox_none(int executor_pid, bool enable_tun) { unshare(CLONE_NEWPID); int pid = fork(); if (pid < 0) fail("sandbox fork failed"); if (pid) return pid; sandbox_common(); loop(); doexit(1); } static void test(); void loop() { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) fail("loop fork failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); test(); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) break; usleep(1000); if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } } } long r[1]; void test() { memset(r, -1, sizeof(r)); syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); memcpy((void*)0x208c8000, "/dev/sg#", 9); r[0] = syz_open_dev(0x208c8000, 0, 0x8002); *(uint8_t*)0x20ace000 = 2; *(uint8_t*)0x20ace001 = 0x83; *(uint16_t*)0x20ace002 = 0xfcc; *(uint16_t*)0x20ace004 = 1; *(uint16_t*)0x20ace006 = 4; *(uint16_t*)0x20ace008 = -1; STORE_BY_BITMASK(uint8_t, 0x20ace00a, 0x1e, 0, 4); STORE_BY_BITMASK(uint8_t, 0x20ace00a, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x20ace00b, 1, 0, 2); STORE_BY_BITMASK(uint8_t, 0x20ace00b, 7, 2, 6); *(uint16_t*)0x20ace00c = htobe16(0x88); *(uint16_t*)0x20ace00e = htobe16(0x67); *(uint16_t*)0x20ace010 = htobe16(0); *(uint8_t*)0x20ace012 = 0x86; *(uint8_t*)0x20ace013 = 0x6e; *(uint16_t*)0x20ace014 = 0; *(uint8_t*)0x20ace016 = 0xac; *(uint8_t*)0x20ace017 = 0x14; *(uint8_t*)0x20ace018 = 0; *(uint8_t*)0x20ace019 = 0xbb; *(uint32_t*)0x20ace01a = htobe32(0); *(uint8_t*)0x20ace01e = 0x89; *(uint8_t*)0x20ace01f = 0x2b; *(uint8_t*)0x20ace020 = 0x1f; *(uint32_t*)0x20ace021 = htobe32(0xe0000001); *(uint32_t*)0x20ace025 = htobe32(0xe0000002); *(uint32_t*)0x20ace029 = htobe32(5); *(uint32_t*)0x20ace02d = htobe32(0xe0000002); *(uint8_t*)0x20ace031 = 0xac; *(uint8_t*)0x20ace032 = 0x14; *(uint8_t*)0x20ace033 = 0; *(uint8_t*)0x20ace034 = 0xbb; *(uint32_t*)0x20ace035 = htobe32(0); *(uint32_t*)0x20ace039 = htobe32(0x7f000001); *(uint32_t*)0x20ace03d = htobe32(0x7ff); *(uint32_t*)0x20ace041 = htobe32(0); *(uint32_t*)0x20ace045 = htobe32(0xe0000002); *(uint8_t*)0x20ace049 = 0x86; *(uint8_t*)0x20ace04a = 0x10; *(uint32_t*)0x20ace04b = htobe32(0x1f); *(uint8_t*)0x20ace04f = 0; *(uint8_t*)0x20ace050 = 2; *(uint8_t*)0x20ace051 = 5; *(uint8_t*)0x20ace052 = 2; *(uint8_t*)0x20ace053 = 0; *(uint8_t*)0x20ace054 = 2; *(uint8_t*)0x20ace055 = 0; *(uint8_t*)0x20ace056 = 2; *(uint8_t*)0x20ace057 = 7; *(uint8_t*)0x20ace058 = 2; *(uint8_t*)0x20ace059 = 7; *(uint8_t*)0x20ace05a = 0x27; *(uint8_t*)0x20ace05b = 5; *(uint8_t*)0x20ace05c = 0xac; *(uint8_t*)0x20ace05d = 0x14; *(uint8_t*)0x20ace05e = 0; *(uint8_t*)0x20ace05f = 0xbb; *(uint32_t*)0x20ace060 = htobe32(0x7f000001); *(uint32_t*)0x20ace064 = htobe32(0); *(uint8_t*)0x20ace068 = 0xac; *(uint8_t*)0x20ace069 = 0x14; *(uint8_t*)0x20ace06a = 0; *(uint8_t*)0x20ace06b = 0xbb; *(uint32_t*)0x20ace06c = htobe32(0x7f000001); *(uint32_t*)0x20ace070 = htobe32(-1); *(uint32_t*)0x20ace074 = htobe32(0x7f000001); *(uint32_t*)0x20ace078 = htobe32(9); *(uint32_t*)0x20ace07c = htobe32(0x3f); *(uint16_t*)0x20ace082 = htobe16(0x4e23); *(uint16_t*)0x20ace084 = htobe16(0x4e21); *(uint8_t*)0x20ace086 = 4; STORE_BY_BITMASK(uint8_t, 0x20ace087, 1, 0, 4); STORE_BY_BITMASK(uint8_t, 0x20ace087, 0x52, 4, 4); *(uint16_t*)0x20ace088 = 0; STORE_BY_BITMASK(uint8_t, 0x20ace08a, 0, 0, 1); STORE_BY_BITMASK(uint8_t, 0x20ace08a, 0, 1, 4); STORE_BY_BITMASK(uint8_t, 0x20ace08a, 0xce, 5, 3); memcpy((void*)0x20ace08b, "\x77\xfd\x93", 3); *(uint8_t*)0x20ace08e = 6; memcpy((void*)0x20ace08f, "\x41\x9e\x5f", 3); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x20ace016, 4); csum_inet_update(&csum_1, (const uint8_t*)0x20ace01a, 4); uint16_t csum_1_chunk_2 = 0x2100; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 2); uint16_t csum_1_chunk_3 = 0x1000; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 2); csum_inet_update(&csum_1, (const uint8_t*)0x20ace082, 16); *(uint16_t*)0x20ace088 = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x20ace00a, 120); *(uint16_t*)0x20ace014 = csum_inet_digest(&csum_2); syscall(__NR_write, r[0], 0x20ace000, 0x92); *(uint64_t*)0x204f2000 = 0x207bc000; *(uint64_t*)0x204f2008 = 0; *(uint64_t*)0x204f2010 = 0x20180000; *(uint64_t*)0x204f2018 = 0; *(uint64_t*)0x204f2020 = 0x20035f1b; *(uint64_t*)0x204f2028 = 0; *(uint64_t*)0x204f2030 = 0x20523f39; *(uint64_t*)0x204f2038 = 0; *(uint64_t*)0x204f2040 = 0x203daf4b; *(uint64_t*)0x204f2048 = 0; *(uint64_t*)0x204f2050 = 0x20fa5000; *(uint64_t*)0x204f2058 = 0; *(uint64_t*)0x204f2060 = 0x20729000; *(uint64_t*)0x204f2068 = 0; *(uint64_t*)0x204f2070 = 0x2041fff8; *(uint64_t*)0x204f2078 = 0; *(uint64_t*)0x204f2080 = 0x20982000; *(uint64_t*)0x204f2088 = 0; *(uint64_t*)0x204f2090 = 0x20142000; *(uint64_t*)0x204f2098 = 1; syscall(__NR_readv, r[0], 0x204f2000, 0xa); } int main() { for (;;) { int pid = do_sandbox_none(0, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } } }