• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * 6.10-rc merge window had a bug where the rewritten mmap support caused
4  * rings allocated with > 1 page, but asking for smaller mappings, would
5  * cause -EFAULT to be returned rather than a successful map. This hit
6  * applications either using an ancient liburing with IORING_FEAT_SINGLE_MMAP
7  * support, or application just ignoring that feature flag and still doing
8  * 3 mmap operations to map the ring.
9  */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 
14 #include "../src/syscall.h"
15 #include "liburing.h"
16 #include "helpers.h"
17 
18 #define ENTRIES	128
19 
main(int argc,char * argv[])20 int main(int argc, char *argv[])
21 {
22 	struct io_uring_params p = { };
23 	void *ptr;
24 	int fd;
25 
26 	if (argc > 1)
27 		return T_EXIT_SKIP;
28 
29 	fd = __sys_io_uring_setup(ENTRIES, &p);
30 	if (fd < 0)
31 		return T_EXIT_SKIP;
32 
33 	if (!(p.features & IORING_FEAT_SINGLE_MMAP)) {
34 		close(fd);
35 		return T_EXIT_SKIP;
36 	}
37 
38 	ptr = __sys_mmap(0, ENTRIES * sizeof(unsigned), PROT_READ | PROT_WRITE,
39 				MAP_SHARED | MAP_POPULATE, fd,
40 				IORING_OFF_SQ_RING);
41 	if (!IS_ERR(ptr)) {
42 		close(fd);
43 		return T_EXIT_PASS;
44 	}
45 
46 	fprintf(stderr, "ring sqe array mmap: %d\n", PTR_ERR(ptr));
47 	return T_EXIT_FAIL;
48 }
49