// https://syzkaller.appspot.com/bug?id=cb4d28adf92d32c30e37571d9887c752e87c0a1e // 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_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 74 72 61 63 69 6e 67 00} (length 0xa) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x20000000, "./tracing\000", 10); 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 74 72 61 63 69 6e 67 00} (length 0xa) // } // type: ptr[in, buffer] { // buffer: {74 72 61 63 65 66 73 00} (length 0x8) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x20000080, "./tracing\000", 10); memcpy((void*)0x200000c0, "tracefs\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 74 72 61 63 69 6e 67 2f 65 76 65 6e 74 73 2f 65 6e 61 // 62 6c 65 00} (length 0x18) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x20000100, "./tracing/events/enable\000", 24); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000100ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {31} (length 0x1) // } // count: len = 0x1 (8 bytes) // ] memset((void*)0x20000200, 49, 1); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x20000200ul, /*count=*/1ul); // syz_open_dev$I2C arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 69 32 63 2d 23 00} (length 0xb) // } // id: intptr = 0x0 (8 bytes) // flags: open_flags = 0x0 (8 bytes) // ] // returns fd_i2c memcpy((void*)0x20000000, "/dev/i2c-#\000", 11); res = -1; res = syz_open_dev(/*dev=*/0x20000000, /*id=*/0, /*flags=*/0); if (res != -1) r[1] = res; // ioctl$I2C_SMBUS arguments: [ // fd: fd_i2c (resource) // cmd: const = 0x720 (4 bytes) // arg: ptr[in, i2c_smbus_ioctl_data] { // i2c_smbus_ioctl_data { // read_write: int8 = 0x0 (1 bytes) // command: int8 = 0x0 (1 bytes) // pad = 0x0 (2 bytes) // size: int32 = 0x5 (4 bytes) // data: ptr[in, i2c_smbus_data] { // i2c_smbus_data { // size: int8 = 0x22 (1 bytes) // block: buffer: {81 00 46 9f d3 29 2a a0 32 4a 1c 00 00 00 00 b7 // 6b 8a fe 83 c9 10 c4 ea e1 a8 98 11 02 df 1f 00 00} (length // 0x21) // } // } // } // } // ] *(uint8_t*)0x20000180 = 0; *(uint8_t*)0x20000181 = 0; *(uint32_t*)0x20000184 = 5; *(uint64_t*)0x20000188 = 0x20000100; *(uint8_t*)0x20000100 = 0x22; memcpy((void*)0x20000101, "\x81\x00\x46\x9f\xd3\x29\x2a\xa0\x32\x4a\x1c\x00\x00\x00\x00\xb7\x6b" "\x8a\xfe\x83\xc9\x10\xc4\xea\xe1\xa8\x98\x11\x02\xdf\x1f\x00\x00", 33); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x720, /*arg=*/0x20000180ul); return 0; }