bpf: Don't redirect packets with pkt_len 0
Subsystems (4)
PATCH 1/1 bpf: Don't redirect packets with pkt_len 0
Syzbot found an issue [1]: fq_codel_drop() try to drop a flow whitout any skbs, that is, the flow->head is null.
The root cause, as the [2] says, is because that bpf_prog_test_run_skb() run a bpf prog which redirects empty skbs.
So we should determine whether the length of the packet modified by bpf prog or others like bpf_prog_test is 0 before forwarding it directly.
--- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/filter.c +3 -0
@@ -2156,6 +2156,9 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,static int __bpf_redirect (struct sk_buff *skb,struct net_device *dev,u32 flags) { +if (unlikely (skb->len ==0 )) +return -EINVAL ; +if (dev_is_mac_header_xmit (dev))return __bpf_redirect_common (skb, dev, flags);else
Signature · 1 line
2.27.0
Quoted 22 lines · Di Zhu
Syzbot found an issue [1]:
fq_codel_drop()try to drop a flow whitout any skbs, that is, theflow->headis null.
The root cause, as the [2] says, is because thatbpf_prog_test_run_skb()run a bpf prog which redirects empty skbs.
So we should determine whether the length of the packet modified by bpf prog or others likebpf_prog_testis 0 before forwarding it directly.Reported-by [email protected]Signed-off-by Di Zhu <[email protected]>--- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+)net/core/filter.c +0
-0
net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2161
Quoted 6 lines
net/core/filter.c +3
-0@@ -2156,6 +2156,9 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,static int __bpf_redirect (struct sk_buff *skb,struct net_device *dev,u32 flags) { +if (unlikely (skb->len ==0 )) +return -EINVAL ; +
You focus again on fq_codel, but we have a more generic issue at hand.
I said that most drivers will assume packets are Ethernet ones, having at least an Ethernet header in them.
Also returning -EINVAL will leak the skb :/
I think a better fix would be to make sure the skb carries an expected packet length,
and this probably differs in __bpf_redirect_common() and __bpf_redirect_no_mac() ?
Current test in __bpf_redirect_common() seems not good enough.
+ /* Verify that a link layer header is carried */
+ if (unlikely(skb->mac_header >= skb->network_header)) {
+ kfree_skb(skb);
+ return -ERANGE;
+ }
+
It should check that the link layer header size is >= dev->min_header_len
Quoted 6 lines
net/core/filter.c +0
-1if (dev_is_mac_header_xmit (dev))return __bpf_redirect_common (skb, dev, flags);else --2.27.0