From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: sashiko-reviews@lists.linux.dev, iommu@lists.linux.dev,
linux-coco@lists.linux.dev, Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [PATCH v7 16/16] PCI/TSM: wait for vdevice contexts before removing a DSM
Date: Mon, 12 Oct 2026 15:31:17 +0530 [thread overview]
Message-ID: <yq5atsmr44r6.fsf@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-163687@kernel.org>
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] PCI/TSM: UAF due to bypassed drain wait in pci_tsm_unregister()
> --
>
> commit 70b40a7c8d41eb1bbe070cea07e7f252f47338e8
> Author: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>
> PCI/TSM: wait for vdevice contexts before removing a DSM
>
> A PF0 DSM can be removed while a sibling function still has a vdevice.
> The context pins both the pci dev, but those references do not keep the
> PF0 DOE mailbox alive. Ignoring -EBUSY from link disconnect lets PCI
> continue to pci_doe_destroy(), leaving the vdevice with a stale mailbox
> pointer.
>
>> diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
>> index c8603867e09df..8aa74ba31932b 100644
>> --- a/drivers/pci/tsm.c
>> +++ b/drivers/pci/tsm.c
> [ ... ]
>> @@ -751,8 +769,44 @@ static void __pci_tsm_destroy(struct pci_dev *pdev, struct tsm_dev *tsm_dev)
>>
>> void pci_tsm_destroy(struct pci_dev *pdev)
>> {
>> - guard(rwsem_write)(&pci_tsm_rwsem);
>> + struct pci_tsm_pf0 *pf0 = NULL;
>> + struct completion *drained;
>> + bool interrupted = false;
>> + long rc;
>> +
>> + down_write(&pci_tsm_rwsem);
>> + if (pdev->tsm && is_link_tsm(pdev->tsm->tsm_dev) &&
>> + is_pci_tsm_pf0(pdev)) {
>> + pf0 = to_pci_tsm_pf0(pdev->tsm);
>> + drained = &pf0->contexts_drained;
>> + mutex_lock(&pf0->lock);
>> + pf0->removing = true;
>> + mutex_unlock(&pf0->lock);
>> +
>> + /* An unused DSM may never have completed contexts_drained. */
>> + rc = pf0->context_users ?
>> + try_wait_for_completion(drained) : 1;
>> + /* Context release needs the read side of pci_tsm_rwsem. */
>> + up_write(&pci_tsm_rwsem);
>> + while (rc <= 0) {
> [ ... ]
>> + if (!rc)
>> + pci_warn(pdev, "TSM connection is in use, waiting for vdevices\n");
>> + }
>> + down_write(&pci_tsm_rwsem);
>> + }
>> __pci_tsm_destroy(pdev, NULL);
>> + up_write(&pci_tsm_rwsem);
>> }
>
> [Severity: High]
> This adds the context drain wait loop when the PCI device is destroyed, but
> what happens when the TSM provider device is unbound and calls
> pci_tsm_unregister() first?
>
> Looking at pci_tsm_unregister() in drivers/pci/tsm.c, it directly calls
> __pci_tsm_destroy(pdev, tsm_dev) bypassing this new wait loop:
>
> drivers/pci/tsm.c:pci_tsm_unregister() {
> ...
> for_each_pci_dev_reverse(pdev)
> __pci_tsm_destroy(pdev, tsm_dev);
> }
>
> If contexts are active, __pci_tsm_destroy() skips clearing pdev->tsm
> because pci_tsm_disconnect() will return -EBUSY:
>
> drivers/pci/tsm.c:__pci_tsm_destroy() {
> ...
> if (is_link_tsm(tsm_dev) && is_pci_tsm_pf0(pdev)) {
> if (pci_tsm_disconnect(pdev))
> pci_warn(pdev, "TSM connection is still in use\n");
> } else {
> ...
> }
>
> tsm_unregister() then drops its reference, and the provider frees the
> underlying pci_tsm memory. Later, when the PCI core calls this modified
> pci_tsm_destroy(), won't it dereference the already freed pdev->tsm and
> pdev->tsm->tsm_dev pointers here?
>
With this series, vdevices hold a reference to their parent vIOMMU,
which pins arm-cca-host. sysfs unbind is disabled, and the SMCCC
provider device has no hot-unplug path.
-aneesh
next prev parent reply other threads:[~2026-10-12 10:01 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 5:59 [PATCH v7 00/16] iommufd: vIOMMUs and TSM guest requests for confidential guests Aneesh Kumar K.V (Arm)
2026-10-08 5:59 ` [PATCH v7 01/16] KVM: Introduce file_to_kvm_<arch>() infrastructure Aneesh Kumar K.V (Arm)
2026-10-08 6:11 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 02/16] KVM: Add file back-pointer to struct kvm Aneesh Kumar K.V (Arm)
2026-10-08 6:16 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 03/16] KVM: x86: Use file_to_kvm_x86() in SEV Aneesh Kumar K.V (Arm)
2026-10-08 6:07 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 04/16] KVM/vfio: Use file-based reference counting for KVM Aneesh Kumar K.V (Arm)
2026-10-08 6:27 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 05/16] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Aneesh Kumar K.V (Arm)
2026-10-08 6:08 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 06/16] KVM: Remove unused file_is_kvm Aneesh Kumar K.V (Arm)
2026-10-08 6:06 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 07/16] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-10-08 6:20 ` sashiko-bot
2026-10-12 8:33 ` Aneesh Kumar K.V
2026-10-12 12:24 ` Jason Gunthorpe
2026-10-08 5:59 ` [PATCH v7 08/16] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-10-08 6:10 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 09/16] tsm: Remove the device from lookup before PCI teardown Aneesh Kumar K.V (Arm)
2026-10-08 6:15 ` sashiko-bot
2026-10-12 9:14 ` Aneesh Kumar K.V
2026-10-12 13:01 ` Jason Gunthorpe
2026-10-13 8:49 ` Aneesh Kumar K.V
2026-10-13 11:57 ` Jason Gunthorpe
2026-10-08 5:59 ` [PATCH v7 10/16] iommufd: Add the vdevice TSM request ioctl Aneesh Kumar K.V (Arm)
2026-10-08 6:10 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 11/16] PCI/TSM: Remove the legacy guest request interface Aneesh Kumar K.V (Arm)
2026-10-08 6:11 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 12/16] PCI/TSM: Add vIOMMU-bound contexts for vdevices Aneesh Kumar K.V (Arm)
2026-10-08 6:18 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 13/16] iommufd/viommu: Select vIOMMU operations before allocation Aneesh Kumar K.V (Arm)
2026-10-08 6:27 ` sashiko-bot
2026-10-12 9:37 ` Aneesh Kumar K.V
2026-10-12 13:05 ` Jason Gunthorpe
2026-10-13 9:11 ` Aneesh Kumar K.V
2026-10-08 5:59 ` [PATCH v7 14/16] iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations Aneesh Kumar K.V (Arm)
2026-10-08 6:19 ` sashiko-bot
2026-10-12 9:55 ` Aneesh Kumar K.V
2026-10-08 5:59 ` [PATCH v7 15/16] iommufd: Allow vIOMMUs without a parent HWPT Aneesh Kumar K.V (Arm)
2026-10-08 6:24 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 16/16] PCI/TSM: wait for vdevice contexts before removing a DSM Aneesh Kumar K.V (Arm)
2026-10-08 6:25 ` sashiko-bot
2026-10-12 10:01 ` Aneesh Kumar K.V [this message]
2026-10-12 13:07 ` Jason Gunthorpe
2026-10-13 9:44 ` Aneesh Kumar K.V
2026-10-13 11:59 ` Jason Gunthorpe
2026-10-12 20:34 ` Bjorn Helgaas
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=yq5atsmr44r6.fsf@kernel.org \
--to=aneesh.kumar@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=linux-coco@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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.