[PATCH v2] support: Align the repeated blob mappings to SHMLBA
Stian Halseth
stian@itx.no
Tue Nov 3 10:47:36 GMT 2026
allocate_big reserves the region with a private anonymous mapping,
which is only page aligned, and then maps the backing file over it
with MAP_FIXED | MAP_SHARED. A shared mapping has to be aligned to
SHMLBA, which is 16 KiB on sparc64 against an 8 KiB page, so the
mapping fails with EINVAL whenever the reservation lands on an odd
page. stdlib/test-bz22786 then crashes on the NULL start, and
stdlib/tst-strtod-overflow and string/tst-memmove-overflow report
UNSUPPORTED.
Reserve the region with MAP_SHARED, which the kernel aligns to SHMLBA,
and make the stride a multiple of SHMLBA so that every shared alias is
aligned too.
Tested on sparc64 and x86_64.
Signed-off-by: Stian Halseth <stian@itx.no>
---
support/blob_repeat.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 6f3fe64cec..c88b4a49f8 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -27,6 +27,7 @@
#include <support/support.h>
#include <support/xunistd.h>
#include <sys/mman.h>
+#include <sys/shm.h>
#include <unistd.h>
#include <wchar.h>
@@ -145,14 +146,19 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
stride_size
= ((maximum_small_size + stride_size - 1) / stride_size) * stride_size;
+ /* The file mappings below are shared and must be aligned to SHMLBA. */
+ while (stride_size % SHMLBA != 0)
+ stride_size += minimum_stride_size (page_size, element_size);
+
if (stride_size > total_size)
/* The mmap optimization would not save anything. */
return allocate_malloc (total_size, element, element_size, count);
/* Reserve the memory region. If we cannot create the mapping,
- there is no reason to set up the backing file. */
+ there is no reason to set up the backing file. MAP_SHARED makes
+ the kernel align the reservation to SHMLBA. */
void *target = mmap (NULL, total_size, PROT_NONE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ MAP_ANONYMOUS | MAP_SHARED | MAP_NORESERVE, -1, 0);
if (target == MAP_FAILED)
return (struct support_blob_repeat) {};
--
2.43.0
More information about the Libc-alpha
mailing list