Skip to content

Commit

Permalink
net: filter: fix SKF_AD_PKTTYPE extension on big-endian
Browse files Browse the repository at this point in the history
BPF classic->internal converter broke SKF_AD_PKTTYPE extension, since
pkt_type_offset() was failing to find skb->pkt_type field which is defined as:
__u8 pkt_type:3,
     fclone:2,
     ipvs_property:1,
     peeked:1,
     nf_trace:1;

Fix it by searching for 3 most significant bits and shift them by 5 at run-time

Fixes: bd4cf0e ("net: filter: rework/optimize internal BPF interpreter's instruction set")
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Tested-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Alexei Starovoitov authored and davem330 committed Jun 5, 2014
1 parent 78c8dbb commit 0dcceab
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,11 @@ EXPORT_SYMBOL_GPL(sk_run_filter_int_skb);
* to make sure its still a 3bit field starting at a byte boundary;
* taken from arch/x86/net/bpf_jit_comp.c.
*/
#ifdef __BIG_ENDIAN_BITFIELD
#define PKT_TYPE_MAX (7 << 5)
#else
#define PKT_TYPE_MAX 7
#endif
static unsigned int pkt_type_offset(void)
{
struct sk_buff skb_probe = { .pkt_type = ~0, };
Expand Down Expand Up @@ -685,6 +689,13 @@ static bool convert_bpf_extensions(struct sock_filter *fp,
insn->code = BPF_ALU | BPF_AND | BPF_K;
insn->a_reg = A_REG;
insn->imm = PKT_TYPE_MAX;
#ifdef __BIG_ENDIAN_BITFIELD
insn++;

insn->code = BPF_ALU | BPF_RSH | BPF_K;
insn->a_reg = A_REG;
insn->imm = 5;
#endif
break;

case SKF_AD_OFF + SKF_AD_IFINDEX:
Expand Down

0 comments on commit 0dcceab

Please sign in to comment.