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 v6 23/25] lib: rspdm: Support SPDM certificate validation
Date: Tue, 10 Nov 2026 04:51:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-206245@kernel.org> (raw)
In-Reply-To: <20261110041832.1730924-24-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] rspdm: premature take_public_key() before validate in
validate_cert_chain()
- [Medium] rspdm: missing leaf key algorithm and size check in
validate_cert_chain()
--
commit 90c6956b70972b83efecdd912863a7121463499f
Author: Alistair Francis <alistair.francis@wdc.com>
lib: rspdm: Support SPDM certificate validation
This commit adds certificate chain digest verification, X.509 chain
signature validation, and leaf public key extraction to the Rust SPDM
implementation.
> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> index f1a55da1f1cfa..dfe2f8becfb74 100644
> --- a/lib/rspdm/state.rs
> +++ b/lib/rspdm/state.rs
[ ... ]
> @@ -593,9 +604,164 @@ pub(crate) fn get_certificate(&mut self, slot: u8) -> Result<(), Error> {
[ ... ]
> + let Some(mut leaf) = prev_cert.take() else {
> + return Err(EPROTO);
> + };
> +
> + let flags = leaf.key_ext_flags()?;
> + if flags.is_ca() || !flags.digital_signature() {
> + dev_err!(&self.dev, "Invalid leaf certificate constraints\n");
> + return Err(EKEYREJECTED);
> + }
[Severity: Medium]
Should validate_cert_chain() verify that leaf.pkey_algo() and
leaf.pkey_len() match the session's negotiated self.base_asym_alg?
Without checking the leaf key's algorithm and size against
self.base_asym_alg, a responder that negotiated a strong algorithm in
NEGOTIATE_ALGORITHMS (for example ECDSA P-384 or RSA-4096) can supply a
leaf certificate with a different or weaker key accepted by the X.509
parser, and validate_cert_chain() will accept the chain and store the
mismatched key in self.leaf_key.
> +
> + // The leaf key is the same for all slots (MULT_KEY_CAP == 0),
> + // so just store the first one.
> + if self.leaf_key.is_none() {
> + self.leaf_key = leaf.take_public_key();
> + }
> +
> + if let Some(validate) = self.validate {
> + // SAFETY: Call the `validate` function provided with a valid
> + // certificate pointer, which the callback must not modify or
> + // free.
> + let rc = unsafe { validate(self.dev.as_raw(), slot, leaf.as_raw()) };
> + to_result(rc)?;
> + }
> +
> + Ok(())
> + }
> }
[Severity: Medium]
Does calling leaf.take_public_key() before invoking self.validate pass a
struct x509_certificate with a NULL pub pointer to the callback on the
first slot?
Certificate::take_public_key() transfers ownership of the key by clearing
cert->pub to NULL in place:
rust/kernel/x509.rs:Certificate::take_public_key() {
...
unsafe {
(*self.cert.as_ptr()).pub_ = ptr::null_mut();
}
...
}
As a result, on the first validated slot a validate callback that inspects
leaf_cert->pub will dereference a NULL pointer, and if the callback
rejects the certificate, self.leaf_key remains populated with the rejected
certificate's key. Moving the self.leaf_key assignment after the
self.validate check avoids both issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110041832.1730924-1-alistair.francis@wdc.com?part=23
next prev parent reply other threads:[~2026-11-10 4:51 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 4:18 [PATCH v6 00/25] lib: Rust implementation of SPDM alistair23
2026-11-10 4:18 ` [PATCH v6 01/25] virt: coco: change tsm_register() to use a const struct alistair23
2026-11-10 4:27 ` sashiko-bot
2026-11-12 2:39 ` Jonathan Cameron
2026-11-12 3:16 ` Alistair Francis
2026-11-10 4:18 ` [PATCH v6 02/25] rust: create basic untrusted data API alistair23
2026-11-10 4:34 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 03/25] rust: validate: add `Validate` trait alistair23
2026-11-10 4:26 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 04/25] X.509: Make certificate parser public alistair23
2026-11-10 4:26 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 05/25] X.509: Parse Subject Alternative Name in certificates alistair23
2026-11-10 4:26 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 06/25] X.509: Move certificate length retrieval into new helper alistair23
2026-11-10 4:27 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 07/25] rust: add bindings for hash.h alistair23
2026-11-10 4:30 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 08/25] rust: device: Expose Device as_raw() publicly alistair23
2026-11-10 4:26 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 09/25] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-11-10 4:32 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 10/25] PCI/TSM: Rename pf0 to host alistair23
2026-11-10 4:28 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 11/25] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-11-10 4:45 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 12/25] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-11-10 4:41 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 13/25] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-11-10 4:40 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 14/25] lib: rspdm: Support SPDM get_version alistair23
2026-11-10 4:32 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 15/25] lib: rspdm: Support SPDM get_capabilities alistair23
2026-11-10 4:38 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 16/25] rust: kernel: Add crypto hash bindings alistair23
2026-11-10 4:37 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 17/25] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-11-10 4:42 ` sashiko-bot
2026-11-12 4:50 ` Alistair Francis
2026-11-10 4:18 ` [PATCH v6 18/25] lib: rspdm: Support SPDM get_digests alistair23
2026-11-10 4:42 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 19/25] lib: rspdm: Support SPDM get_certificate alistair23
2026-11-10 4:40 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 20/25] rust: public_key: Add crypto public key bindings alistair23
2026-11-10 4:47 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 21/25] keys: Guard asymmetric-type.h behind CONFIG_KEYS alistair23
2026-11-10 4:41 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 22/25] rust: x509: Add X509 certificate bindings alistair23
2026-11-10 4:54 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 23/25] lib: rspdm: Support SPDM certificate validation alistair23
2026-11-10 4:51 ` sashiko-bot [this message]
2026-11-10 4:18 ` [PATCH v6 24/25] lib: rspdm: Support SPDM challenge alistair23
2026-11-10 4:49 ` sashiko-bot
2026-11-10 4:18 ` [PATCH v6 25/25] lib: rspdm: Expose public Rust API alistair23
2026-11-10 4:53 ` 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-206245@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;
as well as URLs for NNTP newsgroup(s).