* [PATCH] bpf: Don't redirect packets with pkt_len 0
@ 2022-06-17 7:18 Di Zhu
2022-06-17 8:10 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Di Zhu @ 2022-06-17 7:18 UTC (permalink / raw)
To: ast, edumazet, daniel, andrii, yhs, davem
Cc: netdev, bpf, zhudi2, rose.chen, syzbot+7a12909485b94426aceb
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.
LINK: [1] https://syzkaller.appspot.com/bug?id=0b84da80c2917757915afa89f7738a9d16ec96c5
LINK: [2] https://www.spinics.net/lists/netdev/msg777503.html
Reported-by: syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com
Signed-off-by: Di Zhu <zhudi2@huawei.com>
---
net/core/filter.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/filter.c b/net/core/filter.c
index 5af58eb48587..c7fbfa90898a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -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
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: Don't redirect packets with pkt_len 0
2022-06-17 7:18 [PATCH] bpf: Don't redirect packets with pkt_len 0 Di Zhu
@ 2022-06-17 8:10 ` Eric Dumazet
0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2022-06-17 8:10 UTC (permalink / raw)
To: Di Zhu
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Yonghong Song, David Miller, netdev, bpf, rose.chen,
syzbot+7a12909485b94426aceb
On Fri, Jun 17, 2022 at 9:19 AM Di Zhu <zhudi2@huawei.com> wrote:
>
> 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.
>
> LINK: [1] https://syzkaller.appspot.com/bug?id=0b84da80c2917757915afa89f7738a9d16ec96c5
> LINK: [2] https://www.spinics.net/lists/netdev/msg777503.html
>
> Reported-by: syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com
> Signed-off-by: Di Zhu <zhudi2@huawei.com>
> ---
> net/core/filter.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 5af58eb48587..c7fbfa90898a 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -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
> if (dev_is_mac_header_xmit(dev))
> return __bpf_redirect_common(skb, dev, flags);
> else
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: Don't redirect packets with pkt_len 0
@ 2022-06-18 10:16 zhudi (E)
0 siblings, 0 replies; 3+ messages in thread
From: zhudi (E) @ 2022-06-18 10:16 UTC (permalink / raw)
To: Eric Dumazet
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Yonghong Song, David Miller, netdev, bpf, Chenxiang (EulerOS),
syzbot+7a12909485b94426aceb
> On Fri, Jun 17, 2022 at 9:19 AM Di Zhu <zhudi2@huawei.com> wrote:
> >
> > 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.
> >
> > LINK: [1]
> https://syzkaller.appspot.com/bug?id=0b84da80c2917757915afa89f7738a9d16e
> c96c5
> > LINK: [2] https://www.spinics.net/lists/netdev/msg777503.html
> >
> > Reported-by: syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com
> > Signed-off-by: Di Zhu <zhudi2@huawei.com>
> > ---
> > net/core/filter.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 5af58eb48587..c7fbfa90898a 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -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.
I only focused on this particular test case...
the submission information should be modified to describe a general problem.
> Also returning -EINVAL will leak the skb :/
Yes...
>
> 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() ?
Does the no mac device need to check the length of the package?
> 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
It is only valid for device with mac header. such as ip tunnel device, dev->min_header_len
has not set.
>
>
> > if (dev_is_mac_header_xmit(dev))
> > return __bpf_redirect_common(skb, dev, flags);
> > else
> > --
> > 2.27.0
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-18 10:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17 7:18 [PATCH] bpf: Don't redirect packets with pkt_len 0 Di Zhu
2022-06-17 8:10 ` Eric Dumazet
2022-06-18 10:16 zhudi (E)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).