aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/coredump.c
blob: 44e281789795553800fdb0add355a2846106656e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
 * Description: trigger segfault. A recent 6.4-rc kernel introduced a bug
 *		via vhost where segfaults for applications using io_uring
 *		would hang in D state forever upon trying to generate the
 *		core file. Perform a trivial test where a child process
 *		generates a NULL pointer dereference and ensure that we don't
 *		hang.
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

#include "liburing.h"
#include "helpers.h"

static void test(void)
{
	struct io_uring_sqe *sqe;
	struct io_uring ring;
	int *ptr = NULL;
	int fds[2];
	char r1;

	if (pipe(fds) < 0) {
		perror("pipe");
		exit(0);
	}

	io_uring_queue_init(8, &ring, 0);

	sqe = io_uring_get_sqe(&ring);
	io_uring_prep_read(sqe, fds[0], &r1, sizeof(r1), 0);
	sqe->flags = IOSQE_ASYNC;
	sqe->user_data = 1;

	io_uring_submit(&ring);
	*ptr = 0;
	exit(0);
}

int main(int argc, char *argv[])
{
	pid_t pid;
	int wstat;

	pid = fork();
	if (pid < 0) {
		perror("fork");
		return T_EXIT_SKIP;
	} else if (!pid) {
		test();
	}

	wait(&wstat);
	return T_EXIT_PASS;
}