diff mbox series

[net-next] net/mpls: fix WARNING in mpls_gso_segment

Message ID 20240222040046.2568269-1-lizhi.xu@windriver.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net/mpls: fix WARNING in mpls_gso_segment | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-22--12-00 (tests: 1454)

Commit Message

Lizhi Xu Feb. 22, 2024, 4 a.m. UTC
When the network header pointer is greater than the inner network header, the
difference between the two can cause mpls_hlen overflow.

Reported-and-tested-by: syzbot+99d15fcdb0132a1e1a82@syzkaller.appspotmail.com
Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
---
 net/mpls/mpls_gso.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Feb. 22, 2024, 8:11 a.m. UTC | #1
On Thu, Feb 22, 2024 at 5:00 AM Lizhi Xu <lizhi.xu@windriver.com> wrote:
>
> When the network header pointer is greater than the inner network header, the
> difference between the two can cause mpls_hlen overflow.
>
> Reported-and-tested-by: syzbot+99d15fcdb0132a1e1a82@syzkaller.appspotmail.com
> Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
> ---
>  net/mpls/mpls_gso.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/mpls/mpls_gso.c b/net/mpls/mpls_gso.c
> index 533d082f0701..2ab24b2fd90f 100644
> --- a/net/mpls/mpls_gso.c
> +++ b/net/mpls/mpls_gso.c
> @@ -25,11 +25,11 @@ static struct sk_buff *mpls_gso_segment(struct sk_buff *skb,
>         netdev_features_t mpls_features;
>         u16 mac_len = skb->mac_len;
>         __be16 mpls_protocol;
> -       unsigned int mpls_hlen;
> +       int mpls_hlen;
>
>         skb_reset_network_header(skb);
>         mpls_hlen = skb_inner_network_header(skb) - skb_network_header(skb);
> -       if (unlikely(!mpls_hlen || mpls_hlen % MPLS_HLEN))
> +       if (unlikely(mpls_hlen <= 0 || mpls_hlen % MPLS_HLEN))
>                 goto out;
>         if (unlikely(!pskb_may_pull(skb, mpls_hlen)))
>                 goto out;
> --
> 2.43.0
>

I think Florian posted this patch, right ?

We must add a Fixes: tag

Also we should ask ourselves :
Why are we even looking at skb_inner_network_header(skb) if this was not set ?

Lets not hide a real bug, we need to understand the root cause.
Lizhi Xu Feb. 23, 2024, 3:30 a.m. UTC | #2
On Thu, 22 Feb 2024 09:11:14 +0100, Eric Dumazet <edumazet@google.com> wrote:
> > When the network header pointer is greater than the inner network header, the
> > difference between the two can cause mpls_hlen overflow.
> >
> > Reported-and-tested-by: syzbot+99d15fcdb0132a1e1a82@syzkaller.appspotmail.com
> > Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
> > ---
> >  net/mpls/mpls_gso.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/mpls/mpls_gso.c b/net/mpls/mpls_gso.c
> > index 533d082f0701..2ab24b2fd90f 100644
> > --- a/net/mpls/mpls_gso.c
> > +++ b/net/mpls/mpls_gso.c
> > @@ -25,11 +25,11 @@ static struct sk_buff *mpls_gso_segment(struct sk_buff *skb,
> >         netdev_features_t mpls_features;
> >         u16 mac_len = skb->mac_len;
> >         __be16 mpls_protocol;
> > -       unsigned int mpls_hlen;
> > +       int mpls_hlen;
> >
> >         skb_reset_network_header(skb);
> >         mpls_hlen = skb_inner_network_header(skb) - skb_network_header(skb);
> > -       if (unlikely(!mpls_hlen || mpls_hlen % MPLS_HLEN))
> > +       if (unlikely(mpls_hlen <= 0 || mpls_hlen % MPLS_HLEN))
> >                 goto out;
> >         if (unlikely(!pskb_may_pull(skb, mpls_hlen)))
> >                 goto out;
> > --
> > 2.43.0
> >
> 
> I think Florian posted this patch, right ?
After you mentioned it, I discovered it. 
I forgot to check the email details before sending the patch.
> 
> We must add a Fixes: tag
> 
> Also we should ask ourselves :
> Why are we even looking at skb_inner_network_header(skb) if this was not set ?

__sys_sendto()->
   __sock_sendmsg()->
      netlink_sendmsg()->
         netlink_broadcast_filtered()->
            netlink_trim()->
	       1323         pskb_expand_head(skb, 0, -delta, 
                  1                          (allocation & ~__GFP_DIRECT_RECLAIM) |
                  2                          __GFP_NOWARN | __GFP_NORETRY);
               pskb_expand_head()->
                 skb_headers_offset_update()->
		 1977         skb->inner_network_header += off;

The root cause is: 
Initialize inner_network_header to 0 in network_trim(), and without any other
assignment operations.
diff mbox series

Patch

diff --git a/net/mpls/mpls_gso.c b/net/mpls/mpls_gso.c
index 533d082f0701..2ab24b2fd90f 100644
--- a/net/mpls/mpls_gso.c
+++ b/net/mpls/mpls_gso.c
@@ -25,11 +25,11 @@  static struct sk_buff *mpls_gso_segment(struct sk_buff *skb,
 	netdev_features_t mpls_features;
 	u16 mac_len = skb->mac_len;
 	__be16 mpls_protocol;
-	unsigned int mpls_hlen;
+	int mpls_hlen;
 
 	skb_reset_network_header(skb);
 	mpls_hlen = skb_inner_network_header(skb) - skb_network_header(skb);
-	if (unlikely(!mpls_hlen || mpls_hlen % MPLS_HLEN))
+	if (unlikely(mpls_hlen <= 0 || mpls_hlen % MPLS_HLEN))
 		goto out;
 	if (unlikely(!pskb_may_pull(skb, mpls_hlen)))
 		goto out;