// https://syzkaller.appspot.com/bug?id=5735d842f7ea3ed9220aca64952ac4aba7ba741c // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #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 #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 void use_temporary_dir() { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5) { uint64_t target = a0; uint64_t mode = a1; uint64_t uid = a2; uint64_t gid = a3; uint64_t maxread = a4; uint64_t flags = a5; int fd = open("/dev/fuse", O_RDWR); if (fd == -1) return fd; char buf[1024]; sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd, (long)uid, (long)gid, (unsigned)mode & ~3u); if (maxread != 0) sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread); if (mode & 1) strcat(buf, ",default_permissions"); if (mode & 2) strcat(buf, ",allow_other"); syscall(SYS_mount, "", target, "fuse", flags, buf); return fd; } static void execute_one(); extern unsigned long long procid; void loop() { while (1) { execute_one(); } } 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 int collide; 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); if (collide && call % 2) break; 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}; unsigned long long procid; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[0] = res; break; case 1: *(uint32_t*)0x20000000 = 1; memcpy((void*)0x20000004, "\x73\x79\x7a\x5f\x74\x75\x6e\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint32_t*)0x20000014 = 0; syscall(__NR_setsockopt, r[0], 0, 0x48b, 0x20000000, 0x18); break; case 2: *(uint32_t*)0x20000100 = 1; memcpy((void*)0x20000104, "\x69\x72\x6c\x61\x6e\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint32_t*)0x20000114 = 0; syscall(__NR_setsockopt, r[0], 0, 0x48c, 0x20000100, 0x18); break; case 3: *(uint8_t*)0x200000c0 = 0xaa; *(uint8_t*)0x200000c1 = 0xaa; *(uint8_t*)0x200000c2 = 0xaa; *(uint8_t*)0x200000c3 = 0xaa; *(uint8_t*)0x200000c4 = 0xaa; *(uint8_t*)0x200000c5 = 0xaa; *(uint8_t*)0x200000c6 = 1; *(uint8_t*)0x200000c7 = 0x80; *(uint8_t*)0x200000c8 = 0xc2; *(uint8_t*)0x200000c9 = 0; *(uint8_t*)0x200000ca = 0; *(uint8_t*)0x200000cb = 0; *(uint16_t*)0x200000cc = htobe16(0x800); STORE_BY_BITMASK(uint8_t, 0x200000ce, 5, 0, 4); STORE_BY_BITMASK(uint8_t, 0x200000ce, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x200000cf, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x200000cf, 0, 2, 6); *(uint16_t*)0x200000d0 = htobe16(0x58); *(uint16_t*)0x200000d2 = htobe16(0); *(uint16_t*)0x200000d4 = htobe16(0); *(uint8_t*)0x200000d6 = 0; *(uint8_t*)0x200000d7 = 0x2f; *(uint16_t*)0x200000d8 = 0; *(uint8_t*)0x200000da = 0xac; *(uint8_t*)0x200000db = 0x14; *(uint8_t*)0x200000dc = -1; *(uint8_t*)0x200000dd = 0xaa; *(uint32_t*)0x200000de = htobe32(-1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 0, 0, 1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 0, 1, 1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 1, 2, 1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 0, 3, 1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 0xb, 4, 4); STORE_BY_BITMASK(uint16_t, 0x200000e2, -1, 8, 1); STORE_BY_BITMASK(uint16_t, 0x200000e2, 0, 9, 4); STORE_BY_BITMASK(uint16_t, 0x200000e2, 8, 13, 3); *(uint16_t*)0x200000e4 = htobe16(0x880b); *(uint16_t*)0x200000e6 = htobe16(0); *(uint16_t*)0x200000e8 = htobe16(0); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 0, 1); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 1, 1); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 2, 1); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 3, 1); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 4, 9); STORE_BY_BITMASK(uint16_t, 0x200000ea, 0, 13, 3); *(uint16_t*)0x200000ec = htobe16(0x800); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 0, 1); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 1, 1); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 2, 1); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 3, 1); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 4, 9); STORE_BY_BITMASK(uint16_t, 0x200000ee, 0, 13, 3); *(uint16_t*)0x200000f0 = htobe16(0x86dd); *(uint16_t*)0x200000f2 = 0; *(uint16_t*)0x200000f4 = htobe16(0x21); *(uint32_t*)0x200000f6 = htobe32(0); STORE_BY_BITMASK(uint8_t, 0x200000fa, 0, 0, 4); STORE_BY_BITMASK(uint8_t, 0x200000fa, 0, 4, 4); *(uint8_t*)0x200000fb = 0; STORE_BY_BITMASK(uint8_t, 0x200000fc, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x200000fc, 0, 2, 1); STORE_BY_BITMASK(uint8_t, 0x200000fc, 0, 3, 2); STORE_BY_BITMASK(uint8_t, 0x200000fc, 0, 5, 3); *(uint8_t*)0x200000fd = 0; *(uint32_t*)0x200000fe = 0; *(uint32_t*)0x20000102 = htobe32(0); *(uint16_t*)0x20000106 = 0; *(uint16_t*)0x20000108 = htobe16(0); *(uint32_t*)0x2000010a = htobe32(0); STORE_BY_BITMASK(uint8_t, 0x2000010e, 0, 0, 4); STORE_BY_BITMASK(uint8_t, 0x2000010e, 0, 4, 4); *(uint8_t*)0x2000010f = 0; STORE_BY_BITMASK(uint8_t, 0x20000110, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x20000110, 0, 2, 1); STORE_BY_BITMASK(uint8_t, 0x20000110, 0, 3, 2); STORE_BY_BITMASK(uint8_t, 0x20000110, 0, 5, 3); *(uint8_t*)0x20000111 = 0; *(uint32_t*)0x20000112 = 0; *(uint32_t*)0x20000116 = htobe32(0); *(uint16_t*)0x2000011a = htobe16(0); STORE_BY_BITMASK(uint8_t, 0x2000011c, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x2000011c, 0, 2, 5); STORE_BY_BITMASK(uint8_t, 0x2000011c, 0, 7, 1); STORE_BY_BITMASK(uint8_t, 0x2000011d, 0, 0, 1); STORE_BY_BITMASK(uint8_t, 0x2000011d, 0, 1, 2); STORE_BY_BITMASK(uint8_t, 0x2000011d, 0, 3, 1); STORE_BY_BITMASK(uint8_t, 0x2000011d, 0, 4, 1); *(uint16_t*)0x2000011e = 0; *(uint16_t*)0x20000120 = htobe16(0); *(uint32_t*)0x20000122 = htobe32(0); struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x200000ce, 20); *(uint16_t*)0x200000d8 = csum_inet_digest(&csum_1); break; case 4: memcpy((void*)0x20fd5ff8, "./file0", 8); syscall(__NR_mkdir, 0x20fd5ff8, 0); break; case 5: memcpy((void*)0x20000340, "./file0", 8); syz_fuse_mount(0x20000340, 0x4000, 0, 0, 0, 0); break; } } void execute_one() { execute(6); collide = 1; execute(6); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); char* cwd = get_current_dir_name(); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { if (chdir(cwd)) fail("failed to chdir"); use_temporary_dir(); loop(); } } } sleep(1000000); return 0; }