diff mbox series

[v1,15/17] selftests/nolibc: vfprintf: silence memfd_create() warning

Message ID f0bbf3a7920d86ff37edab5f0c085cb0afb5d8b9.1687344643.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series selftests/nolibc: allow run with minimal kernel config | expand

Commit Message

Zhangjin Wu June 21, 2023, 1:17 p.m. UTC
pass MFD_NOEXEC_SEAL flag to memfd_create() to silence this kernel
warning inserted in the middle of the whole test result:

    memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1

The mixed test result looks this:

    Running test 'vfprintf'
    0 emptymemfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'init'
     "" = ""                                                  [OK]

From v6.2, MFD_NOEXEC_SEAL must be passed for the non-executable memfd.

Since MFD_NOEXEC_SEAL is a whole new flag, to avoid adding ugly #ifdef
macros, let's use magic number here directly.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 19e4ef5ce578..8b1ce9911c5c 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -774,7 +774,17 @@  static int expect_vfprintf(int llen, size_t c, const char *expected, const char
 	FILE *memfile;
 	va_list args;
 
-	fd = memfd_create("vfprintf", 0);
+	/* silence warning for kernel >= v6.2:
+	 *
+	 *   "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=<pid>"
+	 *
+	 * try MFD_NOEXEC_SEAL (0x0008U) flag for kernels >= v6.2, error means
+	 * the kernel is too old and require old flags
+	 */
+	fd = memfd_create("vfprintf", 0x0008U);
+	if (fd == -1)
+		fd = memfd_create("vfprintf", 0);
+
 	if (fd == -1) {
 		pad_spc(llen, 64, "[FAIL]\n");
 		return 1;