Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: linux-cxl@vger.kernel.org, gary@garyguo.net, ojeda@kernel.org,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 16/22] lib: rspdm: Support SPDM get_capabilities
Date: Mon, 28 Sep 2026 01:41:11 +0000	[thread overview]
Message-ID: <20260928014112.507121F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928011123.450800-17-alistair.francis@wdc.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] rspdm: spec violation and connection failure parsing SPDM 1.3 capabilities on SPDM 1.2
- [Low] rspdm: unreachable data_transfer_size boundary error path
--

commit a4f1214f54c265aa579b2a02f78463b717992311
Author: Alistair Francis <alistair@alistair23.me>

lib: rspdm: Support SPDM get_capabilities

This commit adds support for the GET_CAPABILITIES SPDM command.

> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> index 3bbe55d965f7a..fb43260f48004 100644
> --- a/lib/rspdm/state.rs
> +++ b/lib/rspdm/state.rs
[ ... ]
> @@ -290,4 +301,59 @@ pub(crate) fn get_version(&mut self) -> Result<(), Error> {
[ ... ]
> +    pub(crate) fn get_capabilities(&mut self) -> Result<(), Error> {
[ ... ]
> +        let response: GetCapabilitiesRsp =
> +            Untrusted::new(response_vec.as_slice()).validate(&*self)?;
> +
> +        self.rsp_caps = response.flags;
> +        if (self.rsp_caps & SPDM_RSP_MIN_CAPS) != SPDM_RSP_MIN_CAPS {
> +            pr_err!(
> +                "{:#x} capabilities are supported, which don't meet required {:#x}\n",
> +                self.rsp_caps,
> +                SPDM_RSP_MIN_CAPS
> +            );
> +            self.rsp_caps = 0;
> +            return Err(EPROTONOSUPPORT);
> +        }
> +
> +        if self.version >= SPDM_VER_12 {
> +            if response.data_transfer_size < 42 {
> +                pr_err!(
> +                    "Invalid minimum transport size {}, must be at least 42\n",
> +                    response.data_transfer_size
> +                );
> +                return Err(EPROTONOSUPPORT);
> +            }

[Severity: Low]
Is this error path reachable?

It looks like the earlier validation in GetCapabilitiesRsp::validate already
enforces data_transfer_size >= SPDM_MIN_DATA_TRANSFER_SIZE (which is 42)
and returns EPROTO. 

This seems to make the EPROTONOSUPPORT path in SpdmState::get_capabilities
dead code.

> +
> +            self.transport_sz = self.transport_sz.min(response.data_transfer_size);
> +        }
> +
> +        Ok(())
> +    }
>  }
> diff --git a/lib/rspdm/validator.rs b/lib/rspdm/validator.rs
> index d0b6691365c0a..ca837bd9cfcc7 100644
> --- a/lib/rspdm/validator.rs
> +++ b/lib/rspdm/validator.rs
[ ... ]
> @@ -175,3 +183,302 @@ fn validate(unvalidated: &[u8], context: &'c SpdmState) -> Result<Self, Self::Er
[ ... ]
> +impl<'a, 'c> Validate<'c, Untrusted<&'a [u8]>> for GetCapabilitiesRsp {
> +    type Err = Error;
> +
> +    type Context = &'c SpdmState;
> +
> +    fn validate(unvalidated: &[u8], context: &'c SpdmState) -> Result<Self, Self::Err> {
[ ... ]
> +        let (data_transfer_size, max_spdm_msg_size, supported_algorithms, length) =
> +            if context.version <= SPDM_VER_11 {
[ ... ]
> +            } else {
[ ... ]
> +                let supported_algorithms = if header.param1 & SPDM_CAP_SUPPORTED_ALGORITHMS != 0 {
> +                    Some(SupportedAlgorithms::from_bytes(
> +                        unvalidated.get(GET_CAPABILITIES_RSP_SZ..).ok_or(EIO)?,
> +                    )?)
> +                } else {
> +                    None
> +                };

[Severity: Medium]
Can this logic incorrectly parse an SPDM 1.2 payload?

If an SPDM 1.2 responder has bit 0 of Param1 set (either by mistake or due to
uninitialized reserved fields), wouldn't this lack of a
context.version >= SPDM_VER_13 guard cause the kernel to incorrectly interpret
this SPDM 1.3 field?

It seems this would attempt to parse SupportedAlgorithms from the end of the
20-byte packet, read an empty slice, and abort the handshake with EIO.

> +
> +                let length = GET_CAPABILITIES_RSP_SZ
> +                    + supported_algorithms
> +                        .as_ref()
> +                        .map_or(0, |s| s.length as usize);
> +
> +                (
> +                    data_transfer_size,
> +                    max_spdm_msg_size,
> +                    supported_algorithms,
> +                    length,
> +                )
> +            };

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

  reply	other threads:[~2026-09-28  1:41 UTC|newest]

Thread overview: 45+ 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 [this message]
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   ` [PATCH v4 19/22] lib: rspdm: Support SPDM get_certificate 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=20260928014112.507121F000FF@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