|
| 1 | +// https://syzkaller.appspot.com/bug?id=ac361c5db546855a3d27a34f1fa5b10793e54ba6 |
| 2 | +// autogenerated by syzkaller (https://github.com/google/syzkaller) |
| 3 | + |
| 4 | +#define _GNU_SOURCE |
| 5 | + |
| 6 | +#include <dirent.h> |
| 7 | +#include <endian.h> |
| 8 | +#include <errno.h> |
| 9 | +#include <fcntl.h> |
| 10 | +#include <signal.h> |
| 11 | +#include <stdarg.h> |
| 12 | +#include <stdbool.h> |
| 13 | +#include <stdint.h> |
| 14 | +#include <stdio.h> |
| 15 | +#include <stdlib.h> |
| 16 | +#include <string.h> |
| 17 | +#include <sys/prctl.h> |
| 18 | +#include <sys/stat.h> |
| 19 | +#include <sys/syscall.h> |
| 20 | +#include <sys/types.h> |
| 21 | +#include <sys/wait.h> |
| 22 | +#include <time.h> |
| 23 | +#include <unistd.h> |
| 24 | + |
| 25 | +#ifndef __NR_bpf |
| 26 | +#define __NR_bpf 321 |
| 27 | +#endif |
| 28 | + |
| 29 | +static void sleep_ms(uint64_t ms) |
| 30 | +{ |
| 31 | + usleep(ms * 1000); |
| 32 | +} |
| 33 | + |
| 34 | +static uint64_t current_time_ms(void) |
| 35 | +{ |
| 36 | + struct timespec ts; |
| 37 | + if (clock_gettime(CLOCK_MONOTONIC, &ts)) |
| 38 | + exit(1); |
| 39 | + return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; |
| 40 | +} |
| 41 | + |
| 42 | +static bool write_file(const char* file, const char* what, ...) |
| 43 | +{ |
| 44 | + char buf[1024]; |
| 45 | + va_list args; |
| 46 | + va_start(args, what); |
| 47 | + vsnprintf(buf, sizeof(buf), what, args); |
| 48 | + va_end(args); |
| 49 | + buf[sizeof(buf) - 1] = 0; |
| 50 | + int len = strlen(buf); |
| 51 | + int fd = open(file, O_WRONLY | O_CLOEXEC); |
| 52 | + if (fd == -1) |
| 53 | + return false; |
| 54 | + if (write(fd, buf, len) != len) { |
| 55 | + int err = errno; |
| 56 | + close(fd); |
| 57 | + errno = err; |
| 58 | + return false; |
| 59 | + } |
| 60 | + close(fd); |
| 61 | + return true; |
| 62 | +} |
| 63 | + |
| 64 | +static void kill_and_wait(int pid, int* status) |
| 65 | +{ |
| 66 | + kill(-pid, SIGKILL); |
| 67 | + kill(pid, SIGKILL); |
| 68 | + for (int i = 0; i < 100; i++) { |
| 69 | + if (waitpid(-1, status, WNOHANG | __WALL) == pid) |
| 70 | + return; |
| 71 | + usleep(1000); |
| 72 | + } |
| 73 | + DIR* dir = opendir("/sys/fs/fuse/connections"); |
| 74 | + if (dir) { |
| 75 | + for (;;) { |
| 76 | + struct dirent* ent = readdir(dir); |
| 77 | + if (!ent) |
| 78 | + break; |
| 79 | + if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) |
| 80 | + continue; |
| 81 | + char abort[300]; |
| 82 | + snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", |
| 83 | + ent->d_name); |
| 84 | + int fd = open(abort, O_WRONLY); |
| 85 | + if (fd == -1) { |
| 86 | + continue; |
| 87 | + } |
| 88 | + if (write(fd, abort, 1) < 0) { |
| 89 | + } |
| 90 | + close(fd); |
| 91 | + } |
| 92 | + closedir(dir); |
| 93 | + } else { |
| 94 | + } |
| 95 | + while (waitpid(-1, status, __WALL) != pid) { |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +static void setup_test() |
| 100 | +{ |
| 101 | + prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); |
| 102 | + setpgrp(); |
| 103 | + write_file("/proc/self/oom_score_adj", "1000"); |
| 104 | +} |
| 105 | + |
| 106 | +static void execute_one(void); |
| 107 | + |
| 108 | +#define WAIT_FLAGS __WALL |
| 109 | + |
| 110 | +static void loop(void) |
| 111 | +{ |
| 112 | + int iter = 0; |
| 113 | + for (;; iter++) { |
| 114 | + int pid = fork(); |
| 115 | + if (pid < 0) |
| 116 | + exit(1); |
| 117 | + if (pid == 0) { |
| 118 | + setup_test(); |
| 119 | + execute_one(); |
| 120 | + exit(0); |
| 121 | + } |
| 122 | + int status = 0; |
| 123 | + uint64_t start = current_time_ms(); |
| 124 | + for (;;) { |
| 125 | + sleep_ms(10); |
| 126 | + if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) |
| 127 | + break; |
| 128 | + if (current_time_ms() - start < 5000) |
| 129 | + continue; |
| 130 | + kill_and_wait(pid, &status); |
| 131 | + break; |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +uint64_t r[1] = {0xffffffffffffffff}; |
| 137 | + |
| 138 | +void execute_one(void) |
| 139 | +{ |
| 140 | + intptr_t res = 0; |
| 141 | + if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { |
| 142 | + } |
| 143 | + res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0); |
| 144 | + if (res != -1) |
| 145 | + r[0] = res; |
| 146 | + memcpy((void*)0x200000000140, |
| 147 | + "\x01\x00\x00\x00\x09\x00\x00\x00\x05\x00\x10\x00\x02\x00\x00\x00\x00" |
| 148 | + "\x00\x00\x00", |
| 149 | + 20); |
| 150 | + *(uint32_t*)0x200000000154 = -1; |
| 151 | + *(uint32_t*)0x200000000158 = -1; |
| 152 | + syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200000000140ul, /*size=*/0x48ul); |
| 153 | + *(uint64_t*)0x200000000180 = 0; |
| 154 | + *(uint32_t*)0x200000000188 = 0; |
| 155 | + *(uint64_t*)0x200000000190 = 0x200000000080; |
| 156 | + *(uint64_t*)0x200000000080 = 0x200000000100; |
| 157 | + *(uint32_t*)0x200000000100 = 0x44; |
| 158 | + *(uint16_t*)0x200000000104 = 0x24; |
| 159 | + *(uint16_t*)0x200000000106 = 0x800; |
| 160 | + *(uint32_t*)0x200000000108 = 0x70bd29; |
| 161 | + *(uint32_t*)0x20000000010c = 0x25dfdc00; |
| 162 | + *(uint8_t*)0x200000000110 = 0x60; |
| 163 | + *(uint8_t*)0x200000000111 = 0; |
| 164 | + *(uint16_t*)0x200000000112 = 0; |
| 165 | + *(uint32_t*)0x200000000114 = 0; |
| 166 | + *(uint16_t*)0x200000000118 = 0xfff1; |
| 167 | + *(uint16_t*)0x20000000011a = 0xfff2; |
| 168 | + *(uint16_t*)0x20000000011c = 1; |
| 169 | + *(uint16_t*)0x20000000011e = 0xc; |
| 170 | + *(uint16_t*)0x200000000120 = 0xfff3; |
| 171 | + *(uint16_t*)0x200000000122 = 8; |
| 172 | + *(uint16_t*)0x200000000124 = 9; |
| 173 | + *(uint16_t*)0x200000000126 = 1; |
| 174 | + memcpy((void*)0x200000000128, "cake\000", 5); |
| 175 | + *(uint16_t*)0x200000000130 = 0x14; |
| 176 | + *(uint16_t*)0x200000000132 = 2; |
| 177 | + *(uint16_t*)0x200000000134 = 8; |
| 178 | + *(uint16_t*)0x200000000136 = 0xa; |
| 179 | + *(uint32_t*)0x200000000138 = 0x80000000; |
| 180 | + *(uint16_t*)0x20000000013c = 8; |
| 181 | + *(uint16_t*)0x20000000013e = 0xf; |
| 182 | + *(uint32_t*)0x200000000140 = 2; |
| 183 | + *(uint64_t*)0x200000000088 = 0x44; |
| 184 | + *(uint64_t*)0x200000000198 = 1; |
| 185 | + *(uint64_t*)0x2000000001a0 = 0; |
| 186 | + *(uint64_t*)0x2000000001a8 = 0; |
| 187 | + *(uint32_t*)0x2000000001b0 = 0x44045; |
| 188 | + syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000180ul, |
| 189 | + /*f=MSG_PROBE*/ 0x10ul); |
| 190 | + *(uint64_t*)0x200000000000 = 0; |
| 191 | + *(uint32_t*)0x200000000008 = 0; |
| 192 | + *(uint64_t*)0x200000000010 = 0x200000000080; |
| 193 | + *(uint64_t*)0x200000000080 = 0x200000000100; |
| 194 | + memcpy((void*)0x200000000100, |
| 195 | + "\x50\x00\x00\x00\x10\x00\x01\x04\x25\xbb\xe5\xad\x60\x00\x27\x84\x2c" |
| 196 | + "\xf5\x23\x00", |
| 197 | + 20); |
| 198 | + *(uint32_t*)0x200000000114 = 0; |
| 199 | + memcpy((void*)0x200000000118, |
| 200 | + "\x00\x00\x00\x00\x00\x00\x80\x00\x28\x00\x12\x80\x0a\x00\x01\x00\x76" |
| 201 | + "\x78\x6c\x61\x6e", |
| 202 | + 21); |
| 203 | + *(uint64_t*)0x200000000088 = 0x50; |
| 204 | + *(uint64_t*)0x200000000018 = 1; |
| 205 | + *(uint64_t*)0x200000000020 = 0; |
| 206 | + *(uint64_t*)0x200000000028 = 0; |
| 207 | + *(uint32_t*)0x200000000030 = 0; |
| 208 | + syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000000ul, |
| 209 | + /*f=MSG_ZEROCOPY*/ 0x4000000ul); |
| 210 | +} |
| 211 | +int main(void) |
| 212 | +{ |
| 213 | + syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, |
| 214 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 215 | + /*offset=*/0ul); |
| 216 | + syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, |
| 217 | + /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, |
| 218 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 219 | + /*offset=*/0ul); |
| 220 | + syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, |
| 221 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 222 | + /*offset=*/0ul); |
| 223 | + const char* reason; |
| 224 | + (void)reason; |
| 225 | + loop(); |
| 226 | + return 0; |
| 227 | +} |
0 commit comments