octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
PATCH 1/1 octeontx2-af: fix a use-after-free in rvu_npa_register_reporters
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.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +1 -4
@@ -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)
Signature · 1 line
2.34.1
Quoted 35 lines · Zhipeng Lu
The
rvu_dlwill be freed inrvu_npa_health_reporters_destroy(rvu_dl)after thecreate_workqueuefails, and after that free, thervu_dlwill be translate back throughrvu_npa_health_reporters_create,rvu_health_reporters_create, andrvu_register_dl. Finally it goes to theerr_dl_healthlabel, being freed again inrvu_health_reporters_destroy(rvu)byrvu_npa_health_reporters_destroy. In the second calls ofrvu_npa_health_reporters_destroy, however, it usesrvu_dl->rvu_npa_health_reporter, which is already freed at the end ofrvu_npa_health_reporters_destroyin the first call.So this patch prevents the first destroy by instantly returning
-ENONMENwhencreate_workqueuefails. In addition, since the failure ofcreate_workqueueis the only entrence of label err, it has been integrated into the error-handling path ofcreate_workqueue.Fixes f1168d1e207c ("octeontx2-af: Add devlink health reporters for NPA")Signed-off-by Zhipeng Lu <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +1
-1@@ -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);
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c static int rvu_npa_register_reporters(struct rvu_devlink *rvu_dl) · line 1298
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +0
-3@@ -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
but allow some little more time for Marvel's people to have a better look.
Cheers,
Paolo
Geethasowjanya Akula
maintainerQuoted 74 lines
-----Original Message-----
From: Paolo Abeni <[email protected]>
Sent: Tuesday, December 5, 2023 6:05 PM
To: Zhipeng Lu <[email protected]>
Cc: Sunil Kovvuri Goutham <[email protected]>; Linu Cherian <[email protected]>; Geethasowjanya Akula <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Hariprasad Kelam <[email protected]>; Subbaraya Sundeep Bhatta <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; George Cherian <[email protected]>; [email protected]; linux- [email protected]
Subject: [EXT] Re: [PATCH] octeontx2-af: fix a use-after-free inrvu_npa_register_reportersExternal Email
----------------------------------------------------------------------
Quoted 36 lines · Zhipeng Lu
The
rvu_dlwill be freed inrvu_npa_health_reporters_destroy(rvu_dl)after thecreate_workqueuefails, and after that free, thervu_dlwill be translate back throughrvu_npa_health_reporters_create,rvu_health_reporters_create, andrvu_register_dl. Finally it goes to theerr_dl_healthlabel, being freed again inrvu_health_reporters_destroy(rvu)byrvu_npa_health_reporters_destroy. In the second calls ofrvu_npa_health_reporters_destroy, however, it usesrvu_dl->rvu_npa_health_reporter, which is already freed at the end ofrvu_npa_health_reporters_destroyin the first call.So this patch prevents the first destroy by instantly returning
-ENONMENwhencreate_workqueuefails. In addition, since the failure ofcreate_workqueueis the only entrence of label err, it has been integrated into the error-handling path ofcreate_workqueue.Fixes f1168d1e207c ("octeontx2-af: Add devlink health reporters forNPA")
Signed-off-by Zhipeng Lu <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +1
-1@@ -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);Quoted 1 line
INIT_WORK(&rvu_reporters->err_work, rvu_npa_err_work); @@ -1293,9
Quoted 1 line
+1293,6 @@ static int rvu_npa_register_reporters(struct
rvu_devlink
*rvu_dl)Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +0
-3INIT_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
Quoted 7 lines
Acked-by Paolo Abeni <[email protected]>but allow some little more time for Marvel's people to have a better look.
Cheers,
Paolo
Ack. Thanks for the patch.
Quoted 5 lines · Geethasowjanya Akula
Quoted 5 lines
-----Original Message-----
From: Paolo Abeni <[email protected]>
Sent: Tuesday, December 5, 2023 6:05 PM
LGTM
Quoted 8 lines
Quoted 7 lines
Acked-by Paolo Abeni <[email protected]>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:
so that the tools we use will propagate it automatically.
Cheers,
Paolo
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Sat, 2 Dec 2023 17:59:02 +0800 you wrote:
The
rvu_dlwill be freed inrvu_npa_health_reporters_destroy(rvu_dl)after thecreate_workqueuefails, and after that free, thervu_dlwill be translate back throughrvu_npa_health_reporters_create,rvu_health_reporters_create, andrvu_register_dl. Finally it goes to theerr_dl_healthlabel, being freed again inrvu_health_reporters_destroy(rvu)byrvu_npa_health_reporters_destroy. In the second calls ofrvu_npa_health_reporters_destroy, however, it usesrvu_dl->rvu_npa_health_reporter, which is already freed at the end ofrvu_npa_health_reporters_destroyin 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html