[compiler-rt] [sanitizer] Warn if allocator size exceeds max user virtual address (PR #152428)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 7 09:34:55 PDT 2025
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/152428
>From 79257323d56de59269979c6727e82886e67c7377 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 7 Aug 2025 02:16:47 +0000
Subject: [PATCH 1/3] [sanitizer] Warn if allocator size exceeds max user
virtual address
This warns the user of incompatible configurations, such as 39-bit and 42-bit VMAs for AArch64
non-Android Linux ASan (https://github.com/llvm/llvm-project/issues/145259).
---
.../sanitizer_common/sanitizer_allocator_primary64.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 51ac1b6ae4975..56d40c19b0f0c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -113,6 +113,18 @@ class SizeClassAllocator64 {
// ~(uptr)0.
void Init(s32 release_to_os_interval_ms, uptr heap_start = 0) {
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
+
+ uptr MaxAddr = GetMaxUserVirtualAddress();
+ // VReport does not call the sanitizer allocator.
+ VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
+ VReport(3, "Total space size for primary allocator: 0x%zx\n",
+ TotalSpaceSize);
+ if (TotalSpaceSize >= MaxAddr)
+ VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
+ TotalSpaceSize, MaxAddr);
+ // We can't easily adjust the requested heap size, because kSpaceSize is
+ // const (for optimization) and used throughout the code.
+
PremappedHeap = heap_start != 0;
if (PremappedHeap) {
CHECK(!kUsingConstantSpaceBeg);
>From 9b747cd9fec5e3596be73bce15d70815e307ff7b Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 7 Aug 2025 02:49:22 +0000
Subject: [PATCH 2/3] Clarify warning
---
.../sanitizer_common/sanitizer_allocator_primary64.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 56d40c19b0f0c..11fb5f5b92e17 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -119,12 +119,14 @@ class SizeClassAllocator64 {
VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
VReport(3, "Total space size for primary allocator: 0x%zx\n",
TotalSpaceSize);
- if (TotalSpaceSize >= MaxAddr)
+ if (TotalSpaceSize >= MaxAddr) {
+ // We can't easily adjust the requested heap size, because kSpaceSize is
+ // const (for optimization) and used throughout the code.
VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
TotalSpaceSize, MaxAddr);
- // We can't easily adjust the requested heap size, because kSpaceSize is
- // const (for optimization) and used throughout the code.
-
+ VReport(
+ 0, "Try using a kernel that allows a larger virtual address space\n");
+ }
PremappedHeap = heap_start != 0;
if (PremappedHeap) {
CHECK(!kUsingConstantSpaceBeg);
>From 2478b344a471cd499320b15a902f62fd96f55bfc Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 7 Aug 2025 16:34:21 +0000
Subject: [PATCH 3/3] Describe edge case with 48-bit video music awards
---
.../lib/sanitizer_common/sanitizer_allocator_primary64.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 11fb5f5b92e17..fb9981ec00344 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -119,6 +119,9 @@ class SizeClassAllocator64 {
VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
VReport(3, "Total space size for primary allocator: 0x%zx\n",
TotalSpaceSize);
+ // TODO: hypothetical edge case: on >48-bit VMA systems, Linux by default
+ // maps as if it was a 48-bit VMA, but a sanitizer could
+ // theoretically map beyond the 48-bit limit (N.B. 2**48 == 256TB).
if (TotalSpaceSize >= MaxAddr) {
// We can't easily adjust the requested heap size, because kSpaceSize is
// const (for optimization) and used throughout the code.
More information about the llvm-commits
mailing list