From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: gary@garyguo.net, linux-cxl@vger.kernel.org, ojeda@kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 19/22] lib: rspdm: Support SPDM get_certificate
Date: Mon, 28 Sep 2026 01:43:43 +0000 [thread overview]
Message-ID: <20260928014344.261061F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928013123.566184-1-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] rspdm: SPDM cert chain truncation and underflow in SpdmCertChain::validate
- [Medium] rspdm: integer underflow in get_certificate when transport_sz is small
--
commit 4862644196f20f9c3e54555a8df7d0d01825e781
Author: Alistair Francis <alistair@alistair23.me>
lib: rspdm: Support SPDM get_certificate
This commit introduces support for the GET_CERTIFICATE SPDM command. It
sends requests to the responder and iterates over the returned certificates
for later validation.
> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> index 502d99eb13a66..780b9d459abf9 100644
> --- a/lib/rspdm/state.rs
> +++ b/lib/rspdm/state.rs
[ ... ]
> @@ -654,4 +659,107 @@ pub(crate) fn get_digests(&mut self) -> Result<(), Error> {
[ ... ]
> + pub(crate) fn get_certificate(&mut self, slot: u8) -> Result<(), Error> {
> + let mut request = GetCertificateReq::default();
> + request.header.version = self.version;
> + request.header.param1 = slot;
> +
> + let rsp_sz =
> + (GET_CERTIFICATE_RSP_HDR_SZ as u32 + u16::MAX as u32).min(self.transport_sz) as usize;
> +
> + request.offset = 0;
> + request.length = (rsp_sz - GET_CERTIFICATE_RSP_HDR_SZ) as u16;
[Severity: Medium]
What happens if the caller provides a `transport_sz` that is less than 8?
Since `GET_CERTIFICATE_RSP_HDR_SZ` is 8, `rsp_sz` could be less than 8,
causing this subtraction to underflow `usize` and panic.
> +
> + let mut response_vec: KVec<u8> = KVec::from_elem(0u8, rsp_sz, GFP_KERNEL)?;
> +
> + let mut request_buf = request.to_bytes()?;
> + let response = self.get_cert_exchange(request_buf.as_mut_slice(), &mut response_vec)?;
[ ... ]
> + let mut offset: u16 = portion_length;
> + let mut remainder_length = rem_length as usize;
> +
> + while remainder_length > 0 {
> + request.offset = offset;
> + request.length = (remainder_length.min(rsp_sz - GET_CERTIFICATE_RSP_HDR_SZ)) as u16;
[Severity: Medium]
Could this subtraction also underflow under the same conditions where `rsp_sz`
is smaller than `GET_CERTIFICATE_RSP_HDR_SZ`?
> +
> + let mut request_buf = request.to_bytes()?;
[ ... ]
> diff --git a/lib/rspdm/validator.rs b/lib/rspdm/validator.rs
> index c058dde314401..f4e9485179d01 100644
> --- a/lib/rspdm/validator.rs
> +++ b/lib/rspdm/validator.rs
[ ... ]
> @@ -794,3 +795,154 @@ fn validate(unvalidated: &[u8], context: &'c SpdmState<'c>) -> Result<Self, Self
[ ... ]
> +impl<'a, 'c> Validate<'c, Untrusted<&'a [u8]>> for SpdmCertChain {
> + type Err = Error;
> +
> + type Context = &'c SpdmState<'c>;
> +
> + fn validate(unvalidated: &[u8], context: &'c SpdmState<'c>) -> Result<Self, Self::Err> {
[ ... ]
> + let root_hash_end = SPDM_CERT_CHAIN_HDR_SZ + context.hash_len;
> + let mut root_hash = KVec::new();
> + root_hash.extend_from_slice(
> + unvalidated
> + .get(SPDM_CERT_CHAIN_HDR_SZ..root_hash_end)
> + .ok_or(EIO)?,
> + GFP_KERNEL,
> + )?;
> +
> + let cert_chain_end = length as usize - root_hash_end;
[Severity: High]
Does this calculation safely handle payloads where `length` is smaller than
`root_hash_end`?
It appears this subtraction will underflow and trigger a panic if the untrusted
payload provides a short length.
> + let mut certificates = KVec::new();
> + certificates.extend_from_slice(
> + unvalidated.get(root_hash_end..cert_chain_end).ok_or(EIO)?,
[Severity: High]
Is it intentional to use the subtracted value as the exclusive slice bound here?
Because `cert_chain_end` is calculated as a relative length but used as an
absolute upper bound, it seems to unconditionally truncate the valid certificate
stream by `root_hash_end` bytes.
> + GFP_KERNEL,
> + )?;
> +
> + Ok(SpdmCertChain {
> + length,
> + root_hash,
> + certificates,
> + })
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260928011123.450800-1-alistair.francis@wdc.com?part=19
next prev parent reply other threads:[~2026-09-28 1:43 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 1:11 [PATCH v4 00/22] lib: Rust implementation of SPDM alistair23
2026-09-28 1:11 ` [PATCH v4 01/22] virt: coco: change tsm_register() to use a const struct alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 02/22] rust: transmute: add `cast_slice[_mut]` functions alistair23
2026-09-28 1:35 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 03/22] rust: create basic untrusted data API alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 04/22] rust: validate: add `Validate` trait alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 05/22] X.509: Make certificate parser public alistair23
2026-09-28 1:39 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 06/22] X.509: Parse Subject Alternative Name in certificates alistair23
2026-09-28 1:39 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 07/22] X.509: Move certificate length retrieval into new helper alistair23
2026-09-28 1:36 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 08/22] rust: add bindings for hash.h alistair23
2026-09-28 1:43 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 09/22] rust: error: impl From<FromBytesWithNulError> for Kernel Error alistair23
2026-09-28 1:36 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 10/22] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-09-28 1:45 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 11/22] PCI/TSM: Rename pf0 to host alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 12/22] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-09-28 1:43 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 13/22] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-09-28 1:43 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 14/22] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-09-28 1:44 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 15/22] lib: rspdm: Support SPDM get_version alistair23
2026-09-28 1:39 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 16/22] lib: rspdm: Support SPDM get_capabilities alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 17/22] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-09-28 1:45 ` sashiko-bot
2026-09-28 1:11 ` [PATCH v4 18/22] lib: rspdm: Support SPDM get_digests alistair23
2026-09-28 1:45 ` sashiko-bot
2026-09-28 1:31 ` [PATCH v4 19/22] lib: rspdm: Support SPDM get_certificate alistair23
2026-09-28 1:31 ` [PATCH v4 20/22] lib: rspdm: Support SPDM certificate validation alistair23
2026-09-28 1:47 ` sashiko-bot
2026-09-28 1:31 ` [PATCH v4 21/22] rust: allow extracting the buffer from a CString alistair23
2026-09-28 1:41 ` sashiko-bot
2026-09-28 1:31 ` [PATCH v4 22/22] lib: rspdm: Support SPDM challenge alistair23
2026-09-28 1:46 ` sashiko-bot
2026-09-28 1:43 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-09-28 1:20 [PATCH v4 19/22] lib: rspdm: Support SPDM get_certificate alistair23
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=20260928014344.261061F000FF@smtp.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