| // possible deadlock in nfnl_lock |
| // https://syzkaller.appspot.com/bug?id=a84f5bda87016a5080937dc7f9d8e1a007e31c0a |
| // status:open |
| // autogenerated by syzkaller (https://github.com/google/syzkaller) |
| |
| #define _GNU_SOURCE |
| |
| #include <dirent.h> |
| #include <endian.h> |
| #include <errno.h> |
| #include <fcntl.h> |
| #include <signal.h> |
| #include <stdarg.h> |
| #include <stdbool.h> |
| #include <stdint.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <sys/prctl.h> |
| #include <sys/stat.h> |
| #include <sys/syscall.h> |
| #include <sys/types.h> |
| #include <sys/wait.h> |
| #include <time.h> |
| #include <unistd.h> |
| |
| static void sleep_ms(uint64_t ms) |
| { |
| usleep(ms * 1000); |
| } |
| |
| static uint64_t current_time_ms(void) |
| { |
| struct timespec ts; |
| if (clock_gettime(CLOCK_MONOTONIC, &ts)) |
| exit(1); |
| return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; |
| } |
| |
| #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) |
| #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ |
| *(type*)(addr) = \ |
| htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ |
| (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) |
| |
| static bool write_file(const char* file, const char* what, ...) |
| { |
| char buf[1024]; |
| va_list args; |
| va_start(args, what); |
| vsnprintf(buf, sizeof(buf), what, args); |
| va_end(args); |
| buf[sizeof(buf) - 1] = 0; |
| int len = strlen(buf); |
| int fd = open(file, O_WRONLY | O_CLOEXEC); |
| if (fd == -1) |
| return false; |
| if (write(fd, buf, len) != len) { |
| int err = errno; |
| close(fd); |
| errno = err; |
| return false; |
| } |
| close(fd); |
| return true; |
| } |
| |
| static void kill_and_wait(int pid, int* status) |
| { |
| kill(-pid, SIGKILL); |
| kill(pid, SIGKILL); |
| int i; |
| for (i = 0; i < 100; i++) { |
| if (waitpid(-1, status, WNOHANG | __WALL) == pid) |
| return; |
| usleep(1000); |
| } |
| DIR* dir = opendir("/sys/fs/fuse/connections"); |
| if (dir) { |
| for (;;) { |
| struct dirent* ent = readdir(dir); |
| if (!ent) |
| break; |
| if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) |
| continue; |
| char abort[300]; |
| snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", |
| ent->d_name); |
| int fd = open(abort, O_WRONLY); |
| if (fd == -1) { |
| continue; |
| } |
| if (write(fd, abort, 1) < 0) { |
| } |
| close(fd); |
| } |
| closedir(dir); |
| } else { |
| } |
| while (waitpid(-1, status, __WALL) != pid) { |
| } |
| } |
| |
| static void setup_test() |
| { |
| prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); |
| setpgrp(); |
| write_file("/proc/self/oom_score_adj", "1000"); |
| } |
| |
| static void execute_one(void); |
| |
| #define WAIT_FLAGS __WALL |
| |
| static void loop(void) |
| { |
| int iter; |
| for (iter = 0;; iter++) { |
| int pid = fork(); |
| if (pid < 0) |
| exit(1); |
| if (pid == 0) { |
| setup_test(); |
| execute_one(); |
| exit(0); |
| } |
| int status = 0; |
| uint64_t start = current_time_ms(); |
| for (;;) { |
| if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) |
| break; |
| sleep_ms(1); |
| if (current_time_ms() - start < 5 * 1000) |
| continue; |
| kill_and_wait(pid, &status); |
| break; |
| } |
| } |
| } |
| |
| uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; |
| |
| void execute_one(void) |
| { |
| intptr_t res = 0; |
| res = syscall(__NR_socket, 2ul, 2ul, 0ul); |
| if (res != -1) |
| r[0] = res; |
| memcpy( |
| (void*)0x20000640, |
| "\x6d\x61\x6e\x67\x6c\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00" |
| "\x06\x00\x00\x00\xd8\x03\x00\x00\x10\x02\x00\x00\x10\x02\x00\x00\xa8\x02" |
| "\x00\x00\xa8\x02\x00\x00\x10\x02\x00\x00\x40\x03\x00\x00\x40\x03\x00\x00" |
| "\x40\x03\x00\x00\x40\x03\x00\x00\x40\x03\x00\x00\x06\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08" |
| "\x00\x00\x00\x00\x70\x00\x98\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x00\x54\x54\x4c\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x98\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x28\x00\x54\x54\x4c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\xe0\x00\x00\x02\xac\x14\x14\xaa\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x65\x72\x73\x70\x61\x6e\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x98\x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x14\x00\x00\x00\xdd\xff\x28\x00\x72\x70\x66\x69\x6c\x74\x65\x72" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x48\x00\x54\x45\x45\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x01\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x20\x01\x67\x72\x65\x30\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x98\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x00" |
| "\x4e\x46\x51\x55\x45\x55\x45\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x70\x00\x98\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x28\x00\x45\x43\x4e\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x98\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\xff", |
| 1076); |
| syscall(__NR_setsockopt, r[0], 0ul, 0x40ul, 0x20000640ul, 1ul); |
| res = syscall(__NR_socket, 0xaul, 2ul, 0ul); |
| if (res != -1) |
| r[1] = res; |
| *(uint8_t*)0x200000c0 = 0xfe; |
| *(uint8_t*)0x200000c1 = 0x80; |
| *(uint8_t*)0x200000c2 = 0; |
| *(uint8_t*)0x200000c3 = 0xef; |
| *(uint8_t*)0x200000c4 = 0; |
| *(uint8_t*)0x200000c5 = 0; |
| *(uint8_t*)0x200000c6 = 0; |
| *(uint8_t*)0x200000c7 = 0; |
| *(uint8_t*)0x200000c8 = 3; |
| *(uint8_t*)0x200000c9 = 0; |
| *(uint8_t*)0x200000ca = 0; |
| *(uint8_t*)0x200000cb = 0; |
| *(uint8_t*)0x200000cc = 0; |
| *(uint8_t*)0x200000cd = 6; |
| *(uint8_t*)0x200000ce = 0; |
| *(uint8_t*)0x200000cf = 0xaa; |
| *(uint32_t*)0x200000d0 = 0xfffffffe; |
| *(uint32_t*)0x200000d4 = 0; |
| syscall(__NR_ioctl, r[1], 0x89a1ul, 0x200000c0ul); |
| *(uint8_t*)0x200005c0 = 0xfe; |
| *(uint8_t*)0x200005c1 = 0x80; |
| *(uint8_t*)0x200005c2 = 0; |
| *(uint8_t*)0x200005c3 = 0; |
| *(uint8_t*)0x200005c4 = 0; |
| *(uint8_t*)0x200005c5 = 0; |
| *(uint8_t*)0x200005c6 = 0; |
| *(uint8_t*)0x200005c7 = 0; |
| *(uint8_t*)0x200005c8 = 0; |
| *(uint8_t*)0x200005c9 = 0; |
| *(uint8_t*)0x200005ca = 0; |
| *(uint8_t*)0x200005cb = 0; |
| *(uint8_t*)0x200005cc = 0; |
| *(uint8_t*)0x200005cd = 0; |
| *(uint8_t*)0x200005ce = 0; |
| *(uint8_t*)0x200005cf = 0xaa; |
| *(uint8_t*)0x200005d0 = 0; |
| *(uint8_t*)0x200005d1 = 0; |
| *(uint8_t*)0x200005d2 = 0; |
| *(uint8_t*)0x200005d3 = 0; |
| *(uint8_t*)0x200005d4 = 0; |
| *(uint8_t*)0x200005d5 = 0; |
| *(uint8_t*)0x200005d6 = 0; |
| *(uint8_t*)0x200005d7 = 0; |
| *(uint8_t*)0x200005d8 = 0; |
| *(uint8_t*)0x200005d9 = 0; |
| *(uint8_t*)0x200005da = -1; |
| *(uint8_t*)0x200005db = -1; |
| *(uint32_t*)0x200005dc = htobe32(0x7f000001); |
| *(uint8_t*)0x200005e0 = 0; |
| *(uint8_t*)0x200005e1 = 0; |
| *(uint8_t*)0x200005e2 = 0; |
| *(uint8_t*)0x200005e3 = 0; |
| *(uint8_t*)0x200005e4 = 0; |
| *(uint8_t*)0x200005e5 = 0; |
| *(uint8_t*)0x200005e6 = 0; |
| *(uint8_t*)0x200005e7 = 0; |
| *(uint8_t*)0x200005e8 = 0; |
| *(uint8_t*)0x200005e9 = 0; |
| *(uint8_t*)0x200005ea = -1; |
| *(uint8_t*)0x200005eb = -1; |
| *(uint32_t*)0x200005ec = htobe32(0x7f000001); |
| *(uint32_t*)0x200005f0 = 2; |
| *(uint16_t*)0x200005f4 = 0; |
| *(uint16_t*)0x200005f6 = 0; |
| *(uint32_t*)0x200005f8 = 0; |
| *(uint64_t*)0x20000600 = 0; |
| *(uint32_t*)0x20000608 = 0; |
| *(uint32_t*)0x2000060c = 0; |
| syscall(__NR_ioctl, r[1], 0x89a0ul, 0x200005c0ul); |
| res = syscall(__NR_socket, 0x10ul, 3ul, 0xcul); |
| if (res != -1) |
| r[2] = res; |
| *(uint64_t*)0x20000140 = 0; |
| *(uint32_t*)0x20000148 = 0; |
| *(uint64_t*)0x20000150 = 0x20000100; |
| *(uint64_t*)0x20000100 = 0x20000080; |
| *(uint32_t*)0x20000080 = 0x30; |
| *(uint8_t*)0x20000084 = 0; |
| *(uint8_t*)0x20000085 = 0xb; |
| *(uint16_t*)0x20000086 = 0x201; |
| *(uint32_t*)0x20000088 = 0; |
| *(uint32_t*)0x2000008c = 0; |
| *(uint8_t*)0x20000090 = 3; |
| *(uint8_t*)0x20000091 = 0; |
| *(uint16_t*)0x20000092 = htobe16(0); |
| *(uint16_t*)0x20000094 = 9; |
| *(uint16_t*)0x20000096 = 1; |
| memcpy((void*)0x20000098, "ppp0\000", 5); |
| *(uint16_t*)0x200000a0 = 8; |
| STORE_BY_BITMASK(uint16_t, , 0x200000a2, 2, 0, 14); |
| STORE_BY_BITMASK(uint16_t, , 0x200000a3, 1, 6, 1); |
| STORE_BY_BITMASK(uint16_t, , 0x200000a3, 0, 7, 1); |
| *(uint32_t*)0x200000a4 = htobe32(0); |
| *(uint16_t*)0x200000a8 = 8; |
| STORE_BY_BITMASK(uint16_t, , 0x200000aa, 3, 0, 14); |
| STORE_BY_BITMASK(uint16_t, , 0x200000ab, 1, 6, 1); |
| STORE_BY_BITMASK(uint16_t, , 0x200000ab, 0, 7, 1); |
| *(uint32_t*)0x200000ac = htobe32(0); |
| *(uint64_t*)0x20000108 = 0x30; |
| *(uint64_t*)0x20000158 = 1; |
| *(uint64_t*)0x20000160 = 0; |
| *(uint64_t*)0x20000168 = 0; |
| *(uint32_t*)0x20000170 = 0; |
| syscall(__NR_sendmsg, r[2], 0x20000140ul, 0ul); |
| } |
| int main(void) |
| { |
| syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0); |
| loop(); |
| return 0; |
| } |