mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
@ 2023-12-02  9:59 Zhipeng Lu
  2023-12-05 12:35 ` Paolo Abeni
  2023-12-05 14:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Zhipeng Lu @ 2023-12-02  9:59 UTC (permalink / raw)
  To: alexious
  Cc: Sunil Goutham, Linu Cherian, Geetha sowjanya, Jerin Jacob,
	hariprasad, Subbaraya Sundeep, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, George Cherian, netdev,
	linux-kernel

The rvu_dl will be freed in rvu_npa_health_reporters_destroy(rvu_dl)
after the create_workqueue fails, and after that free, the rvu_dl will
be translate back through rvu_npa_health_reporters_create,
rvu_health_reporters_create, and rvu_register_dl. Finally it goes to the
err_dl_health label, being freed again in
rvu_health_reporters_destroy(rvu) by rvu_npa_health_reporters_destroy.
In the second calls of rvu_npa_health_reporters_destroy, however,
it uses rvu_dl->rvu_npa_health_reporter, which is already freed at
the end of rvu_npa_health_reporters_destroy in the first call.

So this patch prevents the first destroy by instantly returning -ENONMEN
when create_workqueue fails. In addition, since the failure of
create_workqueue is the only entrence of label err, it has been
integrated into the error-handling path of create_workqueue.

Fixes: f1168d1e207c ("octeontx2-af: Add devlink health reporters for NPA")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
index 41df5ac23f92..058f75dc4c8a 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
@@ -1285,7 +1285,7 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl)
 
 	rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq");
 	if (!rvu_dl->devlink_wq)
-		goto err;
+		return -ENOMEM;
 
 	INIT_WORK(&rvu_reporters->intr_work, rvu_npa_intr_work);
 	INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work);
@@ -1293,9 +1293,6 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl)
 	INIT_WORK(&rvu_reporters->ras_work, rvu_npa_ras_work);
 
 	return 0;
-err:
-	rvu_npa_health_reporters_destroy(rvu_dl);
-	return -ENOMEM;
 }
 
 static int rvu_npa_health_reporters_create(struct rvu_devlink *rvu_dl)
-- 
2.34.1


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

* Re: [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
  2023-12-02  9:59 [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters Zhipeng Lu
@ 2023-12-05 12:35 ` Paolo Abeni
  2023-12-05 13:13   ` [EXT] " Geethasowjanya Akula
  2023-12-05 14:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2023-12-05 12:35 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: Sunil Goutham, Linu Cherian, Geetha sowjanya, Jerin Jacob,
	hariprasad, Subbaraya Sundeep, David S. Miller, Eric Dumazet,
	Jakub Kicinski, George Cherian, netdev, linux-kernel

On Sat, 2023-12-02 at 17:59 +0800, Zhipeng Lu wrote:
> The rvu_dl will be freed in rvu_npa_health_reporters_destroy(rvu_dl)
> after the create_workqueue fails, and after that free, the rvu_dl will
> be translate back through rvu_npa_health_reporters_create,
> rvu_health_reporters_create, and rvu_register_dl. Finally it goes to the
> err_dl_health label, being freed again in
> rvu_health_reporters_destroy(rvu) by rvu_npa_health_reporters_destroy.
> In the second calls of rvu_npa_health_reporters_destroy, however,
> it uses rvu_dl->rvu_npa_health_reporter, which is already freed at
> the end of rvu_npa_health_reporters_destroy in the first call.
> 
> So this patch prevents the first destroy by instantly returning -ENONMEN
> when create_workqueue fails. In addition, since the failure of
> create_workqueue is the only entrence of label err, it has been
> integrated into the error-handling path of create_workqueue.
> 
> Fixes: f1168d1e207c ("octeontx2-af: Add devlink health reporters for NPA")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
>  drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> index 41df5ac23f92..058f75dc4c8a 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> @@ -1285,7 +1285,7 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl)
>  
>  	rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq");
>  	if (!rvu_dl->devlink_wq)
> -		goto err;
> +		return -ENOMEM;
>  
>  	INIT_WORK(&rvu_reporters->intr_work, rvu_npa_intr_work);
>  	INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work);
> @@ -1293,9 +1293,6 @@ static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl)
>  	INIT_WORK(&rvu_reporters->ras_work, rvu_npa_ras_work);
>  
>  	return 0;
> -err:
> -	rvu_npa_health_reporters_destroy(rvu_dl);
> -	return -ENOMEM;
>  }
>  
>  static int rvu_npa_health_reporters_create(struct rvu_devlink *rvu_dl)

LGTM

Acked-by: Paolo Abeni <pabeni@redhat.com>

but allow some little more time for Marvel's people to have a better
look.

Cheers,

Paolo


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

* RE: [EXT] Re: [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
  2023-12-05 12:35 ` Paolo Abeni
@ 2023-12-05 13:13   ` Geethasowjanya Akula
  2023-12-05 14:43     ` Paolo Abeni
  0 siblings, 1 reply; 5+ messages in thread
From: Geethasowjanya Akula @ 2023-12-05 13:13 UTC (permalink / raw)
  To: Paolo Abeni, Zhipeng Lu
  Cc: Sunil Kovvuri Goutham, Linu Cherian, Jerin Jacob Kollanukkaran,
	Hariprasad Kelam, Subbaraya Sundeep Bhatta, David S. Miller,
	Eric Dumazet, Jakub Kicinski, George Cherian, netdev,
	linux-kernel



> -----Original Message-----
> From: Paolo Abeni <pabeni@redhat.com>
> Sent: Tuesday, December 5, 2023 6:05 PM
> To: Zhipeng Lu <alexious@zju.edu.cn>
> Cc: Sunil Kovvuri Goutham <sgoutham@marvell.com>; Linu Cherian
> <lcherian@marvell.com>; Geethasowjanya Akula <gakula@marvell.com>;
> Jerin Jacob Kollanukkaran <jerinj@marvell.com>; Hariprasad Kelam
> <hkelam@marvell.com>; Subbaraya Sundeep Bhatta
> <sbhatta@marvell.com>; David S. Miller <davem@davemloft.net>; Eric
> Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>;
> George Cherian <gcherian@marvell.com>; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [EXT] Re: [PATCH] octeontx2-af: fix a use-after-free in
> rvu_npa_register_reporters
> 
> External Email
> 
> ----------------------------------------------------------------------
> On Sat, 2023-12-02 at 17:59 +0800, Zhipeng Lu wrote:
> > The rvu_dl will be freed in rvu_npa_health_reporters_destroy(rvu_dl)
> > after the create_workqueue fails, and after that free, the rvu_dl will
> > be translate back through rvu_npa_health_reporters_create,
> > rvu_health_reporters_create, and rvu_register_dl. Finally it goes to
> > the err_dl_health label, being freed again in
> > rvu_health_reporters_destroy(rvu) by rvu_npa_health_reporters_destroy.
> > In the second calls of rvu_npa_health_reporters_destroy, however, it
> > uses rvu_dl->rvu_npa_health_reporter, which is already freed at the
> > end of rvu_npa_health_reporters_destroy in the first call.
> >
> > So this patch prevents the first destroy by instantly returning
> > -ENONMEN when create_workqueue fails. In addition, since the failure
> > of create_workqueue is the only entrence of label err, it has been
> > integrated into the error-handling path of create_workqueue.
> >
> > Fixes: f1168d1e207c ("octeontx2-af: Add devlink health reporters for
> > NPA")
> > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> > ---
> >  drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> > b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> > index 41df5ac23f92..058f75dc4c8a 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
> > @@ -1285,7 +1285,7 @@ static int rvu_npa_register_reporters(struct
> > rvu_devlink *rvu_dl)
> >
> >  	rvu_dl->devlink_wq = create_workqueue("rvu_devlink_wq");
> >  	if (!rvu_dl->devlink_wq)
> > -		goto err;
> > +		return -ENOMEM;
> >
> >  	INIT_WORK(&rvu_reporters->intr_work, rvu_npa_intr_work);
> >  	INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work); @@ -
> 1293,9
> > +1293,6 @@ static int rvu_npa_register_reporters(struct rvu_devlink
> *rvu_dl)
> >  	INIT_WORK(&rvu_reporters->ras_work, rvu_npa_ras_work);
> >
> >  	return 0;
> > -err:
> > -	rvu_npa_health_reporters_destroy(rvu_dl);
> > -	return -ENOMEM;
> >  }
> >
> >  static int rvu_npa_health_reporters_create(struct rvu_devlink
> > *rvu_dl)
> 
> LGTM
> 
> Acked-by: Paolo Abeni <pabeni@redhat.com>
> 
> but allow some little more time for Marvel's people to have a better look.
> 
> Cheers,
> 
> Paolo
Ack. Thanks for the patch. 


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

* Re: [EXT] Re: [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
  2023-12-05 13:13   ` [EXT] " Geethasowjanya Akula
@ 2023-12-05 14:43     ` Paolo Abeni
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2023-12-05 14:43 UTC (permalink / raw)
  To: Geethasowjanya Akula
  Cc: Sunil Kovvuri Goutham, Linu Cherian, Jerin Jacob Kollanukkaran,
	Hariprasad Kelam, Subbaraya Sundeep Bhatta, David S. Miller,
	Eric Dumazet, Jakub Kicinski, George Cherian, netdev,
	linux-kernel, Zhipeng Lu

On Tue, 2023-12-05 at 13:13 +0000, Geethasowjanya Akula wrote:
> > -----Original Message-----
> > From: Paolo Abeni <pabeni@redhat.com>
> > Sent: Tuesday, December 5, 2023 6:05 PM
> > LGTM
> > 
> > Acked-by: Paolo Abeni <pabeni@redhat.com>
> > 
> > but allow some little more time for Marvel's people to have a better look.
> > 
> > Cheers,
> > 
> > Paolo
> Ack. Thanks for the patch. 

Thanks for the review! 

Next time, please use the formal tag:

Acked-by: <you> <your email address> 

so that the tools we use will propagate it automatically.

Cheers,

Paolo


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

* Re: [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
  2023-12-02  9:59 [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters Zhipeng Lu
  2023-12-05 12:35 ` Paolo Abeni
@ 2023-12-05 14:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-05 14:50 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: sgoutham, lcherian, gakula, jerinj, hkelam, sbhatta, davem,
	edumazet, kuba, pabeni, george.cherian, netdev, linux-kernel

Hello:

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

On Sat,  2 Dec 2023 17:59:02 +0800 you wrote:
> The rvu_dl will be freed in rvu_npa_health_reporters_destroy(rvu_dl)
> after the create_workqueue fails, and after that free, the rvu_dl will
> be translate back through rvu_npa_health_reporters_create,
> rvu_health_reporters_create, and rvu_register_dl. Finally it goes to the
> err_dl_health label, being freed again in
> rvu_health_reporters_destroy(rvu) by rvu_npa_health_reporters_destroy.
> In the second calls of rvu_npa_health_reporters_destroy, however,
> it uses rvu_dl->rvu_npa_health_reporter, which is already freed at
> the end of rvu_npa_health_reporters_destroy in the first call.
> 
> [...]

Here is the summary with links:
  - octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
    https://git.kernel.org/netdev/net/c/3c91c909f13f

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-05 14:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-02  9:59 [PATCH] octeontx2-af: fix a use-after-free in rvu_npa_register_reporters Zhipeng Lu
2023-12-05 12:35 ` Paolo Abeni
2023-12-05 13:13   ` [EXT] " Geethasowjanya Akula
2023-12-05 14:43     ` Paolo Abeni
2023-12-05 14: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

all inboxes | Powered by JetHome®