// 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 __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); } 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_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); } } #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_write #define __NR_write 4 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[1]; void loop() { memset(r, -1, sizeof(r)); syscall(__NR_mmap, 0x20000000, 0xfb1000, 0x3, 0x32, 0xffffffff, 0x0); memcpy((void*)0x2002a000, "/dev/sg#", 9); r[0] = syz_open_dev(0x2002a000, 0x0, 0x142); memcpy((void*)0x20016f2f, "\xae\x68\xb4\x1f\xaf\x67\x33\xc7\x68\xd9\xc7\x7d\x27\x4a\xb3" "\xd6\x7d\xba\xa0\x10\x44\xc0\xd2\x66\x18\x82\x9a\x68\xb0\x1b" "\x6e\x8d\xec\xa9\x3b\x15\x9d\x00\xb4\x42\x48\x6f\x36\x2b\x69" "\x6d\x4a\x1d\x3b\x24\x76\x08\x8d\xbc\xbf\xae\x2b\x59\x28\x39" "\x71\x77\x5e\x7b\xfe\x1a\x71\x83\xbd\xb4\x45\x2a\x9c\xc9\x51" "\x85\x13\x48\x92\x51\x16\x42\x2e\x2c\x04\xeb\x79\xb4", 88); syscall(__NR_write, r[0], 0x20016f2f, 0x58); *(uint32_t*)0x20006000 = 0x20001000; *(uint32_t*)0x20006004 = 0x5b; *(uint32_t*)0x20006008 = 0x2002cf2c; *(uint32_t*)0x2000600c = 0x0; *(uint32_t*)0x20006010 = 0x20013000; *(uint32_t*)0x20006014 = 0x0; *(uint32_t*)0x20006018 = 0x2002cf37; *(uint32_t*)0x2000601c = 0x0; *(uint32_t*)0x20006020 = 0x2001df6f; *(uint32_t*)0x20006024 = 0x0; *(uint32_t*)0x20006028 = 0x20001fd7; *(uint32_t*)0x2000602c = 0x0; *(uint32_t*)0x20006030 = 0x2002cf6b; *(uint32_t*)0x20006034 = 0x0; *(uint32_t*)0x20006038 = 0x20001f75; *(uint32_t*)0x2000603c = 0x0; syscall(__NR_readv, r[0], 0x20006000, 0x8); } int main() { use_temporary_dir(); loop(); return 0; }