diff options
author | Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> | 2016-09-23 16:40:05 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-09-27 03:48:58 -0400 |
commit | 973d94d8a87c32661f1308a118074972ac5d483a (patch) | |
tree | 594eeceac135ae0914ac7f6995bf60cbe008ffa4 /samples/bpf | |
parent | 2b064fff8527a1052c7060c65c22cae80a9343b9 (diff) |
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 <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf')
-rw-r--r-- | samples/bpf/tracex5_kern.c | 16 | ||||
-rw-r--r-- | samples/bpf/tracex5_user.c | 3 |
2 files changed, 10 insertions, 9 deletions
diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c index f95f232cbab9..fd12d7154d42 100644 --- a/samples/bpf/tracex5_kern.c +++ b/samples/bpf/tracex5_kern.c | |||
@@ -19,20 +19,18 @@ struct bpf_map_def SEC("maps") progs = { | |||
19 | .max_entries = 1024, | 19 | .max_entries = 1024, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | SEC("kprobe/seccomp_phase1") | 22 | SEC("kprobe/__seccomp_filter") |
23 | int bpf_prog1(struct pt_regs *ctx) | 23 | int bpf_prog1(struct pt_regs *ctx) |
24 | { | 24 | { |
25 | struct seccomp_data sd; | 25 | int sc_nr = (int)PT_REGS_PARM1(ctx); |
26 | |||
27 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); | ||
28 | 26 | ||
29 | /* dispatch into next BPF program depending on syscall number */ | 27 | /* 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); |
31 | 29 | ||
32 | /* fall through -> unknown syscall */ | 30 | /* fall through -> unknown syscall */ |
33 | if (sd.nr >= __NR_getuid && sd.nr <= __NR_getsid) { | 31 | if (sc_nr >= __NR_getuid && sc_nr <= __NR_getsid) { |
34 | char fmt[] = "syscall=%d (one of get/set uid/pid/gid)\n"; | 32 | 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); |
36 | } | 34 | } |
37 | return 0; | 35 | return 0; |
38 | } | 36 | } |
@@ -42,7 +40,7 @@ PROG(__NR_write)(struct pt_regs *ctx) | |||
42 | { | 40 | { |
43 | struct seccomp_data sd; | 41 | struct seccomp_data sd; |
44 | 42 | ||
45 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); | 43 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); |
46 | if (sd.args[2] == 512) { | 44 | if (sd.args[2] == 512) { |
47 | char fmt[] = "write(fd=%d, buf=%p, size=%d)\n"; | 45 | char fmt[] = "write(fd=%d, buf=%p, size=%d)\n"; |
48 | bpf_trace_printk(fmt, sizeof(fmt), | 46 | bpf_trace_printk(fmt, sizeof(fmt), |
@@ -55,7 +53,7 @@ PROG(__NR_read)(struct pt_regs *ctx) | |||
55 | { | 53 | { |
56 | struct seccomp_data sd; | 54 | struct seccomp_data sd; |
57 | 55 | ||
58 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); | 56 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); |
59 | if (sd.args[2] > 128 && sd.args[2] <= 1024) { | 57 | if (sd.args[2] > 128 && sd.args[2] <= 1024) { |
60 | char fmt[] = "read(fd=%d, buf=%p, size=%d)\n"; | 58 | char fmt[] = "read(fd=%d, buf=%p, size=%d)\n"; |
61 | bpf_trace_printk(fmt, sizeof(fmt), | 59 | bpf_trace_printk(fmt, sizeof(fmt), |
diff --git a/samples/bpf/tracex5_user.c b/samples/bpf/tracex5_user.c index a04dd3cd4358..36b5925bb137 100644 --- a/samples/bpf/tracex5_user.c +++ b/samples/bpf/tracex5_user.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <sys/prctl.h> | 6 | #include <sys/prctl.h> |
7 | #include "libbpf.h" | 7 | #include "libbpf.h" |
8 | #include "bpf_load.h" | 8 | #include "bpf_load.h" |
9 | #include <sys/resource.h> | ||
9 | 10 | ||
10 | /* install fake seccomp program to enable seccomp code path inside the kernel, | 11 | /* install fake seccomp program to enable seccomp code path inside the kernel, |
11 | * so that our kprobe attached to seccomp_phase1() can be triggered | 12 | * so that our kprobe attached to seccomp_phase1() can be triggered |
@@ -27,8 +28,10 @@ int main(int ac, char **argv) | |||
27 | { | 28 | { |
28 | FILE *f; | 29 | FILE *f; |
29 | char filename[256]; | 30 | char filename[256]; |
31 | struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; | ||
30 | 32 | ||
31 | snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); | 33 | snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); |
34 | setrlimit(RLIMIT_MEMLOCK, &r); | ||
32 | 35 | ||
33 | if (load_bpf_file(filename)) { | 36 | if (load_bpf_file(filename)) { |
34 | printf("%s", bpf_log_buf); | 37 | printf("%s", bpf_log_buf); |