[LTP] [PATCH v2] syscalls/munmap04: Check errno while trying to exhaust VMA count

Ricardo B. Marlière rbm@suse.com
Mon Jul 28 16:23:17 CEST 2025


From: Ricardo B. Marlière <rbm@suse.com>

In the loop that exhausts the amount of VMAs we must check not only for
MAP_FAILED return from mmap() but also if the error was EEXIST. In that
case, keep retrying with increasing addresses. While at it, add a sanity
check if no regions were mapped.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://lore.kernel.org/r/20250728-fixes-munmap04-v1-1-e32ef11d594a@suse.com
---
 testcases/kernel/syscalls/munmap/munmap04.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/munmap/munmap04.c b/testcases/kernel/syscalls/munmap/munmap04.c
index e046d17a75f8f75c5b11d569c33da41d7adc7d09..aeb905286e9d4214ac6423ef26e9570674b60530 100644
--- a/testcases/kernel/syscalls/munmap/munmap04.c
+++ b/testcases/kernel/syscalls/munmap/munmap04.c
@@ -40,14 +40,17 @@ static void setup(void)
 			     vma_size, PROT_NONE,
 			     MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
 			     -1, 0);
+		if (p == MAP_FAILED && errno == EEXIST)
+			continue;
 		if (p == MAP_FAILED)
 			break;
 		maps[map_count++] = p;
 	}
 
 	if (map_count == MAP_MAX_COUNT)
-		tst_brk(TBROK, "Mapped all %d regions, expected less",
-			map_count);
+		tst_brk(TBROK, "Mapped all %d regions, expected less", map_count);
+	if (map_count == 0)
+		tst_brk(TBROK, "Mapped 0 regions");
 
 	tst_res(TINFO, "Mapped %d regions", map_count);
 }

---
base-commit: 6af619552ce7676171e47b88964ffb5b08499b36
change-id: 20250728-fixes-munmap04-02083c550c6b

Best regards,
-- 
Ricardo B. Marlière <rbm@suse.com>



More information about the ltp mailing list