|
| 1 | +// https://syzkaller.appspot.com/bug?id=27fe4a84236153b25f0ea48b3e92d53487c6859f |
| 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 | +static void sleep_ms(uint64_t ms) |
| 26 | +{ |
| 27 | + usleep(ms * 1000); |
| 28 | +} |
| 29 | + |
| 30 | +static uint64_t current_time_ms(void) |
| 31 | +{ |
| 32 | + struct timespec ts; |
| 33 | + if (clock_gettime(CLOCK_MONOTONIC, &ts)) |
| 34 | + exit(1); |
| 35 | + return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; |
| 36 | +} |
| 37 | + |
| 38 | +static bool write_file(const char* file, const char* what, ...) |
| 39 | +{ |
| 40 | + char buf[1024]; |
| 41 | + va_list args; |
| 42 | + va_start(args, what); |
| 43 | + vsnprintf(buf, sizeof(buf), what, args); |
| 44 | + va_end(args); |
| 45 | + buf[sizeof(buf) - 1] = 0; |
| 46 | + int len = strlen(buf); |
| 47 | + int fd = open(file, O_WRONLY | O_CLOEXEC); |
| 48 | + if (fd == -1) |
| 49 | + return false; |
| 50 | + if (write(fd, buf, len) != len) { |
| 51 | + int err = errno; |
| 52 | + close(fd); |
| 53 | + errno = err; |
| 54 | + return false; |
| 55 | + } |
| 56 | + close(fd); |
| 57 | + return true; |
| 58 | +} |
| 59 | + |
| 60 | +static void kill_and_wait(int pid, int* status) |
| 61 | +{ |
| 62 | + kill(-pid, SIGKILL); |
| 63 | + kill(pid, SIGKILL); |
| 64 | + for (int i = 0; i < 100; i++) { |
| 65 | + if (waitpid(-1, status, WNOHANG | __WALL) == pid) |
| 66 | + return; |
| 67 | + usleep(1000); |
| 68 | + } |
| 69 | + DIR* dir = opendir("/sys/fs/fuse/connections"); |
| 70 | + if (dir) { |
| 71 | + for (;;) { |
| 72 | + struct dirent* ent = readdir(dir); |
| 73 | + if (!ent) |
| 74 | + break; |
| 75 | + if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) |
| 76 | + continue; |
| 77 | + char abort[300]; |
| 78 | + snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", |
| 79 | + ent->d_name); |
| 80 | + int fd = open(abort, O_WRONLY); |
| 81 | + if (fd == -1) { |
| 82 | + continue; |
| 83 | + } |
| 84 | + if (write(fd, abort, 1) < 0) { |
| 85 | + } |
| 86 | + close(fd); |
| 87 | + } |
| 88 | + closedir(dir); |
| 89 | + } else { |
| 90 | + } |
| 91 | + while (waitpid(-1, status, __WALL) != pid) { |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +static void setup_test() |
| 96 | +{ |
| 97 | + prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); |
| 98 | + setpgrp(); |
| 99 | + write_file("/proc/self/oom_score_adj", "1000"); |
| 100 | +} |
| 101 | + |
| 102 | +static void execute_one(void); |
| 103 | + |
| 104 | +#define WAIT_FLAGS __WALL |
| 105 | + |
| 106 | +static void loop(void) |
| 107 | +{ |
| 108 | + int iter = 0; |
| 109 | + for (;; iter++) { |
| 110 | + int pid = fork(); |
| 111 | + if (pid < 0) |
| 112 | + exit(1); |
| 113 | + if (pid == 0) { |
| 114 | + setup_test(); |
| 115 | + execute_one(); |
| 116 | + exit(0); |
| 117 | + } |
| 118 | + int status = 0; |
| 119 | + uint64_t start = current_time_ms(); |
| 120 | + for (;;) { |
| 121 | + sleep_ms(10); |
| 122 | + if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) |
| 123 | + break; |
| 124 | + if (current_time_ms() - start < 5000) |
| 125 | + continue; |
| 126 | + kill_and_wait(pid, &status); |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +uint64_t r[1] = {0xffffffffffffffff}; |
| 133 | + |
| 134 | +void execute_one(void) |
| 135 | +{ |
| 136 | + intptr_t res = 0; |
| 137 | + if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { |
| 138 | + } |
| 139 | + memcpy((void*)0x200000000280, "./file0\000", 8); |
| 140 | + syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000280ul, |
| 141 | + /*mode=S_IWGRP*/ 0x10ul); |
| 142 | + memcpy((void*)0x200000000140, "./file1\000", 8); |
| 143 | + syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000140ul, |
| 144 | + /*mode=*/0ul); |
| 145 | + memcpy((void*)0x200000000300, "./bus\000", 6); |
| 146 | + syscall(__NR_mkdir, /*path=*/0x200000000300ul, /*mode=*/0ul); |
| 147 | + memcpy((void*)0x2000000000c0, "./bus\000", 6); |
| 148 | + memcpy((void*)0x200000000340, "overlay\000", 8); |
| 149 | + memcpy((void*)0x200000000080, "workdir", 7); |
| 150 | + *(uint8_t*)0x200000000087 = 0x3d; |
| 151 | + memcpy((void*)0x200000000088, "./bus", 5); |
| 152 | + *(uint8_t*)0x20000000008d = 0x2c; |
| 153 | + memcpy((void*)0x20000000008e, "lowerdir", 8); |
| 154 | + *(uint8_t*)0x200000000096 = 0x3d; |
| 155 | + memcpy((void*)0x200000000097, "./file0", 7); |
| 156 | + *(uint8_t*)0x20000000009e = 0x2c; |
| 157 | + memcpy((void*)0x20000000009f, "upperdir", 8); |
| 158 | + *(uint8_t*)0x2000000000a7 = 0x3d; |
| 159 | + memcpy((void*)0x2000000000a8, "./file1", 7); |
| 160 | + *(uint8_t*)0x2000000000af = 0x2c; |
| 161 | + *(uint8_t*)0x2000000000b0 = 0; |
| 162 | + syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x2000000000c0ul, |
| 163 | + /*type=*/0x200000000340ul, /*flags=*/0ul, /*opts=*/0x200000000080ul); |
| 164 | + memcpy((void*)0x200000000140, "./bus\000", 6); |
| 165 | + syscall(__NR_chdir, /*dir=*/0x200000000140ul); |
| 166 | + memcpy((void*)0x200000000040, "cgroup.freeze\000", 14); |
| 167 | + res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000040ul, |
| 168 | + /*flags=*/0x275a, /*mode=*/0); |
| 169 | + if (res != -1) |
| 170 | + r[0] = res; |
| 171 | + syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0xb36000ul, |
| 172 | + /*prot=PROT_GROWSDOWN|PROT_WRITE|PROT_READ*/ 0x1000003ul, |
| 173 | + /*flags=MAP_STACK|MAP_POPULATE|MAP_FIXED|MAP_SHARED*/ 0x28011ul, |
| 174 | + /*fd=*/r[0], /*offset=*/0ul); |
| 175 | + syscall(__NR_lseek, /*fd=*/r[0], /*offset=*/5ul, /*whence=SEEK_CUR*/ 1ul); |
| 176 | +} |
| 177 | +int main(void) |
| 178 | +{ |
| 179 | + syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, |
| 180 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 181 | + /*offset=*/0ul); |
| 182 | + syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, |
| 183 | + /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, |
| 184 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 185 | + /*offset=*/0ul); |
| 186 | + syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, |
| 187 | + /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, |
| 188 | + /*offset=*/0ul); |
| 189 | + const char* reason; |
| 190 | + (void)reason; |
| 191 | + loop(); |
| 192 | + return 0; |
| 193 | +} |
0 commit comments