mmap testing suite to cover MAP_32BIT
v3 cover mmap testing suite to cover MAP_32BIT
Create two new tests to verify MAP_32BIT functionality:
- mmap23: verify if it fails with invalid parameters
- mmap24: verify bondaries of the allocation
---
Changes in v3:
- switch to PROT_NONE and drop memory writes to avoid physical allocation and commit limits
- add unrestricted control mmap() on ENOMEM to detect generic memory exhaustion
- fix format warnings on 32-bit builds by replacing %zu with %lu
- use TESTPTR macro instead of bare mmap() calls
Changes in v2:
- fix description
- Link to v1: https://lore.kernel.org/[email protected]
---
Andrea Cervesato (3):
lapi/mmap: add MAP_32BIT fallback
mmap23: add test for MAP_32BIT oversized mapping
mmap24: add test for MAP_32BIT address limit
include/lapi/mmap.h | 4 ++ runtest/syscalls | 2 + testcases/kernel/syscalls/mmap/.gitignore | 2 + testcases/kernel/syscalls/mmap/mmap23.c | 36 ++++++++++ testcases/kernel/syscalls/mmap/mmap24.c | 112 ++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+)
---
base-commit: f6933a16f304f36045ec39300c6496dae452933d
change-id: 20260827-mmap_32bit_coverage-09a22407aa39
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/3 lapi/mmap: add MAP_32BIT fallback
From: Andrea Cervesato <[email protected]>
--- include/lapi/mmap.h | 4 ++++ 1 file changed, 4 insertions(+)
include/lapi/mmap.h +4 -0
@@ -91,6 +91,10 @@# define MAP_DROPPABLE 0x08#endif +#ifndef MAP_32BIT +# define MAP_32BIT 0x40 +#endif +#ifndef MREMAP_DONTUNMAP # define MREMAP_DONTUNMAP 4#endif
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lapi/mmap: add MAP_32BIT fallback
Hi Andrea,
Quoted 1 line · Andrea Cervesato
lapi/mmap: add
MAP_32BITfallback
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/3] lapi/mmap: add MAP_32BIT fallback
In reply to Andrea CervesatoSignature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/3 mmap23: add test for MAP_32BIT oversized mapping
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
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.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mmap/.gitignore | 1 + testcases/kernel/syscalls/mmap/mmap23.c | 36 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+)
runtest/syscalls +1 -0
@@ -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
testcases/kernel/syscalls/mmap/.gitignore +1 -0
@@ -19,3 +19,4 @@ /mmap20 /mmap21 /mmap22 +/mmap23
testcases/kernel/syscalls/mmap/mmap23.c new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* 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 + }, +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/3] mmap23: add test for MAP_32BIT oversized mapping
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 3/3 mmap24: add test for MAP_32BIT address limit
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add a test verifying that mmap() with the MAP_32BIT flag restricts mappings to the first 2GB of address space and fails with ENOMEM when the 32-bit address space is exhausted without falling back to higher addresses.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mmap/.gitignore | 1 + testcases/kernel/syscalls/mmap/mmap24.c | 112 ++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+)
runtest/syscalls +1 -0
@@ -891,6 +891,7 @@ mmap21_01 mmap21 -m 1 mmap21_02 mmap21 mmap22 mmap22 mmap23 mmap23 +mmap24 mmap24 modify_ldt01 modify_ldt01 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
@@ -20,3 +20,4 @@ /mmap21 /mmap22 /mmap23 +/mmap24
testcases/kernel/syscalls/mmap/mmap24.c new file +112 -0
112 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 3/3] mmap24: add test for MAP_32BIT address limit
Quoted 8 lines
+/*\
+ * Verify that :manpage:mmap(2)with theMAP_32BITflag restricts all mappings
+ * to the first 2GB of the process address space (<0x80000000).
+ *
+ *MAP_32BITis supported only on x86-64 for 64-bit programs.
+ *
+ * UsePROT_NONEto test address placement without allocating data pages
+ * or charging private writable memory against the commit limit.
This test itself looks good, but unlike the address placement way, maybe we can create a new test (mmap25.c) that allocates real read-write anonymous memory, writes a pattern, reads it back, and checks the result.
This verifies that read-write memory mapped with MAP_32BIT functions correctly.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 3/3] mmap24: add test for MAP_32BIT address limit
In reply to Andrea CervesatoHi Andrea,
Thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp