// https://syzkaller.appspot.com/bug?id=e7d3a1ff85f2161580f6474aa29d5a34228a6429 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_ioctl #define __NR_ioctl 29 #endif #ifndef __NR_mkdirat #define __NR_mkdirat 34 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_mount #define __NR_mount 40 #endif #ifndef __NR_openat #define __NR_openat 56 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 211 #endif #ifndef __NR_write #define __NR_write 64 #endif static long syz_open_dev(volatile long a0, volatile long a1, volatile long 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 { unsigned long nb = a1; char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(nb % 10); nb /= 10; } return open(buf, a2 & ~O_CREAT, 0); } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 64 65 62 75 67 00} (length 0x8) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x20000000, "./debug\000", 8); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x20000000ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 64 65 62 75 67 00} (length 0x8) // } // type: ptr[in, buffer] { // buffer: {64 65 62 75 67 66 73 00} (length 0x8) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x20000080, "./debug\000", 8); memcpy((void*)0x200000c0, "debugfs\000", 8); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x20000080ul, /*type=*/0x200000c0ul, /*flags=*/0ul, /*data=*/0ul); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 64 65 62 75 67 2f 64 79 6e 61 6d 69 63 5f 64 65 62 75 // 67 2f 63 6f 6e 74 72 6f 6c 00} (length 0x1e) // } // flags: open_flags = 0x2 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x20000080, "./debug/dynamic_debug/control\000", 30); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000080ul, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {2b 70} (length 0x2) // } // count: len = 0x2 (8 bytes) // ] memcpy((void*)0x20000100, "+p", 2); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x20000100ul, /*count=*/2ul); // syz_open_dev$dvb_frontend arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 64 76 62 2f 61 64 61 70 74 65 72 23 2f 66 72 // 6f 6e 74 65 6e 64 23 00} (length 0x1c) // } // id: intptr = 0x0 (8 bytes) // flags: open_flags = 0x0 (8 bytes) // ] // returns fd_dvb_frontend memcpy((void*)0x20000080, "/dev/dvb/adapter#/frontend#\000", 28); res = -1; res = syz_open_dev(/*dev=*/0x20000080, /*id=*/0, /*flags=*/0); if (res != -1) r[1] = res; // sendmsg$can_bcm arguments: [ // fd: sock_can_bcm (resource) // msg: ptr[in, msghdr_can[can_bcm_msg]] { // msghdr_can[can_bcm_msg] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: nil // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x20000080 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x410 (8 bytes) // ] *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0; *(uint64_t*)0x20000190 = 0; *(uint64_t*)0x20000198 = 1; *(uint64_t*)0x200001a0 = 0; *(uint64_t*)0x200001a8 = 0; *(uint32_t*)0x200001b0 = 0x20000080; syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0x20000180ul, /*f=MSG_PROBE|0x400*/ 0x410ul); // ioctl$FE_GET_PROPERTY arguments: [ // fd: fd_dvb_frontend (resource) // cmd: const = 0x80106f53 (4 bytes) // arg: ptr[inout, dtv_properties] { // dtv_properties { // num: int32 = 0x2 (4 bytes) // pad = 0x0 (4 bytes) // props: ptr[in, array[dtv_property]] { // array[dtv_property] { // dtv_property { // cmd: dtv_property_cmd = 0x3c (4 bytes) // reserved: buffer: {00 00 00 00 00 00 00 00 00 00 00 00} // (length 0xc) u: union dtv_property_u { // data: int32 = 0xce (4 bytes) // } // result: int32 = 0x3 (4 bytes) // } // dtv_property { // cmd: dtv_property_cmd = 0x45 (4 bytes) // reserved: buffer: {00 00 00 00 00 00 00 00 00 00 00 00} // (length 0xc) u: union dtv_property_u { // data: int32 = 0x80000000 (4 bytes) // } // result: int32 = 0x1c (4 bytes) // } // } // } // } // } // ] *(uint32_t*)0x200000c0 = 2; *(uint64_t*)0x200000c8 = 0x20000180; *(uint32_t*)0x20000180 = 0x3c; memset((void*)0x20000184, 0, 12); *(uint32_t*)0x20000190 = 0xce; *(uint32_t*)0x200001c8 = 3; *(uint32_t*)0x200001cc = 0x45; memset((void*)0x200001d0, 0, 12); *(uint32_t*)0x200001dc = 0x80000000; *(uint32_t*)0x20000214 = 0x1c; syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x80106f53, /*arg=*/0x200000c0ul); return 0; }