1 // On x86_64, the kernel does not provide the faulting address for dereferences
2 // of addresses greater than the 48-bit hardware addressable range, i.e.,
3 // `siginfo.si_addr` is zero in ASan's SEGV signal handler. This test checks
4 // that ASan does not misrepresent such cases as "NULL dereferences".
5 
6 // REQUIRES: x86_64-target-arch
7 // RUN: %clang_asan %s -o %t
8 // RUN: export %env_asan_opts=print_scariness=1
9 // RUN: not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0
10 // RUN: not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0
11 // RUN: not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE
12 // RUN: not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR
13 // RUN: not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR
14 
15 #include <stdint.h>
16 #include <stdlib.h>
17 
main(int argc,const char * argv[])18 int main(int argc, const char *argv[]) {
19   const char *hex = argv[1];
20   uint64_t *addr = (uint64_t *)strtoull(hex, NULL, 16);
21   uint64_t x = *addr;  // segmentation fault
22   return x;
23 }
24 
25 // ZERO:  SEGV on unknown address 0x000000000000 (pc
26 // LOW1:  SEGV on unknown address 0x000000000fff (pc
27 // LOW2:  SEGV on unknown address 0x000000001000 (pc
28 // HIGH:  {{BUS|SEGV}} on unknown address (pc
29 // MAX:   {{BUS|SEGV}} on unknown address (pc
30 
31 // HINT-PAGE0-NOT: Hint: this fault was caused by a dereference of a high value address
32 // HINT-PAGE0:     Hint: address points to the zero page.
33 
34 // HINT-NONE-NOT:  Hint: this fault was caused by a dereference of a high value address
35 // HINT-NONE-NOT:  Hint: address points to the zero page.
36 
37 // HINT-HIGHADDR:     Hint: this fault was caused by a dereference of a high value address
38 // HINT-HIGHADDR-NOT: Hint: address points to the zero page.
39 
40 // ZERO:  SCARINESS: 10 (null-deref)
41 // LOW1:  SCARINESS: 10 (null-deref)
42 // LOW2:  SCARINESS: 20 (wild-addr-read)
43 // HIGH:  SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}
44 // MAX:   SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}
45 
46 // TODO: Currently, register values are only printed on Mac.  Once this changes,
47 //       remove the 'TODO_' prefix in the following lines.
48 // TODO_HIGH,TODO_MAX: Register values:
49 // TODO_HIGH: = 0x4141414141414141
50 // TODO_MAX:  = 0xffffffffffffffff
51