[LTP] [PATCH 2/3] mmap23: add test for MAP_32BIT oversized mapping

Andrea Cervesato andrea.cervesato@suse.de
Fri Aug 28 17:36:04 CEST 2026


From: Andrea Cervesato <andrea.cervesato@suse.com>

Add a test verifying that mmap() with the MAP_32BIT flag fails
with ENOMEM when requesting a mapping of size >= 2GB, since it
cannot fit within the first 2GB of address space.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/mmap/.gitignore |  1 +
 testcases/kernel/syscalls/mmap/mmap23.c   | 36 +++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 737c63e31..a264f42c8 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -890,6 +890,7 @@ mmap20 mmap20
 mmap21_01 mmap21 -m 1
 mmap21_02 mmap21
 mmap22 mmap22
+mmap23 mmap23
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
diff --git a/testcases/kernel/syscalls/mmap/.gitignore b/testcases/kernel/syscalls/mmap/.gitignore
index 075be933d..dd332e9a1 100644
--- a/testcases/kernel/syscalls/mmap/.gitignore
+++ b/testcases/kernel/syscalls/mmap/.gitignore
@@ -19,3 +19,4 @@
 /mmap20
 /mmap21
 /mmap22
+/mmap23
diff --git a/testcases/kernel/syscalls/mmap/mmap23.c b/testcases/kernel/syscalls/mmap/mmap23.c
new file mode 100644
index 000000000..4eb7bf6e9
--- /dev/null
+++ b/testcases/kernel/syscalls/mmap/mmap23.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that :manpage:`mmap(2)` with the MAP_32BIT flag fails with ENOMEM
+ * when requesting a mapping of size >= 2GB, since it cannot fit within the
+ * first 2GB of address space.
+ *
+ * MAP_32BIT is supported only on x86-64 for 64-bit programs.
+ */
+
+#include "tst_test.h"
+#include "lapi/mmap.h"
+
+#define MAP_SZ (2UL * TST_GB)
+
+static void run(void)
+{
+	TST_EXP_FAIL_PTR_VOID(mmap(NULL, MAP_SZ, PROT_READ | PROT_WRITE,
+				   MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0),
+			      ENOMEM,
+			      "mmap(2GB) with MAP_32BIT");
+
+	if (TST_RET_PTR != MAP_FAILED)
+		SAFE_MUNMAP(TST_RET_PTR, MAP_SZ);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.supported_archs = (const char *const []){
+		"x86_64",
+		NULL
+	},
+};

-- 
2.51.0



More information about the ltp mailing list