a4c0b3decb33.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #ifndef CONFIG_USE_SANITIZER
  26. static void sleep_ms(uint64_t ms)
  27. {
  28. usleep(ms * 1000);
  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. static bool write_file(const char* file, const char* what, ...)
  38. {
  39. char buf[1024];
  40. va_list args;
  41. va_start(args, what);
  42. vsnprintf(buf, sizeof(buf), what, args);
  43. va_end(args);
  44. buf[sizeof(buf) - 1] = 0;
  45. int len = strlen(buf);
  46. int fd = open(file, O_WRONLY | O_CLOEXEC);
  47. if (fd == -1)
  48. return false;
  49. if (write(fd, buf, len) != len) {
  50. int err = errno;
  51. close(fd);
  52. errno = err;
  53. return false;
  54. }
  55. close(fd);
  56. return true;
  57. }
  58. static void kill_and_wait(int pid, int* status)
  59. {
  60. kill(-pid, SIGKILL);
  61. kill(pid, SIGKILL);
  62. int i;
  63. for (i = 0; i < 100; i++) {
  64. if (waitpid(-1, status, WNOHANG | __WALL) == pid)
  65. return;
  66. usleep(1000);
  67. }
  68. DIR* dir = opendir("/sys/fs/fuse/connections");
  69. if (dir) {
  70. for (;;) {
  71. struct dirent* ent = readdir(dir);
  72. if (!ent)
  73. break;
  74. if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
  75. continue;
  76. char abort[300];
  77. snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
  78. ent->d_name);
  79. int fd = open(abort, O_WRONLY);
  80. if (fd == -1) {
  81. continue;
  82. }
  83. if (write(fd, abort, 1) < 0) {
  84. }
  85. close(fd);
  86. }
  87. closedir(dir);
  88. } else {
  89. }
  90. while (waitpid(-1, status, __WALL) != pid) {
  91. }
  92. }
  93. static void setup_test(void)
  94. {
  95. prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  96. setpgrp();
  97. write_file("/proc/self/oom_score_adj", "1000");
  98. }
  99. static void execute_one(void);
  100. #define WAIT_FLAGS __WALL
  101. static void loop(void)
  102. {
  103. int iter;
  104. for (iter = 0; iter < 50; iter++) {
  105. int pid = fork();
  106. if (pid < 0)
  107. exit(1);
  108. if (pid == 0) {
  109. setup_test();
  110. execute_one();
  111. exit(0);
  112. }
  113. int status = 0;
  114. uint64_t start = current_time_ms();
  115. for (;;) {
  116. if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
  117. break;
  118. sleep_ms(1);
  119. if (current_time_ms() - start < 5 * 1000)
  120. continue;
  121. kill_and_wait(pid, &status);
  122. break;
  123. }
  124. }
  125. }
  126. void execute_one(void)
  127. {
  128. *(uint32_t*)0x20000080 = 0;
  129. *(uint32_t*)0x20000084 = 0;
  130. *(uint32_t*)0x20000088 = 3;
  131. *(uint32_t*)0x2000008c = 3;
  132. *(uint32_t*)0x20000090 = 0x175;
  133. *(uint32_t*)0x20000094 = 0;
  134. *(uint32_t*)0x20000098 = 0;
  135. *(uint32_t*)0x2000009c = 0;
  136. *(uint32_t*)0x200000a0 = 0;
  137. *(uint32_t*)0x200000a4 = 0;
  138. *(uint32_t*)0x200000a8 = 0;
  139. *(uint32_t*)0x200000ac = 0;
  140. *(uint32_t*)0x200000b0 = 0;
  141. *(uint32_t*)0x200000b4 = 0;
  142. *(uint32_t*)0x200000b8 = 0;
  143. *(uint32_t*)0x200000bc = 0;
  144. *(uint32_t*)0x200000c0 = 0;
  145. *(uint32_t*)0x200000c4 = 0;
  146. *(uint64_t*)0x200000c8 = 0;
  147. *(uint32_t*)0x200000d0 = 0;
  148. *(uint32_t*)0x200000d4 = 0;
  149. *(uint32_t*)0x200000d8 = 0;
  150. *(uint32_t*)0x200000dc = 0;
  151. *(uint32_t*)0x200000e0 = 0;
  152. *(uint32_t*)0x200000e4 = 0;
  153. *(uint32_t*)0x200000e8 = 0;
  154. *(uint32_t*)0x200000ec = 0;
  155. *(uint64_t*)0x200000f0 = 0;
  156. __sys_io_uring_setup(0x983, (struct io_uring_params *) 0x20000080);
  157. }
  158. static void sig_int(int sig)
  159. {
  160. exit(0);
  161. }
  162. int main(int argc, char *argv[])
  163. {
  164. if (argc > 1)
  165. return T_EXIT_SKIP;
  166. signal(SIGINT, sig_int);
  167. mmap((void *) 0x20000000, 0x1000000, 3, MAP_ANON|MAP_PRIVATE, -1, 0);
  168. loop();
  169. return T_EXIT_PASS;
  170. }
  171. #else
  172. int main(int argc, char *argv[])
  173. {
  174. return T_EXIT_SKIP;
  175. }
  176. #endif