xref: /llvm-project/compiler-rt/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cpp (revision 673dc3d4a0b0fbb3b9b34ae2ecbfa522627fe582)
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 
main()10 int main() {
11   __sanitizer_sandbox_arguments args = {0};
12   // should cache /proc/self/maps
13   __sanitizer_sandbox_on_notify(&args);
14 
15   if (unshare(CLONE_NEWUSER)) {
16     printf("unshare failed\n");
17     return 1;
18   }
19 
20   // remove access to /proc/self/maps
21   if (chroot("/tmp")) {
22     printf("chroot failed\n");
23     return 2;
24   }
25 
26   *(volatile int*)0x42 = 0;
27 // CHECK-NOT: CHECK failed
28 }
29