1// REQUIRES: x86_64-target-arch
2// RUN: %clangxx_asan %s -o %t
3// RUN: not %run %t 2>&1 | FileCheck %s
4#include <sanitizer/common_interface_defs.h>
5#include <sched.h>
6#include <unistd.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10int main() {
11 __sanitizer_sandbox_arguments args = {.coverage_sandboxed: 0};
12 // should cache /proc/self/maps
13 __sanitizer_sandbox_on_notify(args: &args);
14
15 if (unshare(CLONE_NEWUSER)) {
16 printf(format: "unshare failed\n");
17 return 1;
18 }
19
20 // remove access to /proc/self/maps
21 if (chroot(path: "/tmp")) {
22 printf(format: "chroot failed\n");
23 return 2;
24 }
25
26 *(volatile int*)0x42 = 0;
27// CHECK-NOT: CHECK failed
28}
29

source code of compiler-rt/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cpp