1 // Regression test for https://crbug.com/502974, where ASan was unable to read
2 // the binary name because of sandbox restrictions.
3 // This test uses seccomp-BPF to restrict the readlink() system call and makes
4 // sure ASan is still able to
5 // Disable symbolizing results, since this will invoke llvm-symbolizer, which
6 // will be unable to resolve its $ORIGIN due to readlink() restriction and will
7 // thus fail to start, causing the test to die with SIGPIPE when attempting to
9 // RUN: not ls /usr/include/linux/seccomp.h || ( %clang_asan %s -o %t && ( not env ASAN_OPTIONS=symbolize=0 %run %t 2>&1 ) | FileCheck %s )
11 // UNSUPPORTED: android
17 #include <sys/prctl.h>
18 #include <sys/syscall.h>
19 #include <linux/filter.h>
20 #include <linux/seccomp.h>
23 # define __NR_readlink __NR_readlinkat
26 #define syscall_nr (offsetof(struct seccomp_data, nr))
35 prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0);
37 struct sock_filter filter
[] = {
38 /* Grab the system call number */
39 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, syscall_nr
),
40 // If this is __NR_readlink,
41 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_readlink
, 0, 1),
43 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ERRNO
| EPERM
),
44 // otherwise allow the syscall.
45 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ALLOW
)
47 struct sock_fprog prog
;
48 prog
.len
= (unsigned short)(sizeof(filter
)/sizeof(filter
[0]));
51 int res
= prctl(PR_SET_SECCOMP
, SECCOMP_MODE_FILTER
, &prog
, 0, 0);
53 fprintf(stderr
, "PR_SET_SECCOMP unsupported!\n");
56 // CHECK: AddressSanitizer
57 // CHECK-NOT: reading executable name failed