Skip to content

Commit 973d94d

Browse files
rnavdavem330
authored andcommitted
bpf samples: update tracex5 sample to use __seccomp_filter
seccomp_phase1() does not exist anymore. Instead, update sample to use __seccomp_filter(). While at it, set max locked memory to unlimited. Signed-off-by: Naveen N. Rao <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2b064ff commit 973d94d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

samples/bpf/tracex5_kern.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ struct bpf_map_def SEC("maps") progs = {
1919
.max_entries = 1024,
2020
};
2121

22-
SEC("kprobe/seccomp_phase1")
22+
SEC("kprobe/__seccomp_filter")
2323
int bpf_prog1(struct pt_regs *ctx)
2424
{
25-
struct seccomp_data sd;
26-
27-
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
25+
int sc_nr = (int)PT_REGS_PARM1(ctx);
2826

2927
/* dispatch into next BPF program depending on syscall number */
30-
bpf_tail_call(ctx, &progs, sd.nr);
28+
bpf_tail_call(ctx, &progs, sc_nr);
3129

3230
/* fall through -> unknown syscall */
33-
if (sd.nr >= __NR_getuid && sd.nr <= __NR_getsid) {
31+
if (sc_nr >= __NR_getuid && sc_nr <= __NR_getsid) {
3432
char fmt[] = "syscall=%d (one of get/set uid/pid/gid)\n";
35-
bpf_trace_printk(fmt, sizeof(fmt), sd.nr);
33+
bpf_trace_printk(fmt, sizeof(fmt), sc_nr);
3634
}
3735
return 0;
3836
}
@@ -42,7 +40,7 @@ PROG(__NR_write)(struct pt_regs *ctx)
4240
{
4341
struct seccomp_data sd;
4442

45-
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
43+
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
4644
if (sd.args[2] == 512) {
4745
char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
4846
bpf_trace_printk(fmt, sizeof(fmt),
@@ -55,7 +53,7 @@ PROG(__NR_read)(struct pt_regs *ctx)
5553
{
5654
struct seccomp_data sd;
5755

58-
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
56+
bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
5957
if (sd.args[2] > 128 && sd.args[2] <= 1024) {
6058
char fmt[] = "read(fd=%d, buf=%p, size=%d)\n";
6159
bpf_trace_printk(fmt, sizeof(fmt),

samples/bpf/tracex5_user.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <sys/prctl.h>
77
#include "libbpf.h"
88
#include "bpf_load.h"
9+
#include <sys/resource.h>
910

1011
/* install fake seccomp program to enable seccomp code path inside the kernel,
1112
* so that our kprobe attached to seccomp_phase1() can be triggered
@@ -27,8 +28,10 @@ int main(int ac, char **argv)
2728
{
2829
FILE *f;
2930
char filename[256];
31+
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
3032

3133
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
34+
setrlimit(RLIMIT_MEMLOCK, &r);
3235

3336
if (load_bpf_file(filename)) {
3437
printf("%s", bpf_log_buf);

0 commit comments

Comments
 (0)