diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2014-09-12 08:04:43 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-13 17:07:21 -0400 |
commit | 233577a22089facf5271ab5e845b2262047c971f (patch) | |
tree | c93ec43dbf3adb316b3af67a3d315984b3cc5f10 /arch | |
parent | ac7a04c33dd7f8e429df4b929ba3a3e8e729cc89 (diff) |
net: filter: constify detection of pkt_type_offset
Currently we have 2 pkt_type_offset functions doing the same thing and
spread across the architecture files. Remove those and replace them
with a PKT_TYPE_OFFSET macro helper which gets the constant value from a
zero sized sk_buff member right in front of the bitfield with offsetof.
This new offset marker does not change size of struct sk_buff.
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Markos Chandras <markos.chandras@imgtec.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/net/bpf_jit.c | 27 | ||||
-rw-r--r-- | arch/s390/net/bpf_jit_comp.c | 35 |
2 files changed, 2 insertions, 60 deletions
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c index 0e97ccd29fe3..7edc08398c4a 100644 --- a/arch/mips/net/bpf_jit.c +++ b/arch/mips/net/bpf_jit.c | |||
@@ -765,27 +765,6 @@ static u64 jit_get_skb_w(struct sk_buff *skb, unsigned offset) | |||
765 | return (u64)err << 32 | ntohl(ret); | 765 | return (u64)err << 32 | ntohl(ret); |
766 | } | 766 | } |
767 | 767 | ||
768 | #ifdef __BIG_ENDIAN_BITFIELD | ||
769 | #define PKT_TYPE_MAX (7 << 5) | ||
770 | #else | ||
771 | #define PKT_TYPE_MAX 7 | ||
772 | #endif | ||
773 | static int pkt_type_offset(void) | ||
774 | { | ||
775 | struct sk_buff skb_probe = { | ||
776 | .pkt_type = ~0, | ||
777 | }; | ||
778 | u8 *ct = (u8 *)&skb_probe; | ||
779 | unsigned int off; | ||
780 | |||
781 | for (off = 0; off < sizeof(struct sk_buff); off++) { | ||
782 | if (ct[off] == PKT_TYPE_MAX) | ||
783 | return off; | ||
784 | } | ||
785 | pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n"); | ||
786 | return -1; | ||
787 | } | ||
788 | |||
789 | static int build_body(struct jit_ctx *ctx) | 768 | static int build_body(struct jit_ctx *ctx) |
790 | { | 769 | { |
791 | void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; | 770 | void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; |
@@ -1332,11 +1311,7 @@ jmp_cmp: | |||
1332 | case BPF_ANC | SKF_AD_PKTTYPE: | 1311 | case BPF_ANC | SKF_AD_PKTTYPE: |
1333 | ctx->flags |= SEEN_SKB; | 1312 | ctx->flags |= SEEN_SKB; |
1334 | 1313 | ||
1335 | off = pkt_type_offset(); | 1314 | emit_load_byte(r_tmp, r_skb, PKT_TYPE_OFFSET(), ctx); |
1336 | |||
1337 | if (off < 0) | ||
1338 | return -1; | ||
1339 | emit_load_byte(r_tmp, r_skb, off, ctx); | ||
1340 | /* Keep only the last 3 bits */ | 1315 | /* Keep only the last 3 bits */ |
1341 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); | 1316 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); |
1342 | #ifdef __BIG_ENDIAN_BITFIELD | 1317 | #ifdef __BIG_ENDIAN_BITFIELD |
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 555f5c7e83ab..c52ac77408ca 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c | |||
@@ -227,37 +227,6 @@ static void bpf_jit_epilogue(struct bpf_jit *jit) | |||
227 | EMIT2(0x07fe); | 227 | EMIT2(0x07fe); |
228 | } | 228 | } |
229 | 229 | ||
230 | /* Helper to find the offset of pkt_type in sk_buff | ||
231 | * Make sure its still a 3bit field starting at the MSBs within a byte. | ||
232 | */ | ||
233 | #define PKT_TYPE_MAX 0xe0 | ||
234 | static int pkt_type_offset; | ||
235 | |||
236 | static int __init bpf_pkt_type_offset_init(void) | ||
237 | { | ||
238 | struct sk_buff skb_probe = { | ||
239 | .pkt_type = ~0, | ||
240 | }; | ||
241 | char *ct = (char *)&skb_probe; | ||
242 | int off; | ||
243 | |||
244 | pkt_type_offset = -1; | ||
245 | for (off = 0; off < sizeof(struct sk_buff); off++) { | ||
246 | if (!ct[off]) | ||
247 | continue; | ||
248 | if (ct[off] == PKT_TYPE_MAX) | ||
249 | pkt_type_offset = off; | ||
250 | else { | ||
251 | /* Found non matching bit pattern, fix needed. */ | ||
252 | WARN_ON_ONCE(1); | ||
253 | pkt_type_offset = -1; | ||
254 | return -1; | ||
255 | } | ||
256 | } | ||
257 | return 0; | ||
258 | } | ||
259 | device_initcall(bpf_pkt_type_offset_init); | ||
260 | |||
261 | /* | 230 | /* |
262 | * make sure we dont leak kernel information to user | 231 | * make sure we dont leak kernel information to user |
263 | */ | 232 | */ |
@@ -757,12 +726,10 @@ call_fn: /* lg %r1,<d(function)>(%r13) */ | |||
757 | } | 726 | } |
758 | break; | 727 | break; |
759 | case BPF_ANC | SKF_AD_PKTTYPE: | 728 | case BPF_ANC | SKF_AD_PKTTYPE: |
760 | if (pkt_type_offset < 0) | ||
761 | goto out; | ||
762 | /* lhi %r5,0 */ | 729 | /* lhi %r5,0 */ |
763 | EMIT4(0xa7580000); | 730 | EMIT4(0xa7580000); |
764 | /* ic %r5,<d(pkt_type_offset)>(%r2) */ | 731 | /* ic %r5,<d(pkt_type_offset)>(%r2) */ |
765 | EMIT4_DISP(0x43502000, pkt_type_offset); | 732 | EMIT4_DISP(0x43502000, PKT_TYPE_OFFSET()); |
766 | /* srl %r5,5 */ | 733 | /* srl %r5,5 */ |
767 | EMIT4_DISP(0x88500000, 5); | 734 | EMIT4_DISP(0x88500000, 5); |
768 | break; | 735 | break; |