* [PATCH v2] rapidio: fix an API misues when rio_add_net() fails
@ 2025-02-27 7:34 Haoxiang Li
2025-02-27 9:59 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-02-27 7:34 UTC (permalink / raw)
To: mporter, alex.bou9, haoxiang_li2024, akpm, error27; +Cc: linux-kernel, stable
rio_add_net() calls device_register() and fails when device_register()
fails. Thus, put_device() should be used rather than kfree().
Add "mport->net = NULL;" to avoid a use after free issue.
Fixes: e8de370188d0 ("rapidio: add mport char device driver")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
Changes in v2:
- Add "mport->net = NULL;" to avoid a use after free issue. Thanks, Dan!
---
drivers/rapidio/devices/rio_mport_cdev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 27afbb9d544b..cbf531d0ba68 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1742,7 +1742,8 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv,
err = rio_add_net(net);
if (err) {
rmcd_debug(RDEV, "failed to register net, err=%d", err);
- kfree(net);
+ put_device(&net->dev);
+ mport->net = NULL;
goto cleanup;
}
}
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rapidio: fix an API misues when rio_add_net() fails
2025-02-27 7:34 [PATCH v2] rapidio: fix an API misues when rio_add_net() fails Haoxiang Li
@ 2025-02-27 9:59 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2025-02-27 9:59 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mporter, alex.bou9, akpm, error27, linux-kernel, stable
On Thu, Feb 27, 2025 at 03:34:09PM +0800, Haoxiang Li wrote:
> rio_add_net() calls device_register() and fails when device_register()
> fails. Thus, put_device() should be used rather than kfree().
> Add "mport->net = NULL;" to avoid a use after free issue.
>
> Fixes: e8de370188d0 ("rapidio: add mport char device driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
> Changes in v2:
> - Add "mport->net = NULL;" to avoid a use after free issue. Thanks, Dan!
Thank you!
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-27 9:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27 7:34 [PATCH v2] rapidio: fix an API misues when rio_add_net() fails Haoxiang Li
2025-02-27 9:59 ` Dan Carpenter
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®