// https://syzkaller.appspot.com/bug?id=07c86caf545892c7d50891a5e414b12243ee9c99 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include 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 test(); void loop() { while (1) { test(); } } long r[1]; void* thr(void* arg) { switch ((long)arg) { case 0: syscall(__NR_mmap, 0x20000000ul, 0xfff000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul); break; case 1: memcpy((void*)0x20000000, "/dev/sg#", 9); r[0] = syz_open_dev(0x20000000ul, 0x0ul, 0x2ul); break; case 2: *(uint64_t*)0x20001000 = (uint64_t)0x0; *(uint64_t*)0x20001008 = (uint64_t)0x0; *(uint16_t*)0x20001010 = (uint16_t)0x0; *(uint16_t*)0x20001012 = (uint16_t)0x0; *(uint32_t*)0x20001014 = (uint32_t)0x0; *(uint64_t*)0x20001018 = (uint64_t)0x0; *(uint64_t*)0x20001020 = (uint64_t)0x0; *(uint16_t*)0x20001028 = (uint16_t)0x0; *(uint16_t*)0x2000102a = (uint16_t)0x0; *(uint32_t*)0x2000102c = (uint32_t)0x2; *(uint64_t*)0x20001030 = (uint64_t)0x0; *(uint64_t*)0x20001038 = (uint64_t)0x0; *(uint16_t*)0x20001040 = (uint16_t)0x0; *(uint16_t*)0x20001042 = (uint16_t)0x0; *(uint32_t*)0x20001044 = (uint32_t)0x0; *(uint64_t*)0x20001048 = (uint64_t)0x0; *(uint64_t*)0x20001050 = (uint64_t)0x2710; *(uint16_t*)0x20001058 = (uint16_t)0x0; *(uint16_t*)0x2000105a = (uint16_t)0x0; *(uint32_t*)0x2000105c = (uint32_t)0x0; syscall(__NR_write, r[0], 0x20001000ul, 0x60ul); break; case 3: *(uint64_t*)0x20b16000 = (uint64_t)0x20dc8000; *(uint64_t*)0x20b16008 = (uint64_t)0xa5; syscall(__NR_readv, r[0], 0x20b16000ul, 0x1ul); break; } return 0; } void test() { long i; pthread_t th[8]; memset(r, -1, sizeof(r)); srand(getpid()); for (i = 0; i < 4; i++) { pthread_create(&th[i], 0, thr, (void*)i); usleep(rand() % 10000); } for (i = 0; i < 4; i++) { pthread_create(&th[4 + i], 0, thr, (void*)i); if (rand() % 2) usleep(rand() % 10000); } usleep(rand() % 100000); } int main() { loop(); return 0; }