DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vinicius Costa Gomes" <vinicius.gomes@intel.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 4/6] dmaengine: idxd: Fix unwind bounds in device registration error paths
Date: Mon, 12 Oct 2026 21:47:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-168646@kernel.org> (raw)
In-Reply-To: <20261012-wt-idxd-fixes-v1-4-30a35a445077@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dmaengine: idxd: UAF/double-free on device registration failure
--

commit 571be93356be3fdc63d0506588c4e560e5d9eccc
Author: Vinicius Costa Gomes <vinicius.gomes@intel.com>

dmaengine: idxd: Fix unwind bounds in device registration error paths

When registering the per-idxd wq, engine, or group devices, a failure partway
through must roll back exactly the devices already added. This commit fixes
an underflow loop by starting the rollback at i instead of i - 1.

> diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
> index d5ffc641c8567..e828292e5fb88 100644
> --- a/drivers/dma/idxd/sysfs.c
> +++ b/drivers/dma/idxd/sysfs.c
> @@ -1876,7 +1876,7 @@ static int idxd_register_engine_devices(struct idxd_device *idxd)
>  	return 0;
>  
>  cleanup:
> -	j = i - 1;
> +	j = i;
>  	for (; i < idxd->max_engines; i++) {
>  		engine = idxd->engines[i];
>  		put_device(engine_confdev(engine));

[Severity: High]
Does this error handling sequence lead to a double-free of the child devices?

If device registration fails partway, this local cleanup path drops the refcounts
on the child device kobjects via put_device() and device_unregister(), which
frees them.

The failure then cascades up to idxd_register_devices(), which rolls back
previously registered child devices (like WQs), also freeing them. Crucially,
the pointers in idxd->engines and idxd->wqs are left dangling.

Then, the error is returned to idxd_pci_probe_alloc(), which unwinds by jumping
to err_dev_register and explicitly calling idxd_cleanup():

drivers/dma/idxd/init.c:idxd_pci_probe_alloc() {
    ...
	rc = idxd_register_devices(idxd);
	if (rc) {
		dev_err(dev, "IDXD sysfs setup failed\n");
		goto err_dev_register;
	}
    ...
 err_dev_register:
	idxd_cleanup(idxd);
    ...
}

idxd_cleanup() invokes idxd_cleanup_internals(), which iterates over the arrays
via idxd_clean_engines() and calls put_device() again on the dangling pointers:

drivers/dma/idxd/init.c:idxd_clean_engines() {
	for (i = 0; i < idxd->max_engines; i++) {
		conf_dev = engine_confdev(idxd->engines[i]);
		put_device(conf_dev);
	}
}

Could this secondary cleanup access the freed device pointer and execute a
double-put, causing a use-after-free?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-wt-idxd-fixes-v1-0-30a35a445077@intel.com?part=4

  reply	other threads:[~2026-10-12 21:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 21:38 [PATCH 0/6] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-10-12 21:38 ` [PATCH 1/6] dmaengine: idxd: Do not call destroy_workqueue with null idxd->wq Vinicius Costa Gomes
2026-10-13 14:55   ` Frank Li
2026-10-12 21:38 ` [PATCH 2/6] dmaengine: idxd: fix duplicate memory frees on initialization error path Vinicius Costa Gomes
2026-10-13 14:57   ` Frank Li
2026-10-12 21:38 ` [PATCH 3/6] dmaengine: idxd: Fix potential double free on probe " Vinicius Costa Gomes
2026-10-12 21:38 ` [PATCH 4/6] dmaengine: idxd: Fix unwind bounds in device registration error paths Vinicius Costa Gomes
2026-10-12 21:47   ` sashiko-bot [this message]
2026-10-12 21:38 ` [PATCH 5/6] dmaengine: idxd: Fix error code handling in idxd_cdev_open() Vinicius Costa Gomes
2026-10-12 21:50   ` sashiko-bot
2026-10-12 21:38 ` [PATCH 6/6] dmaengine: idxd: Do not release interrupt handles on terminate_all Vinicius Costa Gomes
2026-10-12 21:58   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-168646@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vinicius.gomes@intel.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox