Skip to content

Commit 144dae2

Browse files
authored
[hwasan] Report unavalible fixed shadow range (llvm#98574)
Before the patch `fixed-shadow.c` test died with an obscure SEGV, because shadow was mapped over libc.so. Note, FindDynamicShadowStart is expected to select in available region.
1 parent 076ae58 commit 144dae2

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ static void InitializeShadowBaseAddress(uptr shadow_size_bytes) {
109109
// FIXME: Android should init flags before shadow.
110110
if (!SANITIZER_ANDROID && flags()->fixed_shadow_base != (uptr)-1) {
111111
__hwasan_shadow_memory_dynamic_address = flags()->fixed_shadow_base;
112+
uptr beg = __hwasan_shadow_memory_dynamic_address;
113+
uptr end = beg + shadow_size_bytes;
114+
if (!MemoryRangeIsAvailable(beg, end)) {
115+
Report(
116+
"FATAL: HWAddressSanitizer: Shadow range %p-%p is not available.\n",
117+
(void *)beg, (void *)end);
118+
DumpProcessMap();
119+
CHECK(MemoryRangeIsAvailable(beg, end));
120+
}
112121
} else {
113122
__hwasan_shadow_memory_dynamic_address =
114123
FindDynamicShadowStart(shadow_size_bytes);

compiler-rt/test/hwasan/TestCases/Linux/fixed-shadow.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// Test fixed shadow base functionality.
22
//
33
// Default compiler instrumentation works with any shadow base (dynamic or fixed).
4-
// RUN: %clang_hwasan %s -o %t && %run %t
5-
// RUN: %clang_hwasan %s -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t
6-
// RUN: %clang_hwasan %s -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
4+
// RUN: %clang_hwasan %s -o %t
5+
// RUN: %run %t
6+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
7+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
78
//
89
// If -hwasan-mapping-offset is set, then the fixed_shadow_base needs to match.
9-
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t
10-
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
11-
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 not %run %t
12-
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 not %run %t
10+
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t
11+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
12+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 not %run %t
13+
14+
// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t
15+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
16+
// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 not %run %t
1317
//
1418
// Note: if fixed_shadow_base is not set, compiler-rt will dynamically choose a
1519
// shadow base, which has a tiny but non-zero probability of matching the
@@ -22,8 +26,7 @@
2226
//
2327
// UNSUPPORTED: android
2428

25-
// FIXME: SEGV on Ubuntu 24.04. Looking.
26-
// UNSUPPORTED: linux
29+
// CHECK: FATAL: HWAddressSanitizer: Shadow range {{.*}} is not available
2730

2831
#include <assert.h>
2932
#include <sanitizer/allocator_interface.h>

0 commit comments

Comments
 (0)