coredump.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: trigger segfault. A recent 6.4-rc kernel introduced a bug
  5. * via vhost where segfaults for applications using io_uring
  6. * would hang in D state forever upon trying to generate the
  7. * core file. Perform a trivial test where a child process
  8. * generates a NULL pointer dereference and ensure that we don't
  9. * hang.
  10. *
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <unistd.h>
  15. #include <sys/wait.h>
  16. #include "liburing.h"
  17. #include "helpers.h"
  18. #ifndef CONFIG_USE_SANITIZER
  19. static void test(void)
  20. {
  21. struct io_uring_sqe *sqe;
  22. struct io_uring ring;
  23. int *ptr = NULL;
  24. int fds[2];
  25. char r1;
  26. if (pipe(fds) < 0) {
  27. perror("pipe");
  28. exit(0);
  29. }
  30. io_uring_queue_init(8, &ring, 0);
  31. sqe = io_uring_get_sqe(&ring);
  32. io_uring_prep_read(sqe, fds[0], &r1, sizeof(r1), 0);
  33. sqe->flags = IOSQE_ASYNC;
  34. sqe->user_data = 1;
  35. io_uring_submit(&ring);
  36. *ptr = 0;
  37. exit(0);
  38. }
  39. int main(int argc, char *argv[])
  40. {
  41. pid_t pid;
  42. int wstat;
  43. pid = fork();
  44. if (pid < 0) {
  45. perror("fork");
  46. return T_EXIT_SKIP;
  47. } else if (!pid) {
  48. test();
  49. }
  50. wait(&wstat);
  51. unlink("core");
  52. return T_EXIT_PASS;
  53. }
  54. #else
  55. int main(int argc, char *argv[])
  56. {
  57. return T_EXIT_SKIP;
  58. }
  59. #endif