netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
@ 2022-12-03  9:29 YueHaibing
  2022-12-03 10:29 ` Biju Das
  2022-12-06 11:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: YueHaibing @ 2022-12-03  9:29 UTC (permalink / raw)
  To: s.shtylyov, davem, edumazet, kuba, pabeni, phil.edworthy,
	biju.das.jz, prabhakar.mahadev-lad.rj
  Cc: netdev, linux-renesas-soc, linux-kernel, YueHaibing

The skb is delivered to napi_gro_receive() which may free it, after calling this,
dereferencing skb may trigger use-after-free.

Fixes: 1c59eb678cbd ("ravb: Fillup ravb_rx_gbeth() stub")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/renesas/ravb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 6bc923326268..33f723a9f471 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -841,7 +841,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
 				napi_gro_receive(&priv->napi[q],
 						 priv->rx_1st_skb);
 				stats->rx_packets++;
-				stats->rx_bytes += priv->rx_1st_skb->len;
+				stats->rx_bytes += pkt_len;
 				break;
 			}
 		}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
  2022-12-03  9:29 [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth() YueHaibing
@ 2022-12-03 10:29 ` Biju Das
  2022-12-05  8:43   ` Geert Uytterhoeven
  2022-12-06 11:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Biju Das @ 2022-12-03 10:29 UTC (permalink / raw)
  To: YueHaibing, s.shtylyov, davem, edumazet, kuba, pabeni,
	phil.edworthy, Prabhakar Mahadev Lad
  Cc: netdev, linux-renesas-soc, linux-kernel

Hi YueHaibing,

Thanks for the feedback.

> Subject: [PATCH net] ravb: Fix potential use-after-free in
> ravb_rx_gbeth()
> 
> The skb is delivered to napi_gro_receive() which may free it, after
> calling this, dereferencing skb may trigger use-after-free.

Can you please reconfirm the changes you have done is actually fixing any issue? 
If yes, please provide the details.

Current code,

napi_gro_receive(&priv->napi[q], priv->rx_1st_skb);

- stats->rx_bytes += priv->rx_1st_skb->len;
+ stats->rx_bytes += pkt_len;

Note: I haven't tested your patch yet to see it cause any regression.

Cheers,
Biju

> 
> Fixes: 1c59eb678cbd ("ravb: Fillup ravb_rx_gbeth() stub")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/net/ethernet/renesas/ravb_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c
> b/drivers/net/ethernet/renesas/ravb_main.c
> index 6bc923326268..33f723a9f471 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -841,7 +841,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev,
> int *quota, int q)
>  				napi_gro_receive(&priv->napi[q],
>  						 priv->rx_1st_skb);
>  				stats->rx_packets++;
> -				stats->rx_bytes += priv->rx_1st_skb->len;
> +				stats->rx_bytes += pkt_len;
>  				break;
>  			}
>  		}
> --
> 2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
  2022-12-03 10:29 ` Biju Das
@ 2022-12-05  8:43   ` Geert Uytterhoeven
  2022-12-05  8:46     ` Biju Das
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2022-12-05  8:43 UTC (permalink / raw)
  To: Biju Das
  Cc: YueHaibing, s.shtylyov, davem, edumazet, kuba, pabeni,
	phil.edworthy, Prabhakar Mahadev Lad, netdev, linux-renesas-soc,
	linux-kernel

Hi Biju,

On Sat, Dec 3, 2022 at 11:29 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > Subject: [PATCH net] ravb: Fix potential use-after-free in
> > ravb_rx_gbeth()
> >
> > The skb is delivered to napi_gro_receive() which may free it, after
> > calling this, dereferencing skb may trigger use-after-free.
>
> Can you please reconfirm the changes you have done is actually fixing any issue?
> If yes, please provide the details.
>
> Current code,
>
> napi_gro_receive(&priv->napi[q], priv->rx_1st_skb);

IIUIC, after this, priv->rx_1st_skb may have been freed...

>
> - stats->rx_bytes += priv->rx_1st_skb->len;

... so accessing priv->rx_1st_skb->len here may be a UAF.

> + stats->rx_bytes += pkt_len;

So this change looks correct to me, as pkt_len was stored to
priv->rx_1st_skb->len using skb_put() before.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

>
> Note: I haven't tested your patch yet to see it cause any regression.
>
> Cheers,
> Biju
>
> >
> > Fixes: 1c59eb678cbd ("ravb: Fillup ravb_rx_gbeth() stub")
> > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > ---
> >  drivers/net/ethernet/renesas/ravb_main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/renesas/ravb_main.c
> > b/drivers/net/ethernet/renesas/ravb_main.c
> > index 6bc923326268..33f723a9f471 100644
> > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> > @@ -841,7 +841,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev,
> > int *quota, int q)
> >                               napi_gro_receive(&priv->napi[q],
> >                                                priv->rx_1st_skb);
> >                               stats->rx_packets++;
> > -                             stats->rx_bytes += priv->rx_1st_skb->len;
> > +                             stats->rx_bytes += pkt_len;
> >                               break;
> >                       }
> >               }

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
  2022-12-05  8:43   ` Geert Uytterhoeven
@ 2022-12-05  8:46     ` Biju Das
  0 siblings, 0 replies; 5+ messages in thread
From: Biju Das @ 2022-12-05  8:46 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: YueHaibing, s.shtylyov, davem, edumazet, kuba, pabeni,
	phil.edworthy, Prabhakar Mahadev Lad, netdev, linux-renesas-soc,
	linux-kernel

Hi Geert,

> Subject: Re: [PATCH net] ravb: Fix potential use-after-free in
> ravb_rx_gbeth()
> 
> Hi Biju,
> 
> On Sat, Dec 3, 2022 at 11:29 AM Biju Das <biju.das.jz@bp.renesas.com>
> wrote:
> > > Subject: [PATCH net] ravb: Fix potential use-after-free in
> > > ravb_rx_gbeth()
> > >
> > > The skb is delivered to napi_gro_receive() which may free it, after
> > > calling this, dereferencing skb may trigger use-after-free.
> >
> > Can you please reconfirm the changes you have done is actually fixing
> any issue?
> > If yes, please provide the details.
> >
> > Current code,
> >
> > napi_gro_receive(&priv->napi[q], priv->rx_1st_skb);
> 
> IIUIC, after this, priv->rx_1st_skb may have been freed...
> 
> >
> > - stats->rx_bytes += priv->rx_1st_skb->len;
> 
> ... so accessing priv->rx_1st_skb->len here may be a UAF.
> 
> > + stats->rx_bytes += pkt_len;
> 
> So this change looks correct to me, as pkt_len was stored to
> priv->rx_1st_skb->len using skb_put() before.

Thanks for detailed explanation. It makes sense now.

Cheers,
Biju
> 
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> >
> > Note: I haven't tested your patch yet to see it cause any regression.
> >
> > Cheers,
> > Biju
> >
> > >
> > > Fixes: 1c59eb678cbd ("ravb: Fillup ravb_rx_gbeth() stub")
> > > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > > ---
> > >  drivers/net/ethernet/renesas/ravb_main.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/net/ethernet/renesas/ravb_main.c
> > > b/drivers/net/ethernet/renesas/ravb_main.c
> > > index 6bc923326268..33f723a9f471 100644
> > > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> > > @@ -841,7 +841,7 @@ static bool ravb_rx_gbeth(struct net_device
> > > *ndev, int *quota, int q)
> > >                               napi_gro_receive(&priv->napi[q],
> > >                                                priv->rx_1st_skb);
> > >                               stats->rx_packets++;
> > > -                             stats->rx_bytes += priv->rx_1st_skb-
> >len;
> > > +                             stats->rx_bytes += pkt_len;
> > >                               break;
> > >                       }
> > >               }
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-
> m68k.org
> 
> In personal conversations with technical people, I call myself a hacker.
> But when I'm talking to journalists I just say "programmer" or something
> like that.
>                                 -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
  2022-12-03  9:29 [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth() YueHaibing
  2022-12-03 10:29 ` Biju Das
@ 2022-12-06 11:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-06 11:50 UTC (permalink / raw)
  To: YueHaibing
  Cc: s.shtylyov, davem, edumazet, kuba, pabeni, phil.edworthy,
	biju.das.jz, prabhakar.mahadev-lad.rj, netdev, linux-renesas-soc,
	linux-kernel

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Sat, 3 Dec 2022 17:29:41 +0800 you wrote:
> The skb is delivered to napi_gro_receive() which may free it, after calling this,
> dereferencing skb may trigger use-after-free.
> 
> Fixes: 1c59eb678cbd ("ravb: Fillup ravb_rx_gbeth() stub")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/net/ethernet/renesas/ravb_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
  - [net] ravb: Fix potential use-after-free in ravb_rx_gbeth()
    https://git.kernel.org/netdev/net/c/5a5a3e564de6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-06 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-03  9:29 [PATCH net] ravb: Fix potential use-after-free in ravb_rx_gbeth() YueHaibing
2022-12-03 10:29 ` Biju Das
2022-12-05  8:43   ` Geert Uytterhoeven
2022-12-05  8:46     ` Biju Das
2022-12-06 11:50 ` patchwork-bot+netdevbpf

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).