Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alistair23@gmail.com, linux-pci@vger.kernel.org,
	linux-cxl@vger.kernel.org
Cc: ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v5 12/23] PCI/CMA: Add a PCI TSM CMA driver using SPDM
Date: Tue, 27 Oct 2026 05:46:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-186141@kernel.org> (raw)
In-Reply-To: <20261027052536.1722081-13-alistair.francis@wdc.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] PCI/CMA: pci_cma_tsm_probe() initializes subfunctions without connect()
--

commit 422c44a59294e74ffe91f6512ceb7d64705e55f8
Author: Alistair Francis <alistair.francis@wdc.com>

PCI/CMA: Add a PCI TSM CMA driver using SPDM

This commit adds a PCI TSM driver for Component Measurement and
Authentication (CMA-SPDM) over a PCI DOE mailbox to support device
authentication.

> diff --git a/drivers/pci/cma.c b/drivers/pci/cma.c
> new file mode 100644
> index 0000000000000..6b52b129574ec
> --- /dev/null
> +++ b/drivers/pci/cma.c

[ ... ]

> +static struct pci_tsm *pci_cma_tsm_probe(struct tsm_dev *tsm_dev,
> +					 struct pci_dev *pdev)
> +{
> +	struct pci_cma_tsm *cma;
> +	int rc;
> +
> +	if (!pdev->doe_cma)
> +		return NULL;
> +
> +	cma = kzalloc(sizeof(*cma), GFP_KERNEL);
> +	if (!cma)
> +		return NULL;
> +
> +	rc = pci_tsm_host_constructor(pdev, &cma->host, tsm_dev);
> +	if (rc) {
> +		kfree(cma);
> +		return NULL;
> +	}
> +
> +	cma->spdm = spdm_create(&pdev->dev, pci_doe_transport, cma->host.doe_mb,
> +				PCI_DOE_MAX_PAYLOAD, NULL);
> +	if (!cma->spdm) {
> +		pci_tsm_host_destructor(&cma->host);
> +		kfree(cma);
> +		return NULL;
> +	}
> +
> +	return &cma->host.base_tsm;
> +}

[Severity: High]
Can pci_cma_tsm_probe() be invoked via probe_fn() for subordinate or
sibling PCI functions without pci_cma_tsm_connect() ever being called on
them?

In drivers/pci/tsm.c, ops->probe() is called not only on the target host
device in pci_tsm_connect(), but also via probe_fn() when walking
functions in pci_tsm_connect() (when has_tee(pdev) is true) or when SR-IOV
VFs are initialized in pci_tsm_init():

drivers/pci/tsm.c:probe_fn() {
	if (pdev->tsm)
		return 0;

	pdev->tsm = ops->probe(dsm_dev->tsm->tsm_dev, pdev);
	pci_dbg(pdev, "setup TSM context: DSM: %s status: %s\n",
		pci_name(dsm_dev), pdev->tsm ? "success" : "failed");
	if (pdev->tsm)
		link_sysfs_enable(pdev);
	return 0;
}

drivers/pci/tsm.c:pci_tsm_connect() {
	...
	if (has_tee(pdev))
		pci_tsm_walk_fns(pdev, probe_fn, pdev);
	return 0;
}

Because pci_cma_tsm_probe() only checks pdev->doe_cma, any walked sibling
PF, downstream device, or VF with doe_cma set will have cma->host and
cma->spdm allocated and assigned to pdev->tsm, followed by
link_sysfs_enable(), without pci_cma_tsm_connect() (and thus
spdm_authenticate()) running on that function.

Doesn't this cause a few issues for those walked functions:

1. In drivers/pci/tsm.c, authenticated_show() delegates to connect_show(),
which reports the TSM device name whenever pdev->tsm is non-NULL, falsely
reporting the unauthenticated function as authenticated in sysfs.

2. Any subsequent attempt by userspace to authenticate that function via
connect_store() will fail with -EBUSY because pdev->tsm is already
populated.

3. For sibling PFs and downstream endpoints where is_pci_tsm_host() is
true, pci_tsm_host_constructor() sets sub_pdev->tsm->dsm_dev = sub_pdev
via find_dsm_dev(). When the parent device later disconnects in
__pci_tsm_disconnect(), remove_fn() skips cleaning up sub_pdev:

drivers/pci/tsm.c:remove_fn() {
	if (!pdev->tsm || pdev->tsm->dsm_dev != host)
		return 0;
	...
}

leaving the unauthenticated sub_pdev->tsm and cma->spdm leaked and active.

4. If a VF (pdev->is_virtfn) has doe_cma set, calling
pci_tsm_host_constructor() on it violates the is_pci_tsm_host()
expectation for struct pci_tsm_host.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027052536.1722081-1-alistair.francis@wdc.com?part=12

  reply	other threads:[~2026-10-27  5:46 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  5:25 [PATCH v5 00/23] lib: Rust implementation of SPDM alistair23
2026-10-27  5:25 ` [PATCH v5 01/23] virt: coco: change tsm_register() to use a const struct alistair23
2026-10-27  5:32   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 02/23] rust: create basic untrusted data API alistair23
2026-10-27  5:34   ` sashiko-bot
2026-10-27 13:17     ` Benno Lossin
2026-10-27  5:25 ` [PATCH v5 03/23] rust: validate: add `Validate` trait alistair23
2026-10-27  5:33   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 04/23] X.509: Make certificate parser public alistair23
2026-10-27  5:33   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 05/23] X.509: Parse Subject Alternative Name in certificates alistair23
2026-10-27  5:32   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 06/23] X.509: Move certificate length retrieval into new helper alistair23
2026-10-27  5:32   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 07/23] rust: add bindings for hash.h alistair23
2026-10-27  5:34   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 08/23] rust: device: Expose Device from_raw() publically alistair23
2026-10-27  5:34   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 09/23] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-10-27  5:42   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 10/23] PCI/TSM: Rename pf0 to host alistair23
2026-10-27  5:33   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 11/23] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-10-27  5:50   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 12/23] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-10-27  5:46   ` sashiko-bot [this message]
2026-10-27  5:25 ` [PATCH v5 13/23] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-10-27  5:37   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 14/23] lib: rspdm: Support SPDM get_version alistair23
2026-10-27  5:41   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 15/23] lib: rspdm: Support SPDM get_capabilities alistair23
2026-10-27  5:36   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 16/23] rust: kernel: Add crypto hash bindings alistair23
2026-10-27  5:41   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 17/23] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-10-27  5:43   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 18/23] lib: rspdm: Support SPDM get_digests alistair23
2026-10-27  5:38   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 19/23] lib: rspdm: Support SPDM get_certificate alistair23
2026-10-27  5:35   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 20/23] rust: public_key: Add crypto public key bindings alistair23
2026-10-27  5:41   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 21/23] rust: x509: Add X509 certificate bindings alistair23
2026-10-27  5:45   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 22/23] lib: rspdm: Support SPDM certificate validation alistair23
2026-10-27  5:38   ` sashiko-bot
2026-10-27  5:25 ` [PATCH v5 23/23] lib: rspdm: Support SPDM challenge alistair23
2026-10-27  5:43   ` 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-186141@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alistair23@gmail.com \
    --cc=gary@garyguo.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox