a4c0b3decb33.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. // autogenerated by syzkaller (https://github.com/google/syzkaller)
  4. #include <dirent.h>
  5. #include <endian.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include <signal.h>
  9. #include <stdarg.h>
  10. #include <stdbool.h>
  11. #include <stdint.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <sys/prctl.h>
  16. #include <sys/stat.h>
  17. #include <sys/types.h>
  18. #include <sys/wait.h>
  19. #include <sys/mman.h>
  20. #include <time.h>
  21. #include <unistd.h>
  22. #include "liburing.h"
  23. #include "helpers.h"
  24. #include "../src/syscall.h"
  25. static void sleep_ms(uint64_t ms)
  26. {
  27. usleep(ms * 1000);
  28. }
  29. static uint64_t current_time_ms(void)
  30. {
  31. struct timespec ts;
  32. if (clock_gettime(CLOCK_MONOTONIC, &ts))
  33. exit(1);
  34. return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
  35. }
  36. static bool write_file(const char* file, const char* what, ...)
  37. {
  38. char buf[1024];
  39. va_list args;
  40. va_start(args, what);
  41. vsnprintf(buf, sizeof(buf), what, args);
  42. va_end(args);
  43. buf[sizeof(buf) - 1] = 0;
  44. int len = strlen(buf);
  45. int fd = open(file, O_WRONLY | O_CLOEXEC);
  46. if (fd == -1)
  47. return false;
  48. if (write(fd, buf, len) != len) {
  49. int err = errno;
  50. close(fd);
  51. errno = err;
  52. return false;
  53. }
  54. close(fd);
  55. return true;
  56. }
  57. static void kill_and_wait(int pid, int* status)
  58. {
  59. kill(-pid, SIGKILL);
  60. kill(pid, SIGKILL);
  61. int i;
  62. for (i = 0; i < 100; i++) {
  63. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  64. return;
  65. usleep(1000);
  66. }
  67. DIR* dir = opendir("/sys/fs/fuse/connections");
  68. if (dir) {
  69. for (;;) {
  70. struct dirent* ent = readdir(dir);
  71. if (!ent)
  72. break;
  73. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  74. continue;
  75. char abort[300];
  76. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  77. ent->d_name);
  78. int fd = open(abort, O_WRONLY);
  79. if (fd == -1) {
  80. continue;
  81. }
  82. if (write(fd, abort, 1) < 0) {
  83. }
  84. close(fd);
  85. }
  86. closedir(dir);
  87. } else {
  88. }
  89. while (waitpid(-1, status, __WALL) != pid) {
  90. }
  91. }
  92. static void setup_test(void)
  93. {
  94. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  95. setpgrp();
  96. write_file("/proc/self/oom_score_adj", "1000");
  97. }
  98. static void execute_one(void);
  99. #define WAIT_FLAGS __WALL
  100. static void loop(void)
  101. {
  102. int iter;
  103. for (iter = 0; iter < 5000; iter++) {
  104. int pid = fork();
  105. if (pid < 0)
  106. exit(1);
  107. if (pid == 0) {
  108. setup_test();
  109. execute_one();
  110. exit(0);
  111. }
  112. int status = 0;
  113. uint64_t start = current_time_ms();
  114. for (;;) {
  115. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  116. break;
  117. sleep_ms(1);
  118. if (current_time_ms() - start < 5 * 1000)
  119. continue;
  120. kill_and_wait(pid, &status);
  121. break;
  122. }
  123. }
  124. }
  125. void execute_one(void)
  126. {
  127. *(uint32_t*)0x20000080 = 0;
  128. *(uint32_t*)0x20000084 = 0;
  129. *(uint32_t*)0x20000088 = 3;
  130. *(uint32_t*)0x2000008c = 3;
  131. *(uint32_t*)0x20000090 = 0x175;
  132. *(uint32_t*)0x20000094 = 0;
  133. *(uint32_t*)0x20000098 = 0;
  134. *(uint32_t*)0x2000009c = 0;
  135. *(uint32_t*)0x200000a0 = 0;
  136. *(uint32_t*)0x200000a4 = 0;
  137. *(uint32_t*)0x200000a8 = 0;
  138. *(uint32_t*)0x200000ac = 0;
  139. *(uint32_t*)0x200000b0 = 0;
  140. *(uint32_t*)0x200000b4 = 0;
  141. *(uint32_t*)0x200000b8 = 0;
  142. *(uint32_t*)0x200000bc = 0;
  143. *(uint32_t*)0x200000c0 = 0;
  144. *(uint32_t*)0x200000c4 = 0;
  145. *(uint64_t*)0x200000c8 = 0;
  146. *(uint32_t*)0x200000d0 = 0;
  147. *(uint32_t*)0x200000d4 = 0;
  148. *(uint32_t*)0x200000d8 = 0;
  149. *(uint32_t*)0x200000dc = 0;
  150. *(uint32_t*)0x200000e0 = 0;
  151. *(uint32_t*)0x200000e4 = 0;
  152. *(uint32_t*)0x200000e8 = 0;
  153. *(uint32_t*)0x200000ec = 0;
  154. *(uint64_t*)0x200000f0 = 0;
  155. __sys_io_uring_setup(0x983, (struct io_uring_params *) 0x20000080);
  156. }
  157. static void sig_int(int sig)
  158. {
  159. exit(0);
  160. }
  161. int main(int argc, char *argv[])
  162. {
  163. if (argc > 1)
  164. return T_EXIT_SKIP;
  165. signal(SIGINT, sig_int);
  166. mmap((void *) 0x20000000, 0x1000000, 3, MAP_ANON|MAP_PRIVATE, -1, 0);
  167. loop();
  168. return T_EXIT_PASS;
  169. }