* [PATCH] dmaengine: idxd: fix double free in idxd_setup_engines() error path
@ 2026-04-01 3:40 Guangshuo Li
2026-04-02 1:37 ` Shuai Xue
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-04-01 3:40 UTC (permalink / raw)
To: Vinicius Costa Gomes, Dave Jiang, Vinod Koul, Fenghua Yu,
Shuai Xue, dmaengine, linux-kernel
Cc: Guangshuo Li, stable
When an error happens after device_initialize(), idxd_setup_engines()
calls put_device(conf_dev).
The device release callback idxd_conf_engine_release() frees engine,
but the current error paths then call kfree(engine) again, causing a
double free.
Keep the cleanup in idxd_conf_engine_release() after put_device() and
avoid freeing engine again in idxd_setup_engines().
Fixes: 817bced19d1d ("dmaengine: idxd: fix memory leak in error handling path of idxd_setup_engines")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/dma/idxd/init.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index d9a9d56dd277..4eff74182225 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -310,7 +310,7 @@ static int idxd_setup_engines(struct idxd_device *idxd)
rc = dev_set_name(conf_dev, "engine%d.%d", idxd->id, engine->id);
if (rc < 0) {
put_device(conf_dev);
- kfree(engine);
+
goto err;
}
@@ -324,7 +324,7 @@ static int idxd_setup_engines(struct idxd_device *idxd)
engine = idxd->engines[i];
conf_dev = engine_confdev(engine);
put_device(conf_dev);
- kfree(engine);
+
}
kfree(idxd->engines);
@@ -374,7 +374,6 @@ static int idxd_setup_groups(struct idxd_device *idxd)
rc = dev_set_name(conf_dev, "group%d.%d", idxd->id, group->id);
if (rc < 0) {
put_device(conf_dev);
-
goto err;
}
@@ -399,7 +398,6 @@ static int idxd_setup_groups(struct idxd_device *idxd)
while (--i >= 0) {
group = idxd->groups[i];
put_device(group_confdev(group));
-
}
kfree(idxd->groups);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] dmaengine: idxd: fix double free in idxd_setup_engines() error path
2026-04-01 3:40 [PATCH] dmaengine: idxd: fix double free in idxd_setup_engines() error path Guangshuo Li
@ 2026-04-02 1:37 ` Shuai Xue
0 siblings, 0 replies; 2+ messages in thread
From: Shuai Xue @ 2026-04-02 1:37 UTC (permalink / raw)
To: Guangshuo Li, Vinicius Costa Gomes, Dave Jiang, Vinod Koul,
Fenghua Yu, dmaengine, linux-kernel
Cc: stable
On 4/1/26 11:40 AM, Guangshuo Li wrote:
> When an error happens after device_initialize(), idxd_setup_engines()
> calls put_device(conf_dev).
>
> The device release callback idxd_conf_engine_release() frees engine,
> but the current error paths then call kfree(engine) again, causing a
> double free.
>
> Keep the cleanup in idxd_conf_engine_release() after put_device() and
> avoid freeing engine again in idxd_setup_engines().
>
> Fixes: 817bced19d1d ("dmaengine: idxd: fix memory leak in error handling path of idxd_setup_engines")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/dma/idxd/init.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
> index d9a9d56dd277..4eff74182225 100644
> --- a/drivers/dma/idxd/init.c
> +++ b/drivers/dma/idxd/init.c
> @@ -310,7 +310,7 @@ static int idxd_setup_engines(struct idxd_device *idxd)
> rc = dev_set_name(conf_dev, "engine%d.%d", idxd->id, engine->id);
> if (rc < 0) {
> put_device(conf_dev);
> - kfree(engine);
> +
> goto err;
> }
>
> @@ -324,7 +324,7 @@ static int idxd_setup_engines(struct idxd_device *idxd)
> engine = idxd->engines[i];
> conf_dev = engine_confdev(engine);
> put_device(conf_dev);
> - kfree(engine);
> +
> }
> kfree(idxd->engines);
>
> @@ -374,7 +374,6 @@ static int idxd_setup_groups(struct idxd_device *idxd)
> rc = dev_set_name(conf_dev, "group%d.%d", idxd->id, group->id);
> if (rc < 0) {
> put_device(conf_dev);
> -
> goto err;
> }
>
> @@ -399,7 +398,6 @@ static int idxd_setup_groups(struct idxd_device *idxd)
> while (--i >= 0) {
> group = idxd->groups[i];
> put_device(group_confdev(group));
> -
> }
> kfree(idxd->groups);
>
Nit: please remove the blank lines left behind by both deletions.
With those addressed:Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>
Thanks.
Shuai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-02 1:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-01 3:40 [PATCH] dmaengine: idxd: fix double free in idxd_setup_engines() error path Guangshuo Li
2026-04-02 1:37 ` Shuai Xue
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®