diff mbox series

net: bnxt: fix a potential use-after-free in bnxt_init_tc

Message ID 20231204024004.8245-1-dinghao.liu@zju.edu.cn (mailing list archive)
State Accepted
Commit d007caaaf052f82ca2340d4c7b32d04a3f5dbf3f
Delegated to: Netdev Maintainers
Headers show
Series net: bnxt: fix a potential use-after-free in bnxt_init_tc | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors;
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: 1115 this patch: 1115
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 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

Commit Message

Dinghao Liu Dec. 4, 2023, 2:40 a.m. UTC
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(+)

Comments

Pavan Chebbi Dec. 4, 2023, 8:56 a.m. UTC | #1
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
>
>
Michael Chan Dec. 4, 2023, 7:14 p.m. UTC | #2
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>
Somnath Kotur Dec. 5, 2023, 2:54 a.m. UTC | #3
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>
patchwork-bot+netdevbpf@kernel.org Dec. 6, 2023, 3:50 a.m. UTC | #4
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!
diff mbox series

Patch

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;
 }