[LTP] [PATCH v2] syscalls/munmap04: Increase target map address in case of EEXIST

Ricardo B. Marlière rbm@suse.com
Thu Jul 31 13:18:01 CEST 2025


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

While trying to exhaust the amount of VMAs, the test should bump the
address for the next try in case of EEXIST. Otherwise, it might timeout in
an infinite loop.

Fixes: 7f70db39ec45 ("syscalls/munmap04: Check errno while trying to exhaust VMA count")
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
Changes in v2:
- Use `goto` instead of `continue`.
- Link to v1: https://lore.kernel.org/r/20250731-fixes-munmap04-v1-1-995c33b79fee@suse.com
---
 testcases/kernel/syscalls/munmap/munmap04.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/munmap/munmap04.c b/testcases/kernel/syscalls/munmap/munmap04.c
index aeb905286e9d4214ac6423ef26e9570674b60530..987a7c7e7a95e15622e91dc3c777b06070736145 100644
--- a/testcases/kernel/syscalls/munmap/munmap04.c
+++ b/testcases/kernel/syscalls/munmap/munmap04.c
@@ -28,6 +28,8 @@ static void run(void)
 
 static void setup(void)
 {
+	uintptr_t addr = base;
+
 	page_sz = SAFE_SYSCONF(_SC_PAGESIZE);
 	vma_size = MEMSIZE * page_sz;
 
@@ -36,15 +38,17 @@ static void setup(void)
 		maps[i] = NULL;
 
 	while (1) {
-		void *p = mmap((void *)(base + PAD * vma_size * map_count),
+		void *p = mmap((void *) addr,
 			     vma_size, PROT_NONE,
 			     MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
 			     -1, 0);
 		if (p == MAP_FAILED && errno == EEXIST)
-			continue;
+			goto next_addr;
 		if (p == MAP_FAILED)
 			break;
 		maps[map_count++] = p;
+next_addr:
+		addr += PAD * vma_size;
 	}
 
 	if (map_count == MAP_MAX_COUNT)

---
base-commit: 91fa413eb521fde80d57c79bd3d2fb5cbe4ad3f4
change-id: 20250728-fixes-munmap04-02083c550c6b

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



More information about the ltp mailing list