Skip to contentSkip to conversation

tests/io_uring/iouring.c: bump RLIMIT_MEMLOCK up to hard limit

PATCH In review Ondrej Mosnacek 2 participants 3 messages Aug 5 – Aug 6 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tests/io_uring/iouring.c: bump RLIMIT_MEMLOCK up to hard limit

Test domains may get their soft resource limits lowered on transition due to the typically denied rlimitinh permission. However, the resulting RLIMIT_MEMLOCK limit may not be enough to run the io_uring test program in some cases (low init task's limit + large page size, for example). Ensure that io_uring tests can run successfully in such environments as well by bumping the soft limit to the hard limit (which should be sufficient everywhere) in iouring.c.

The issue can be observed for example on CentOS Stream 9 on aarch64 or ppc64le.

Fixes 3b4e44eb3243 ("Add tests for io_uring")

---

This is an alternative (better) approach to fix the problem described in the v1 patch:
https://lore.kernel.org/selinux/[email protected]/

 tests/io_uring/iouring.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tests/io_uring/iouring.c +15 -0
index d5f9cbc..36b014f 100644
@@ -68,6 +68,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 
@@ -475,6 +476,7 @@ int main(int argc, char *argv[])
 	struct urt_config *cfg_p;
 	char *progname;
 	char *progdir;
+	struct rlimit rlim;
 
 	enum { TST_UNKNOWN,
 	       TST_SQPOLL,
@@ -500,6 +502,19 @@ int main(int argc, char *argv[])
 	progname = strdup(argv[0]);
 	progdir = dirname(progname);
 
+	/*
+	 * bump RLIMIT_MEMLOCK up to hard limit (some operations may need it,
+	 * especially if PAGE_SIZE is big)
+	 */
+	if (getrlimit(RLIMIT_MEMLOCK, &rlim))
+		fatal("getrlimit");
+
+	if (rlim.rlim_cur < rlim.rlim_max) {
+		rlim.rlim_cur = rlim.rlim_max;
+		if (setrlimit(RLIMIT_MEMLOCK, &rlim))
+			fatal("setrlimit");
+	}
+
 	snprintf(uring_path, sizeof(uring_path), "%s/iouring.out", progdir);
 
 	/* simple header */
Signature · 1 line
2.55.0
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Ondrej Mosnacek

Test domains may get their soft resource limits lowered on transition due to the typically denied rlimitinh permission. However, the resulting RLIMIT_MEMLOCK limit may not be enough to run the io_uring test program in some cases (low init task's limit + large page size, for example). Ensure that io_uring tests can run successfully in such environments as well by bumping the soft limit to the hard limit (which should be sufficient everywhere) in iouring.c.

Quoted 5 lines

The issue can be observed for example on CentOS Stream 9 on aarch64 or ppc64le.

Fixes 3b4e44eb3243 ("Add tests for io_uring")
author Applied
#2 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Ondrej Mosnacek

Test domains may get their soft resource limits lowered on transition due to the typically denied rlimitinh permission. However, the resulting RLIMIT_MEMLOCK limit may not be enough to run the io_uring test program in some cases (low init task's limit + large page size, for example). Ensure that io_uring tests can run successfully in such environments as well by bumping the soft limit to the hard limit (which should be sufficient everywhere) in iouring.c.

Quoted 7 lines
Quoted 5 lines

The issue can be observed for example on CentOS Stream 9 on aarch64 or ppc64le.

Fixes 3b4e44eb3243 ("Add tests for io_uring")

Thanks, applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/d03e89292da66e638d795c06840037d27131d82c

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.