Skip to contentSkip to conversation

syscalls/munmap04: Check errno while trying to exhaust VMA count

PATCH Superseded Ricardo B. Marlière via ltp 2 participants 3 messages Jul 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 syscalls/munmap04: Check errno while trying to exhaust VMA count

From: Ricardo B. Marlière <[email protected]>

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.

---
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/[email protected]

---
 testcases/kernel/syscalls/munmap/munmap04.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/munmap/munmap04.c +5 -2
index e046d17a75f8f75c5b11d569c33da41d7adc7d09..aeb905286e9d4214ac6423ef26e9570674b60530 100644
@@ -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,

Signature · 5 lines
Ricardo B. Marlière <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw
Quoted 7 lines · Ricardo B. Marlière

From: Ricardo B. Marlière <[email protected]>

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.

Quoted 7 lines

---
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/[email protected]

Oops, forgot to edit this:

Changes in v2:
- Check for errno == EEXIST instead of removing MAP_FIXED_NOREPLACE flag

Quoted 34 lines
---
 testcases/kernel/syscalls/munmap/munmap04.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/munmap/munmap04.c +5 -3
index e046d17a75f8f75c5b11d569c33da41d7adc7d09..aeb905286e9d4214ac6423ef26e9570674b60530 100644
@@ -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,

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp