Skip to content

Commit b75174d

Browse files
authored
[compiler-rt] prctl interception update, SECCOMP_MODE_FILTER support. (#107722)
1 parent 4b96400 commit b75174d

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,9 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12891289
static const int PR_SCHED_CORE = 62;
12901290
static const int PR_SCHED_CORE_GET = 0;
12911291
static const int PR_GET_PDEATHSIG = 2;
1292+
static const int PR_SET_SECCOMP = 22;
1293+
1294+
static const int SECCOMP_MODE_FILTER = 2;
12921295
if (option == PR_SET_VMA && arg2 == 0UL) {
12931296
char *name = (char *)arg5;
12941297
COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1);
@@ -1307,6 +1310,9 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
13071310
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg5), sizeof(u64));
13081311
} else if (res != -1 && option == PR_GET_PDEATHSIG) {
13091312
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(int));
1313+
} else if (res != -1 && option == PR_SET_SECCOMP &&
1314+
arg2 == SECCOMP_MODE_FILTER) {
1315+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg3), struct_sock_fprog_sz);
13101316
}
13111317
return res;
13121318
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@ typedef struct user_fpregs elf_fpregset_t;
117117
#if SANITIZER_LINUX
118118
#if SANITIZER_GLIBC
119119
#include <fstab.h>
120-
#include <net/if_ppp.h>
121-
#include <netax25/ax25.h>
122-
#include <netipx/ipx.h>
123-
#include <netrom/netrom.h>
124-
#include <obstack.h>
125-
#if HAVE_RPC_XDR_H
126-
# include <rpc/xdr.h>
127-
#endif
128-
#include <scsi/scsi.h>
120+
# include <linux/filter.h>
121+
# include <net/if_ppp.h>
122+
# include <netax25/ax25.h>
123+
# include <netipx/ipx.h>
124+
# include <netrom/netrom.h>
125+
# include <obstack.h>
126+
# if HAVE_RPC_XDR_H
127+
# include <rpc/xdr.h>
128+
# endif
129+
# include <scsi/scsi.h>
129130
#else
130131
#include <linux/if_ppp.h>
131132
#include <linux/kd.h>
@@ -531,9 +532,10 @@ 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);
534-
#endif // SANITIZER_GLIBC
535+
unsigned struct_sock_fprog_sz = sizeof(struct sock_fprog);
536+
# endif // SANITIZER_GLIBC
535537

536-
#if !SANITIZER_ANDROID && !SANITIZER_APPLE
538+
# if !SANITIZER_ANDROID && !SANITIZER_APPLE
537539
unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req);
538540
unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
539541
#endif

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ 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-
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
1053+
extern unsigned struct_sock_fprog_sz;
1054+
# endif // SANITIZER_LINUX && !SANITIZER_ANDROID
10541055

10551056
extern const unsigned long __sanitizer_bufsiz;
10561057

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

Lines changed: 10 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,13 @@ int main() {
7880
}
7981
}
8082

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

0 commit comments

Comments
 (0)