Skip to content

Commit 9dad441

Browse files
committed
[compiler-rt] prctl interception update, SECCOMP_MODE_FILTER support.
1 parent dbb03f8 commit 9dad441

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,9 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12561256
static const int PR_SCHED_CORE = 62;
12571257
static const int PR_SCHED_CORE_GET = 0;
12581258
static const int PR_GET_PDEATHSIG = 2;
1259+
static const int PR_SET_SECCOMP = 22;
1260+
1261+
static const int SECCOMP_MODE_FILTER = 2;
12591262
if (option == PR_SET_VMA && arg2 == 0UL) {
12601263
char *name = (char *)arg5;
12611264
COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1);
@@ -1274,6 +1277,8 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12741277
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg5), sizeof(u64));
12751278
} else if (res != -1 && option == PR_GET_PDEATHSIG) {
12761279
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(int));
1280+
} else if (res != -1 && option == PR_SET_SECCOMP && arg2 == SECCOMP_MODE_FILTER) {
1281+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg3), struct_sock_fprog_sz);
12771282
}
12781283
return res;
12791284
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct user_fpregs elf_fpregset_t;
117117
#if SANITIZER_LINUX
118118
#if SANITIZER_GLIBC
119119
#include <fstab.h>
120+
#include <linux/filter.h>
120121
#include <net/if_ppp.h>
121122
#include <netax25/ax25.h>
122123
#include <netipx/ipx.h>
@@ -531,6 +532,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
531532

532533
unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info);
533534
unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats);
535+
unsigned struct_sock_fprog_sz = sizeof(struct sock_fprog);
534536
#endif // SANITIZER_GLIBC
535537

536538
#if !SANITIZER_ANDROID && !SANITIZER_APPLE

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ extern unsigned struct_serial_struct_sz;
10501050
extern unsigned struct_sockaddr_ax25_sz;
10511051
extern unsigned struct_unimapdesc_sz;
10521052
extern unsigned struct_unimapinit_sz;
1053+
extern unsigned struct_sock_fprog_sz;
10531054
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
10541055

10551056
extern const unsigned long __sanitizer_bufsiz;

compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <assert.h>
66
#include <errno.h>
7+
#include <linux/filter.h>
8+
#include <linux/seccomp.h>
79
#include <stdint.h>
810
#include <string.h>
911
#include <sys/mman.h>
@@ -78,5 +80,20 @@ int main() {
7880
}
7981
}
8082

83+
sock_filter f[] = {{
84+
.code = (BPF_LD|BPF_W|BPF_ABS),
85+
.k = (uint32_t)(SKF_AD_OFF | SKF_AD_CPU)
86+
},{
87+
.code = (BPF_RET|BPF_A),
88+
.k = 0
89+
}};
90+
sock_fprog pr = {
91+
.len = 2,
92+
.filter = f
93+
};
94+
95+
res = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &pr);
96+
assert(res == -1);
97+
8198
return 0;
8299
}

0 commit comments

Comments
 (0)