File: high-address-dereference.c

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (50 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// On x86_64, the kernel does not provide the faulting address for dereferences
// of addresses greater than the 48-bit hardware addressable range, i.e.,
// `siginfo.si_addr` is zero in ASan's SEGV signal handler. This test checks
// that ASan does not misrepresent such cases as "NULL dereferences".

// REQUIRES: x86_64-target-arch
// RUN: %clang_asan %s -o %t
// RUN: export %env_asan_opts=print_scariness=1
// RUN: not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0
// RUN: not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0
// RUN: not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE
// RUN: not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR
// RUN: not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR

#include <stdint.h>
#include <stdlib.h>

int main(int argc, const char *argv[]) {
  const char *hex = argv[1];
  uint64_t *addr = (uint64_t *)strtoull(hex, NULL, 16);
  uint64_t x = *addr;  // segmentation fault
  return x;
}

// ZERO:  SEGV on unknown address 0x000000000000 (pc
// LOW1:  SEGV on unknown address 0x000000000fff (pc
// LOW2:  SEGV on unknown address 0x000000001000 (pc
// HIGH:  {{BUS|SEGV}} on unknown address (pc
// MAX:   {{BUS|SEGV}} on unknown address (pc

// HINT-PAGE0-NOT: Hint: this fault was caused by a dereference of a high value address
// HINT-PAGE0:     Hint: address points to the zero page.

// HINT-NONE-NOT:  Hint: this fault was caused by a dereference of a high value address
// HINT-NONE-NOT:  Hint: address points to the zero page.

// HINT-HIGHADDR:     Hint: this fault was caused by a dereference of a high value address
// HINT-HIGHADDR-NOT: Hint: address points to the zero page.

// ZERO:  SCARINESS: 10 (null-deref)
// LOW1:  SCARINESS: 10 (null-deref)
// LOW2:  SCARINESS: 20 (wild-addr-read)
// HIGH:  SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}
// MAX:   SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}

// TODO: Currently, register values are only printed on Mac.  Once this changes,
//       remove the 'TODO_' prefix in the following lines.
// TODO_HIGH,TODO_MAX: Register values:
// TODO_HIGH: = 0x4141414141414141
// TODO_MAX:  = 0xffffffffffffffff