| // general protection fault in sg_remove_scat |
| // https://syzkaller.appspot.com/bug?id=b443d21f7f64a6aeefd046bae43d1be8803e8810 |
| // status:fixed |
| // autogenerated by syzkaller (http://github.com/google/syzkaller) |
| |
| #define _GNU_SOURCE |
| #include <endian.h> |
| #include <fcntl.h> |
| #include <linux/futex.h> |
| #include <pthread.h> |
| #include <stdint.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <string.h> |
| #include <sys/stat.h> |
| #include <sys/syscall.h> |
| #include <unistd.h> |
| |
| 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 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[3] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff}; |
| unsigned long long procid; |
| void execute_call(int call) |
| { |
| long res; |
| switch (call) { |
| case 0: |
| *(uint64_t*)0x20000000 = 0x20ffc000; |
| *(uint64_t*)0x20000008 = 0; |
| *(uint32_t*)0x20000010 = 0; |
| *(uint32_t*)0x20000014 = 0; |
| *(uint64_t*)0x20000018 = 0x20fff000; |
| *(uint32_t*)0x20000020 = 0; |
| syscall(__NR_ioctl, -1, 0x4028641b, 0x20000000); |
| break; |
| case 1: |
| memcpy((void*)0x20000040, "/dev/keychord", 14); |
| res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000040, 0x40, 0); |
| if (res != -1) |
| r[0] = res; |
| break; |
| case 2: |
| *(uint64_t*)0x20001780 = 0; |
| *(uint32_t*)0x20001788 = 0; |
| *(uint64_t*)0x20001790 = 0x200016c0; |
| *(uint64_t*)0x200016c0 = 0x20000280; |
| *(uint64_t*)0x200016c8 = 0x2e; |
| *(uint64_t*)0x200016d0 = 0x20000340; |
| *(uint64_t*)0x200016d8 = 0xe0; |
| *(uint64_t*)0x200016e0 = 0x20000440; |
| *(uint64_t*)0x200016e8 = 0xee; |
| *(uint64_t*)0x200016f0 = 0x20000540; |
| *(uint64_t*)0x200016f8 = 0x1000; |
| *(uint64_t*)0x20001700 = 0x20001540; |
| *(uint64_t*)0x20001708 = 0xaa; |
| *(uint64_t*)0x20001710 = 0x20001600; |
| *(uint64_t*)0x20001718 = 0x88; |
| *(uint64_t*)0x20001798 = 6; |
| *(uint64_t*)0x200017a0 = 0x20001740; |
| *(uint64_t*)0x200017a8 = 0x26; |
| *(uint32_t*)0x200017b0 = 0x1000; |
| syscall(__NR_recvmsg, r[0], 0x20001780, 0x10020); |
| break; |
| case 3: |
| *(uint32_t*)0x20001b40 = 0xe8; |
| res = syscall(__NR_getsockopt, r[0], 0x29, 0x23, 0x20001a40, 0x20001b40); |
| if (res != -1) |
| r[1] = *(uint32_t*)0x20001a74; |
| break; |
| case 4: |
| *(uint64_t*)0x20001cc0 = 0x20001a00; |
| *(uint16_t*)0x20001a00 = 0x10; |
| *(uint16_t*)0x20001a02 = 0; |
| *(uint32_t*)0x20001a04 = 0; |
| *(uint32_t*)0x20001a08 = 0x90000; |
| *(uint32_t*)0x20001cc8 = 0xc; |
| *(uint64_t*)0x20001cd0 = 0x20001c80; |
| *(uint64_t*)0x20001c80 = 0x20001b80; |
| *(uint32_t*)0x20001b80 = 0xf8; |
| *(uint16_t*)0x20001b84 = 0x24; |
| *(uint16_t*)0x20001b86 = 4; |
| *(uint32_t*)0x20001b88 = 0x70bd26; |
| *(uint32_t*)0x20001b8c = 0x25dfdbff; |
| *(uint32_t*)0x20001b90 = 3; |
| *(uint16_t*)0x20001b94 = 0xe4; |
| *(uint16_t*)0x20001b96 = 6; |
| *(uint8_t*)0x20001b98 = 0; |
| *(uint8_t*)0x20001b99 = 0; |
| *(uint8_t*)0x20001b9a = 0; |
| *(uint8_t*)0x20001b9b = 0; |
| *(uint8_t*)0x20001b9c = 0; |
| *(uint8_t*)0x20001b9d = 0; |
| *(uint8_t*)0x20001b9e = 0; |
| *(uint8_t*)0x20001b9f = 0; |
| *(uint8_t*)0x20001ba0 = 0; |
| *(uint8_t*)0x20001ba1 = 0; |
| *(uint8_t*)0x20001ba2 = -1; |
| *(uint8_t*)0x20001ba3 = -1; |
| *(uint32_t*)0x20001ba4 = htobe32(-1); |
| *(uint8_t*)0x20001ba8 = 0; |
| *(uint8_t*)0x20001ba9 = 0; |
| *(uint8_t*)0x20001baa = 0; |
| *(uint8_t*)0x20001bab = 0; |
| *(uint8_t*)0x20001bac = 0; |
| *(uint8_t*)0x20001bad = 0; |
| *(uint8_t*)0x20001bae = 0; |
| *(uint8_t*)0x20001baf = 0; |
| *(uint8_t*)0x20001bb0 = 0; |
| *(uint8_t*)0x20001bb1 = 0; |
| *(uint8_t*)0x20001bb2 = 0; |
| *(uint8_t*)0x20001bb3 = 0; |
| *(uint8_t*)0x20001bb4 = 0; |
| *(uint8_t*)0x20001bb5 = 0; |
| *(uint8_t*)0x20001bb6 = 0; |
| *(uint8_t*)0x20001bb7 = 0; |
| *(uint16_t*)0x20001bb8 = htobe16(0x4e20); |
| *(uint16_t*)0x20001bba = htobe16(0); |
| *(uint16_t*)0x20001bbc = htobe16(0x4e20); |
| *(uint16_t*)0x20001bbe = htobe16(0); |
| *(uint16_t*)0x20001bc0 = 0xa; |
| *(uint8_t*)0x20001bc2 = 0x20; |
| *(uint8_t*)0x20001bc3 = 0x80; |
| *(uint8_t*)0x20001bc4 = 6; |
| *(uint32_t*)0x20001bc8 = 0; |
| *(uint32_t*)0x20001bcc = r[1]; |
| *(uint8_t*)0x20001bd0 = 0xac; |
| *(uint8_t*)0x20001bd1 = 0x14; |
| *(uint8_t*)0x20001bd2 = 0x14; |
| *(uint8_t*)0x20001bd3 = 0xaa; |
| *(uint32_t*)0x20001be0 = htobe32(0x4d2); |
| *(uint8_t*)0x20001be4 = -1; |
| *(uint8_t*)0x20001be8 = 0xac; |
| *(uint8_t*)0x20001be9 = 0x14; |
| *(uint8_t*)0x20001bea = 0x14; |
| *(uint8_t*)0x20001beb = 0xbb; |
| *(uint64_t*)0x20001bf8 = 2; |
| *(uint64_t*)0x20001c00 = 2; |
| *(uint64_t*)0x20001c08 = 0x3ff; |
| *(uint64_t*)0x20001c10 = 0x69; |
| *(uint64_t*)0x20001c18 = 0x42; |
| *(uint64_t*)0x20001c20 = 6; |
| *(uint64_t*)0x20001c28 = 0xfffffffffffffbff; |
| *(uint64_t*)0x20001c30 = 3; |
| *(uint64_t*)0x20001c38 = 6; |
| *(uint64_t*)0x20001c40 = 5; |
| *(uint64_t*)0x20001c48 = 1; |
| *(uint64_t*)0x20001c50 = 4; |
| *(uint32_t*)0x20001c58 = 0xfff; |
| *(uint32_t*)0x20001c5c = 0x804; |
| *(uint32_t*)0x20001c60 = 0x2c; |
| *(uint32_t*)0x20001c64 = 0x70bd2c; |
| *(uint32_t*)0x20001c68 = 0x3505; |
| *(uint16_t*)0x20001c6c = 0xa; |
| *(uint8_t*)0x20001c6e = 4; |
| *(uint8_t*)0x20001c6f = 1; |
| *(uint8_t*)0x20001c70 = 0; |
| *(uint64_t*)0x20001c88 = 0xf8; |
| *(uint64_t*)0x20001cd8 = 1; |
| *(uint64_t*)0x20001ce0 = 0; |
| *(uint64_t*)0x20001ce8 = 0; |
| *(uint32_t*)0x20001cf0 = 0x24004040; |
| syscall(__NR_sendmsg, r[0], 0x20001cc0, 0x80); |
| break; |
| case 5: |
| *(uint64_t*)0x20000240 = 0x200017c0; |
| *(uint64_t*)0x20000248 = 0; |
| *(uint64_t*)0x20000250 = 0x20001880; |
| *(uint64_t*)0x20000258 = 0; |
| *(uint64_t*)0x20000260 = 0x20000140; |
| *(uint64_t*)0x20000268 = 0; |
| *(uint64_t*)0x20000270 = 0x200002c0; |
| *(uint64_t*)0x20000278 = 0; |
| syscall(__NR_pwritev, r[0], 0x20000240, 4, 0); |
| break; |
| case 6: |
| memcpy((void*)0x20797ff7, "/dev/sg#", 9); |
| res = syz_open_dev(0x20797ff7, 0, 0); |
| if (res != -1) |
| r[2] = res; |
| break; |
| case 7: |
| *(uint32_t*)0x200000c0 = 0; |
| *(uint32_t*)0x200000c4 = 0; |
| *(uint32_t*)0x20000100 = 8; |
| syscall(__NR_getsockopt, r[2], 0x84, 0x7b, 0x200000c0, 0x20000100); |
| break; |
| case 8: |
| *(uint32_t*)0x20000200 = 0x10; |
| syscall(__NR_getsockname, -1, 0x200001c0, 0x20000200); |
| break; |
| case 9: |
| syscall(__NR_ioctl, r[2], 0x20000000002285, 0x20000000); |
| break; |
| case 10: |
| syscall(__NR_read, r[2], 0x20001940, 0x8f); |
| break; |
| } |
| } |
| |
| void execute_one() |
| { |
| execute(11); |
| collide = 1; |
| execute(11); |
| } |
| |
| int main() |
| { |
| syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); |
| for (procid = 0; procid < 8; procid++) { |
| if (fork() == 0) { |
| for (;;) { |
| loop(); |
| } |
| } |
| } |
| sleep(1000000); |
| return 0; |
| } |