* [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3
@ 2016-09-23 20:40 Naveen N. Rao
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Naveen N. Rao @ 2016-09-23 20:40 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, netdev, David S. Miller
Cc: Michael Ellerman, Alexei Starovoitov, Daniel Borkmann,
Ananth N Mavinakayanahalli
These samples fail to compile as 'struct flow_keys' conflicts with
definition in net/flow_dissector.h. Fix the same by renaming the
structure used in the sample.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
samples/bpf/sockex2_kern.c | 10 +++++-----
samples/bpf/sockex3_kern.c | 8 ++++----
samples/bpf/sockex3_user.c | 4 ++--
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/samples/bpf/sockex2_kern.c b/samples/bpf/sockex2_kern.c
index ba0e177..44e5846 100644
--- a/samples/bpf/sockex2_kern.c
+++ b/samples/bpf/sockex2_kern.c
@@ -14,7 +14,7 @@ struct vlan_hdr {
__be16 h_vlan_encapsulated_proto;
};
-struct flow_keys {
+struct bpf_flow_keys {
__be32 src;
__be32 dst;
union {
@@ -59,7 +59,7 @@ static inline __u32 ipv6_addr_hash(struct __sk_buff *ctx, __u64 off)
}
static inline __u64 parse_ip(struct __sk_buff *skb, __u64 nhoff, __u64 *ip_proto,
- struct flow_keys *flow)
+ struct bpf_flow_keys *flow)
{
__u64 verlen;
@@ -83,7 +83,7 @@ static inline __u64 parse_ip(struct __sk_buff *skb, __u64 nhoff, __u64 *ip_proto
}
static inline __u64 parse_ipv6(struct __sk_buff *skb, __u64 nhoff, __u64 *ip_proto,
- struct flow_keys *flow)
+ struct bpf_flow_keys *flow)
{
*ip_proto = load_byte(skb,
nhoff + offsetof(struct ipv6hdr, nexthdr));
@@ -96,7 +96,7 @@ static inline __u64 parse_ipv6(struct __sk_buff *skb, __u64 nhoff, __u64 *ip_pro
return nhoff;
}
-static inline bool flow_dissector(struct __sk_buff *skb, struct flow_keys *flow)
+static inline bool flow_dissector(struct __sk_buff *skb, struct bpf_flow_keys *flow)
{
__u64 nhoff = ETH_HLEN;
__u64 ip_proto;
@@ -198,7 +198,7 @@ struct bpf_map_def SEC("maps") hash_map = {
SEC("socket2")
int bpf_prog2(struct __sk_buff *skb)
{
- struct flow_keys flow;
+ struct bpf_flow_keys flow;
struct pair *value;
u32 key;
diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c
index 41ae2fd..95907f8 100644
--- a/samples/bpf/sockex3_kern.c
+++ b/samples/bpf/sockex3_kern.c
@@ -61,7 +61,7 @@ struct vlan_hdr {
__be16 h_vlan_encapsulated_proto;
};
-struct flow_keys {
+struct bpf_flow_keys {
__be32 src;
__be32 dst;
union {
@@ -88,7 +88,7 @@ static inline __u32 ipv6_addr_hash(struct __sk_buff *ctx, __u64 off)
}
struct globals {
- struct flow_keys flow;
+ struct bpf_flow_keys flow;
};
struct bpf_map_def SEC("maps") percpu_map = {
@@ -114,14 +114,14 @@ struct pair {
struct bpf_map_def SEC("maps") hash_map = {
.type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(struct flow_keys),
+ .key_size = sizeof(struct bpf_flow_keys),
.value_size = sizeof(struct pair),
.max_entries = 1024,
};
static void update_stats(struct __sk_buff *skb, struct globals *g)
{
- struct flow_keys key = g->flow;
+ struct bpf_flow_keys key = g->flow;
struct pair *value;
value = bpf_map_lookup_elem(&hash_map, &key);
diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index d4184ab..3fcfd8c4 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -7,7 +7,7 @@
#include <arpa/inet.h>
#include <sys/resource.h>
-struct flow_keys {
+struct bpf_flow_keys {
__be32 src;
__be32 dst;
union {
@@ -49,7 +49,7 @@ int main(int argc, char **argv)
(void) f;
for (i = 0; i < 5; i++) {
- struct flow_keys key = {}, next_key;
+ struct bpf_flow_keys key = {}, next_key;
struct pair value;
sleep(1);
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter
2016-09-23 20:40 [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Naveen N. Rao
@ 2016-09-23 20:40 ` Naveen N. Rao
2016-09-24 7:27 ` Alexei Starovoitov
2016-09-27 7:49 ` David Miller
2016-09-24 7:25 ` [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Alexei Starovoitov
2016-09-27 7:49 ` David Miller
2 siblings, 2 replies; 6+ messages in thread
From: Naveen N. Rao @ 2016-09-23 20:40 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, netdev, David S. Miller
Cc: Michael Ellerman, Alexei Starovoitov, Daniel Borkmann,
Ananth N Mavinakayanahalli
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>
---
I am not completely sure if __seccomp_filter is the right place to hook
in. This works for me though. Please review.
Thanks,
Naveen
samples/bpf/tracex5_kern.c | 16 +++++++---------
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 f95f232..fd12d71 100644
--- a/samples/bpf/tracex5_kern.c
+++ b/samples/bpf/tracex5_kern.c
@@ -19,20 +19,18 @@ struct bpf_map_def SEC("maps") progs = {
.max_entries = 1024,
};
-SEC("kprobe/seccomp_phase1")
+SEC("kprobe/__seccomp_filter")
int bpf_prog1(struct pt_regs *ctx)
{
- struct seccomp_data sd;
-
- bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
+ int sc_nr = (int)PT_REGS_PARM1(ctx);
/* dispatch into next BPF program depending on syscall number */
- bpf_tail_call(ctx, &progs, sd.nr);
+ bpf_tail_call(ctx, &progs, sc_nr);
/* fall through -> unknown syscall */
- if (sd.nr >= __NR_getuid && sd.nr <= __NR_getsid) {
+ if (sc_nr >= __NR_getuid && sc_nr <= __NR_getsid) {
char fmt[] = "syscall=%d (one of get/set uid/pid/gid)\n";
- bpf_trace_printk(fmt, sizeof(fmt), sd.nr);
+ bpf_trace_printk(fmt, sizeof(fmt), sc_nr);
}
return 0;
}
@@ -42,7 +40,7 @@ PROG(__NR_write)(struct pt_regs *ctx)
{
struct seccomp_data sd;
- bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
+ bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
if (sd.args[2] == 512) {
char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
bpf_trace_printk(fmt, sizeof(fmt),
@@ -55,7 +53,7 @@ PROG(__NR_read)(struct pt_regs *ctx)
{
struct seccomp_data sd;
- bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx));
+ bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
if (sd.args[2] > 128 && sd.args[2] <= 1024) {
char fmt[] = "read(fd=%d, buf=%p, size=%d)\n";
bpf_trace_printk(fmt, sizeof(fmt),
diff --git a/samples/bpf/tracex5_user.c b/samples/bpf/tracex5_user.c
index a04dd3c..36b5925 100644
--- a/samples/bpf/tracex5_user.c
+++ b/samples/bpf/tracex5_user.c
@@ -6,6 +6,7 @@
#include <sys/prctl.h>
#include "libbpf.h"
#include "bpf_load.h"
+#include <sys/resource.h>
/* install fake seccomp program to enable seccomp code path inside the kernel,
* so that our kprobe attached to seccomp_phase1() can be triggered
@@ -27,8 +28,10 @@ int main(int ac, char **argv)
{
FILE *f;
char filename[256];
+ struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
+ setrlimit(RLIMIT_MEMLOCK, &r);
if (load_bpf_file(filename)) {
printf("%s", bpf_log_buf);
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3
2016-09-23 20:40 [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Naveen N. Rao
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
@ 2016-09-24 7:25 ` Alexei Starovoitov
2016-09-27 7:49 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2016-09-24 7:25 UTC (permalink / raw)
To: Naveen N. Rao
Cc: linux-kernel, linuxppc-dev, netdev, David S. Miller,
Michael Ellerman, Alexei Starovoitov, Daniel Borkmann,
Ananth N Mavinakayanahalli
On Sat, Sep 24, 2016 at 02:10:04AM +0530, Naveen N. Rao wrote:
> These samples fail to compile as 'struct flow_keys' conflicts with
> definition in net/flow_dissector.h. Fix the same by renaming the
> structure used in the sample.
>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Thanks for the fix.
Acked-by: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
@ 2016-09-24 7:27 ` Alexei Starovoitov
2016-09-27 7:49 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2016-09-24 7:27 UTC (permalink / raw)
To: Naveen N. Rao
Cc: linux-kernel, linuxppc-dev, netdev, David S. Miller,
Michael Ellerman, Alexei Starovoitov, Daniel Borkmann,
Ananth N Mavinakayanahalli
On Sat, Sep 24, 2016 at 02:10:05AM +0530, Naveen N. Rao wrote:
> 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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3
2016-09-23 20:40 [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Naveen N. Rao
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
2016-09-24 7:25 ` [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Alexei Starovoitov
@ 2016-09-27 7:49 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2016-09-27 7:49 UTC (permalink / raw)
To: naveen.n.rao; +Cc: linux-kernel, linuxppc-dev, netdev, mpe, ast, daniel, ananth
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Date: Sat, 24 Sep 2016 02:10:04 +0530
> These samples fail to compile as 'struct flow_keys' conflicts with
> definition in net/flow_dissector.h. Fix the same by renaming the
> structure used in the sample.
>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Applied to net-next.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
2016-09-24 7:27 ` Alexei Starovoitov
@ 2016-09-27 7:49 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2016-09-27 7:49 UTC (permalink / raw)
To: naveen.n.rao; +Cc: linux-kernel, linuxppc-dev, netdev, mpe, ast, daniel, ananth
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Date: Sat, 24 Sep 2016 02:10:05 +0530
> 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>
Also applied to net-next, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-09-27 7:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-23 20:40 [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Naveen N. Rao
2016-09-23 20:40 ` [PATCH 2/2] bpf samples: update tracex5 sample to use __seccomp_filter Naveen N. Rao
2016-09-24 7:27 ` Alexei Starovoitov
2016-09-27 7:49 ` David Miller
2016-09-24 7:25 ` [PATCH 1/2] bpf samples: fix compiler errors with sockex2 and sockex3 Alexei Starovoitov
2016-09-27 7:49 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).