From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, ojeda@kernel.org
Subject: Re: [PATCH v2 11/21] PCI/TSM: Support connecting to PCIe CMA devices
Date: Tue, 23 Jun 2026 05:16:20 +0000 [thread overview]
Message-ID: <20260623051620.95CD11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623045406.2589547-12-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Bypassing the function 0 check for CMA-capable devices breaks the subsystem's architectural assumptions and physical function iteration logic, leading to UAF when unlocking a freed mutex on disconnect.
- [High] Calling `pci_find_doe_mailbox()` inside `is_pci_tsm_host()` introduces a Use-After-Free vulnerability when iterating over PCI devices, as DOE mailboxes can be concurrently freed by device removal.
--
commit 4f85c4326e0a051322285638e0233e1946a251be
Author: Alistair Francis <alistair.francis@wdc.com>
PCI/TSM: Support connecting to PCIe CMA devices
In the next patch we are going to add a PCIe CMA TSM driver, as such we
need to ensure that is_pci_tsm_host() will allow us to connect to CMA
capable devices. These devices don't necessarily has DEVCAP_TEE or IDE
support.
> diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
> --- a/include/linux/pci-tsm.h
> +++ b/include/linux/pci-tsm.h
[ ... ]
> @@ -142,6 +143,14 @@ static inline bool is_pci_tsm_host(struct pci_dev *pdev)
> if (pdev->is_virtfn)
> return false;
>
> + /*
> + * Report capable if CMA is supported, which can be supported on any PCIe
> + * device.
> + */
> + if (pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG,
> + PCI_DOE_FEATURE_CMA))
> + return true;
[Severity: High]
Does returning true for devices where the function is not 0 cause a use
after free during device disconnect?
If a CMA-capable device connects where its function number is greater
than 0, when the device is disconnected, __pci_tsm_disconnect() invokes
pci_tsm_walk_fns_reverse().
The reverse walk hardcodes the assumption that the host is function 0:
drivers/pci/tsm.c:pci_tsm_walk_fns_reverse() {
...
/* on exit, caller will run @cb on function 0 */
if (i > 0)
cb(pf, data);
...
}
Because the host is a non-zero function, the walk mistakenly runs remove_fn
on the host itself, freeing the memory containing tsm_host.
drivers/pci/tsm.c:__pci_tsm_disconnect() {
guard(mutex)(&tsm_host->lock);
pci_tsm_walk_fns_reverse(pdev, remove_fn, NULL);
ops->disconnect(pdev);
}
When __pci_tsm_disconnect() returns, does dropping the guard unlock a mutex
in the already freed memory?
[Severity: High]
Is it safe to call pci_find_doe_mailbox() here while iterating over PCI
devices without holding the device lock?
The TSM subsystem iterates over all PCI devices using for_each_pci_dev(),
repeatedly invoking is_pci_tsm_host(). While this holds a kref on the
device, pci_find_doe_mailbox() performs a lockless iteration over the xarray
without an RCU read lock:
drivers/pci/doe.c:pci_find_doe_mailbox() {
...
xa_for_each(&pdev->doe_mbs, index, doe_mb)
if (pci_doe_supports_feat(doe_mb, vendor, type))
return doe_mb;
...
}
During concurrent device hot-removal, pci_destroy_dev() unconditionally
destroys mailboxes directly, without waiting for an RCU grace period:
drivers/pci/doe.c:pci_doe_destroy_mb() {
...
kfree(doe_mb);
...
}
Can this lead to a use after free where pci_find_doe_mailbox() dereferences
mailboxes that have already been freed by a concurrent removal thread?
> +
> /*
> * Allow for a Device Security Manager (DSM) associated with function0
> * of an Endpoint to coordinate TDISP requests for other functions
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260623045406.2589547-1-alistair.francis@wdc.com?part=11
next prev parent reply other threads:[~2026-06-23 5:16 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 4:53 [PATCH v2 00/21] lib: Rust implementation of SPDM alistair23
2026-06-23 4:53 ` [PATCH v2 01/21] rust: transmute: add `cast_slice[_mut]` functions alistair23
2026-06-23 5:05 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 02/21] rust: create basic untrusted data API alistair23
2026-06-23 5:09 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 03/21] rust: validate: add `Validate` trait alistair23
2026-06-23 5:10 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 04/21] X.509: Make certificate parser public alistair23
2026-06-23 5:03 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 05/21] X.509: Parse Subject Alternative Name in certificates alistair23
2026-06-23 5:07 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 06/21] X.509: Move certificate length retrieval into new helper alistair23
2026-06-23 5:02 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 07/21] rust: add bindings for hash.h alistair23
2026-06-23 7:01 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 08/21] rust: error: impl From<FromBytesWithNulError> for Kernel Error alistair23
2026-06-23 5:01 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 09/21] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-06-23 5:09 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 10/21] PCI/TSM: Rename pf0 to host alistair23
2026-06-23 5:12 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 11/21] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-06-23 5:16 ` sashiko-bot [this message]
2026-06-23 4:53 ` [PATCH v2 12/21] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-06-23 5:07 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 13/21] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-06-23 5:07 ` sashiko-bot
2026-06-23 4:53 ` [PATCH v2 14/21] lib: rspdm: Support SPDM get_version alistair23
2026-06-23 5:10 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 15/21] lib: rspdm: Support SPDM get_capabilities alistair23
2026-06-23 5:09 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 16/21] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-06-23 5:17 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 17/21] lib: rspdm: Support SPDM get_digests alistair23
2026-06-23 5:17 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 18/21] lib: rspdm: Support SPDM get_certificate alistair23
2026-06-23 5:20 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 19/21] lib: rspdm: Support SPDM certificate validation alistair23
2026-06-23 5:19 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 20/21] rust: allow extracting the buffer from a CString alistair23
2026-06-23 5:13 ` sashiko-bot
2026-06-23 4:54 ` [PATCH v2 21/21] lib: rspdm: Support SPDM challenge alistair23
2026-06-23 5:21 ` 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=20260623051620.95CD11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alistair23@gmail.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--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.