All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: sashiko-reviews@lists.linux.dev
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: Wed, 14 Oct 2026 15:10:28 -0700	[thread overview]
Message-ID: <87o6cwhr1n.fsf@intel.com> (raw)
In-Reply-To: <sashiko-outbox-168646@kernel.org>

sashiko-bot@kernel.org writes:

> 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?
>
> [ ... ]

This wasn't easy to parse at all. But I think (with help from AI, kind
of funny) that I get it now. This is an pre-existing issue, will try to
fix on v2 unless it makes the series become too messy.


Cheers,
-- 
Vinicius

  reply	other threads:[~2026-10-14 22:10 UTC|newest]

Thread overview: 20+ 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-13 17:18   ` Dave Jiang
2026-10-13 22:34     ` Vinicius Costa Gomes
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-13 22:31     ` Vinicius Costa Gomes
2026-10-13 17:21   ` Dave Jiang
2026-10-12 21:38 ` [PATCH 3/6] dmaengine: idxd: Fix potential double free on probe " Vinicius Costa Gomes
2026-10-13 17:30   ` Dave Jiang
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
2026-10-14 22:10     ` Vinicius Costa Gomes [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-14 22:17     ` Vinicius Costa Gomes
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
2026-10-14 22:25     ` Vinicius Costa Gomes

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=87o6cwhr1n.fsf@intel.com \
    --to=vinicius.gomes@intel.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.