[LTP] [PATCH] syscalls/munmap04: Increase target map address in case of EEXIST
Andrea Cervesato
andrea.cervesato@suse.com
Thu Jul 31 13:14:09 CEST 2025
Hi!
On 7/31/25 11:51 AM, Ricardo B. Marlière via ltp wrote:
> 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>
> ---
> testcases/kernel/syscalls/munmap/munmap04.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/munmap/munmap04.c b/testcases/kernel/syscalls/munmap/munmap04.c
> index aeb905286e9d4214ac6423ef26e9570674b60530..106f99e27f813130558f5f51707642f22b1892e2 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,18 @@ 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)
> + if (p == MAP_FAILED && errno == EEXIST) {
> + addr += PAD * vma_size;
> continue;
Here you can do instead:
goto next_addr;
> + }
> if (p == MAP_FAILED)
> break;
> maps[map_count++] = p;
And here we add the goto label, so we won't increment addr variable in
the same way in two different places:
next_addr:
> + addr += PAD * vma_size;
> }
>
> if (map_count == MAP_MAX_COUNT)
>
> ---
> base-commit: 91fa413eb521fde80d57c79bd3d2fb5cbe4ad3f4
> change-id: 20250728-fixes-munmap04-02083c550c6b
>
> Best regards,
- Andrea
More information about the ltp
mailing list