diff options
author | Markos Chandras <markos.chandras@imgtec.com> | 2014-06-23 05:38:58 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-06-26 05:48:22 -0400 |
commit | b4fe0ec86dae91abfa9f932cd0e2e9d50e336c8b (patch) | |
tree | a40109b4861da4da8fff62c37bac63907c2e1600 /arch/mips | |
parent | 95782bf434437b3292f5cb9ce21b53bdbc1beda1 (diff) |
MIPS: bpf: Fix PKT_TYPE case for big-endian cores
The skb->pkt_type field is defined as follows:
u8 pkt_type:3,
fclone:2,
ipvs_property:1,
peeked:1,
nf_trace:1
resulting to the following layout in big-endian systems
[pkt_type][fclone][ipvs_propery][peeked][nf_trace]
^ ^
| |
LSB MSB
As a result, the existing code did not work because it was trying to
match pkt_type == 7 whereas in reality it is 7<<5 on big-endian
systems.
This has been fixed in the interpreter in
0dcceabb0c1bf2d4c12a748df9933fad303072a7
"net: filter: fix SKF_AD_PKTTYPE extension on big-endian"
The fix is to look for 7<<5 on big-endian systems for the pkt_type
field, and shift by 5 so the packet type will be at the lower 3 bits
of the A register.
Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: netdev@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/7132/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/net/bpf_jit.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c index 9476e7f061a1..4505e2e6ab53 100644 --- a/arch/mips/net/bpf_jit.c +++ b/arch/mips/net/bpf_jit.c | |||
@@ -751,13 +751,17 @@ static u64 jit_get_skb_w(struct sk_buff *skb, unsigned offset) | |||
751 | return (u64)err << 32 | ntohl(ret); | 751 | return (u64)err << 32 | ntohl(ret); |
752 | } | 752 | } |
753 | 753 | ||
754 | #define PKT_TYPE_MAX 7 | 754 | #ifdef __BIG_ENDIAN_BITFIELD |
755 | #define PKT_TYPE_MAX (7 << 5) | ||
756 | #else | ||
757 | #define PKT_TYPE_MAX 7 | ||
758 | #endif | ||
755 | static int pkt_type_offset(void) | 759 | static int pkt_type_offset(void) |
756 | { | 760 | { |
757 | struct sk_buff skb_probe = { | 761 | struct sk_buff skb_probe = { |
758 | .pkt_type = ~0, | 762 | .pkt_type = ~0, |
759 | }; | 763 | }; |
760 | char *ct = (char *)&skb_probe; | 764 | u8 *ct = (u8 *)&skb_probe; |
761 | unsigned int off; | 765 | unsigned int off; |
762 | 766 | ||
763 | for (off = 0; off < sizeof(struct sk_buff); off++) { | 767 | for (off = 0; off < sizeof(struct sk_buff); off++) { |
@@ -1320,6 +1324,10 @@ jmp_cmp: | |||
1320 | emit_load_byte(r_tmp, r_skb, off, ctx); | 1324 | emit_load_byte(r_tmp, r_skb, off, ctx); |
1321 | /* Keep only the last 3 bits */ | 1325 | /* Keep only the last 3 bits */ |
1322 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); | 1326 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); |
1327 | #ifdef __BIG_ENDIAN_BITFIELD | ||
1328 | /* Get the actual packet type to the lower 3 bits */ | ||
1329 | emit_srl(r_A, r_A, 5, ctx); | ||
1330 | #endif | ||
1323 | break; | 1331 | break; |
1324 | case BPF_ANC | SKF_AD_QUEUE: | 1332 | case BPF_ANC | SKF_AD_QUEUE: |
1325 | ctx->flags |= SEEN_SKB | SEEN_A; | 1333 | ctx->flags |= SEEN_SKB | SEEN_A; |