All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shuangpeng Bai" <shuangpeng.kernel@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] misc: pci_endpoint_test: fix use-after-free after device unbind
Date: Sun, 21 Jun 2026 06:02:47 +0000	[thread overview]
Message-ID: <20260621060247.B723A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260621054609.186877-1-shuangpeng.kernel@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Deadlock in pci_endpoint_test_remove() on device unbind due to serialization with ioctls that sleep indefinitely.
--

commit 8935a4226276767a2564aa469158f4ffb5341492
Author: Shuangpeng Bai <shuangpeng.kernel@gmail.com>

misc: pci_endpoint_test: fix use-after-free after device unbind

This commit explicitly manages the lifetime of the test object with a kref
to prevent a use-after-free when an open file descriptor outlives the PCI
device binding. The remove path now serializes with ioctl using the
existing mutex and clears device state before dropping the initial
reference.

Closes: https://lore.kernel.org/all/178144969601.60470.7358419009914000395@gmail.com/

> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index dbd017cabbb92..981a834ce41bd 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
[ ... ]
> @@ -1364,10 +1405,13 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
>  	if (id < 0)
>  		return;
>  
> +	misc_deregister(&test->miscdev);
> +
> +	mutex_lock(&test->mutex);
> +

[Severity: High]
Can this lock acquisition cause a deadlock during device unbind?

The ioctl handlers, such as pci_endpoint_test_copy(), hold this same mutex
while waiting indefinitely for hardware interrupts:

    mutex_lock(&test->mutex);
    ...
    wait_for_completion(&test->irq_raised);

If the hardware fails to raise the expected interrupt, perhaps due to a
hardware hang or abrupt hot-unplug, the ioctl thread will block forever
while holding the mutex.

Since pci_endpoint_test_remove() now waits on this mutex, wouldn't a hanging
ioctl permanently block the removal path and deadlock the PCI subsystem for
this device?

>  	pci_endpoint_test_release_irq(test);
>  	pci_endpoint_test_free_irq_vectors(test);
>  
> -	misc_deregister(&test->miscdev);
>  	kfree(misc_device->name);
>  	kfree(test->name);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260621054609.186877-1-shuangpeng.kernel@gmail.com?part=1

  reply	other threads:[~2026-06-21  6:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14 22:16 [BUG] KASAN: slab-use-after-free in pci_endpoint_test_ioctl Shuangpeng Bai
2026-06-15  2:39 ` Greg KH
2026-06-15 20:06   ` Shuangpeng
2026-06-18  3:01 ` Krzysztof Wilczyński
2026-06-21  5:46 ` [PATCH] misc: pci_endpoint_test: fix use-after-free after device unbind Shuangpeng Bai
2026-06-21  6:02   ` sashiko-bot [this message]
2026-06-22 16:52   ` [PATCH v2] " Shuangpeng Bai
2026-06-22 17:15     ` sashiko-bot
2026-06-22 20:40     ` Frank Li

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=20260621060247.B723A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuangpeng.kernel@gmail.com \
    /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.