Skip to content

Commit 0c6bc6e

Browse files
jrfastabAlexei Starovoitov
authored andcommitted
bpf: fix sk_skb programs without skb->dev assigned
Multiple BPF helpers in use by sk_skb programs calculate the max skb length using the __bpf_skb_max_len function. However, this calculates the max length using the skb->dev pointer which can be NULL when an sk_skb program is paired with an sk_msg program. To force this a sk_msg program needs to redirect into the ingress path of a sock with an attach sk_skb program. Then the the sk_skb program would need to call one of the helpers that adjust the skb size. To fix the null ptr dereference use SKB_MAX_ALLOC size if no dev is available. Fixes: 8934ce2 ("bpf: sockmap redirect ingress support") Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 631da85 commit 0c6bc6e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2779,7 +2779,8 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
27792779

27802780
static u32 __bpf_skb_max_len(const struct sk_buff *skb)
27812781
{
2782-
return skb->dev->mtu + skb->dev->hard_header_len;
2782+
return skb->dev ? skb->dev->mtu + skb->dev->hard_header_len :
2783+
SKB_MAX_ALLOC;
27832784
}
27842785

27852786
static int bpf_skb_adjust_net(struct sk_buff *skb, s32 len_diff)

0 commit comments

Comments
 (0)