netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc
@ 2023-12-04  2:40 Dinghao Liu
  2023-12-04  8:56 ` Pavan Chebbi
  2023-12-06  3:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Dinghao Liu @ 2023-12-04  2:40 UTC (permalink / raw)
  To: dinghao.liu
  Cc: Michael Chan, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sriharsha Basavapatna, netdev, linux-kernel

When flow_indr_dev_register() fails, bnxt_init_tc will free
bp->tc_info through kfree(). However, the caller function
bnxt_init_one() will ignore this failure and call
bnxt_shutdown_tc() on failure of bnxt_dl_register(), where
a use-after-free happens. Fix this issue by setting
bp->tc_info to NULL after kfree().

Fixes: 627c89d00fb9 ("bnxt_en: flow_offload: offload tunnel decap rules via indirect callbacks")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
index 38d89d80b4a9..273c9ba48f09 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
@@ -2075,6 +2075,7 @@ int bnxt_init_tc(struct bnxt *bp)
 	rhashtable_destroy(&tc_info->flow_table);
 free_tc_info:
 	kfree(tc_info);
+	bp->tc_info = NULL;
 	return rc;
 }
 
-- 
2.17.1


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

* Re: [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc
  2023-12-04  2:40 [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc Dinghao Liu
@ 2023-12-04  8:56 ` Pavan Chebbi
  2023-12-04 19:14   ` Michael Chan
  2023-12-06  3:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Pavan Chebbi @ 2023-12-04  8:56 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Michael Chan, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sriharsha Basavapatna, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]

On Mon, Dec 4, 2023 at 8:11 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
>
> When flow_indr_dev_register() fails, bnxt_init_tc will free
> bp->tc_info through kfree(). However, the caller function
> bnxt_init_one() will ignore this failure and call
> bnxt_shutdown_tc() on failure of bnxt_dl_register(), where
> a use-after-free happens. Fix this issue by setting
> bp->tc_info to NULL after kfree().
>
> Fixes: 627c89d00fb9 ("bnxt_en: flow_offload: offload tunnel decap rules via indirect callbacks")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> index 38d89d80b4a9..273c9ba48f09 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> @@ -2075,6 +2075,7 @@ int bnxt_init_tc(struct bnxt *bp)
>         rhashtable_destroy(&tc_info->flow_table);
>  free_tc_info:
>         kfree(tc_info);
> +       bp->tc_info = NULL;
>         return rc;
>  }

The other way could have been to assign bp->tc_info only after
flow_indr_dev_register succeeds.
But this one works too. Thanks.
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>

>
> --
> 2.17.1
>
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* Re: [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc
  2023-12-04  8:56 ` Pavan Chebbi
@ 2023-12-04 19:14   ` Michael Chan
  2023-12-05  2:54     ` Somnath Kotur
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Chan @ 2023-12-04 19:14 UTC (permalink / raw)
  To: Pavan Chebbi
  Cc: Dinghao Liu, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sriharsha Basavapatna, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1719 bytes --]

On Mon, Dec 4, 2023 at 12:56 AM Pavan Chebbi <pavan.chebbi@broadcom.com> wrote:
>
> On Mon, Dec 4, 2023 at 8:11 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> >
> > When flow_indr_dev_register() fails, bnxt_init_tc will free
> > bp->tc_info through kfree(). However, the caller function
> > bnxt_init_one() will ignore this failure and call
> > bnxt_shutdown_tc() on failure of bnxt_dl_register(), where
> > a use-after-free happens. Fix this issue by setting
> > bp->tc_info to NULL after kfree().
> >
> > Fixes: 627c89d00fb9 ("bnxt_en: flow_offload: offload tunnel decap rules via indirect callbacks")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > index 38d89d80b4a9..273c9ba48f09 100644
> > --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > @@ -2075,6 +2075,7 @@ int bnxt_init_tc(struct bnxt *bp)
> >         rhashtable_destroy(&tc_info->flow_table);
> >  free_tc_info:
> >         kfree(tc_info);
> > +       bp->tc_info = NULL;
> >         return rc;
> >  }
>
> The other way could have been to assign bp->tc_info only after
> flow_indr_dev_register succeeds.
> But this one works too. Thanks.
> Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>

I think this is the correct fix.  flow_indr_dev_register(), if
successful, may call the driver's call back function and so
bp->tc_info must be set up before the call.  Thanks.

Reviewed-by: Michael Chan <michael.chan@broadcom.com>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

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

* Re: [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc
  2023-12-04 19:14   ` Michael Chan
@ 2023-12-05  2:54     ` Somnath Kotur
  0 siblings, 0 replies; 5+ messages in thread
From: Somnath Kotur @ 2023-12-05  2:54 UTC (permalink / raw)
  To: Michael Chan
  Cc: Pavan Chebbi, Dinghao Liu, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Sriharsha Basavapatna, netdev,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1954 bytes --]

On Tue, Dec 5, 2023 at 2:05 AM Michael Chan <michael.chan@broadcom.com>
wrote:

> On Mon, Dec 4, 2023 at 12:56 AM Pavan Chebbi <pavan.chebbi@broadcom.com>
> wrote:
> >
> > On Mon, Dec 4, 2023 at 8:11 AM Dinghao Liu <dinghao.liu@zju.edu.cn>
> wrote:
> > >
> > > When flow_indr_dev_register() fails, bnxt_init_tc will free
> > > bp->tc_info through kfree(). However, the caller function
> > > bnxt_init_one() will ignore this failure and call
> > > bnxt_shutdown_tc() on failure of bnxt_dl_register(), where
> > > a use-after-free happens. Fix this issue by setting
> > > bp->tc_info to NULL after kfree().
> > >
> > > Fixes: 627c89d00fb9 ("bnxt_en: flow_offload: offload tunnel decap
> rules via indirect callbacks")
> > > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > > ---
> > >  drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > > index 38d89d80b4a9..273c9ba48f09 100644
> > > --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > > +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
> > > @@ -2075,6 +2075,7 @@ int bnxt_init_tc(struct bnxt *bp)
> > >         rhashtable_destroy(&tc_info->flow_table);
> > >  free_tc_info:
> > >         kfree(tc_info);
> > > +       bp->tc_info = NULL;
> > >         return rc;
> > >  }
> >
> > The other way could have been to assign bp->tc_info only after
> > flow_indr_dev_register succeeds.
> > But this one works too. Thanks.
> > Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
>
> I think this is the correct fix.  flow_indr_dev_register(), if
> successful, may call the driver's call back function and so
> bp->tc_info must be set up before the call.  Thanks.
>
> Reviewed-by: Michael Chan <michael.chan@broadcom.com>
>

Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>

[-- Attachment #1.2: Type: text/html, Size: 2975 bytes --]

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

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

* Re: [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc
  2023-12-04  2:40 [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc Dinghao Liu
  2023-12-04  8:56 ` Pavan Chebbi
@ 2023-12-06  3:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-06  3:50 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: michael.chan, davem, edumazet, kuba, pabeni,
	sriharsha.basavapatna, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  4 Dec 2023 10:40:04 +0800 you wrote:
> When flow_indr_dev_register() fails, bnxt_init_tc will free
> bp->tc_info through kfree(). However, the caller function
> bnxt_init_one() will ignore this failure and call
> bnxt_shutdown_tc() on failure of bnxt_dl_register(), where
> a use-after-free happens. Fix this issue by setting
> bp->tc_info to NULL after kfree().
> 
> [...]

Here is the summary with links:
  - net: bnxt: fix a potential use-after-free in bnxt_init_tc
    https://git.kernel.org/netdev/net/c/d007caaaf052

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:[~2023-12-06  3:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04  2:40 [PATCH] net: bnxt: fix a potential use-after-free in bnxt_init_tc Dinghao Liu
2023-12-04  8:56 ` Pavan Chebbi
2023-12-04 19:14   ` Michael Chan
2023-12-05  2:54     ` Somnath Kotur
2023-12-06  3: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).