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 19/25] lib: rspdm: Support SPDM get_certificate
Date: Tue, 10 Nov 2026 04:40:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-206225@kernel.org> (raw)
In-Reply-To: <20261110041832.1730924-20-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] lib: rspdm: u16 length truncation in get_certificate() on 64K+
page kernels
- [Low] lib: rspdm: duplicated initial exchange and missing check in
get_certificate()
--
commit af8f6804281e40cfc39810cbc243efa8a576944b
Author: Alistair Francis <alistair.francis@wdc.com>
lib: rspdm: Support SPDM get_certificate
This commit adds support for the SPDM GET_CERTIFICATE command to retrieve
and store certificate chains for each provisioned slot from the responder.
> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> index a44f98a941cd0..f1a55da1f1cfa 100644
> --- a/lib/rspdm/state.rs
> +++ b/lib/rspdm/state.rs
[ ... ]
> @@ -500,4 +505,97 @@ pub(crate) fn get_digests(&mut self) -> Result<(), Error> {
>
> Ok(())
> }
> +
> + 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;
> +
> + // Bound the per-chunk allocation to one page
> + let rsp_sz = (GET_CERTIFICATE_RSP_HDR_SZ + PAGE_SIZE).min(self.data_transfer_sz as usize);
> +
> + request.offset = 0;
> + request.length = (rsp_sz - GET_CERTIFICATE_RSP_HDR_SZ) as u16;
[Severity: High]
Does casting rsp_sz - GET_CERTIFICATE_RSP_HDR_SZ to u16 truncate
request.length to 0 on 64K and 256K page kernels?
When self.data_transfer_sz is at least GET_CERTIFICATE_RSP_HDR_SZ +
PAGE_SIZE (such as with PCI_DOE_MAX_PAYLOAD), rsp_sz -
GET_CERTIFICATE_RSP_HDR_SZ equals PAGE_SIZE (0x10000 on 64K-page kernels),
which wraps to 0 when cast to u16 and causes certificate retrieval and
device authentication to fail. Adding GET_CERTIFICATE_RSP_HDR_SZ to
PAGE_SIZE also makes rsp_sz equal PAGE_SIZE + 8, so KVec::from_elem()
allocates two pages instead of one.
Bounding rsp_sz to PAGE_SIZE.min(self.data_transfer_sz as usize) and
clamping the requested length to u16::MAX avoids the truncation and keeps
the buffer within a single page.
> +
> + let response_vec: KVec<u8> = KVec::from_elem(0u8, rsp_sz, GFP_KERNEL)?;
> +
> + let mut request_buf = request.to_bytes()?;
> + let response: GetCertificateRsp = self
> + .spdm_exchange(request_buf.as_mut_slice(), response_vec)?
> + .validate(&*self)?;
> +
> + if (response.header.param1 & 0xF) != slot {
> + dev_err!(&self.dev, "Invalid slot response\n");
> + return Err(EPROTO);
> + }
> +
> + let portion_length = response.portion_length;
> + let rem_length = response.remainder_length;
> +
> + let total_cert_len = portion_length as usize + rem_length as usize;
> +
> + let mut certs_buf: KVec<u8> = KVec::new();
> +
> + certs_buf.extend_from_slice(&response.cert_chain, GFP_KERNEL)?;
> +
> + 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;
> +
> + let mut request_buf = request.to_bytes()?;
> +
> + let response_vec: KVec<u8> = KVec::from_elem(
> + 0u8,
> + request.length as usize + GET_CERTIFICATE_RSP_HDR_SZ,
> + GFP_KERNEL,
> + )?;
> +
> + let response: GetCertificateRsp = self
> + .spdm_exchange(request_buf.as_mut_slice(), response_vec)?
> + .validate(&*self)?;
> +
> + let portion_length = response.portion_length;
> + let rem_length = response.remainder_length;
> +
> + if portion_length == 0
> + || (response.header.param1 & 0xF) != slot
> + || offset as usize + portion_length as usize + rem_length as usize != total_cert_len
> + {
> + dev_err!(&self.dev, "Malformed certificate response\n");
> + return Err(EPROTO);
> + }
[Severity: Low]
Can the initial exchange before the while loop be folded into the loop so
that the first response also checks portion_length == 0 and avoids
duplicating the request/response sequence? Right now, if a responder
returns portion_length == 0 with a non-zero remainder_length on the first
chunk, or a total_cert_len exceeding u16::MAX, get_certificate() performs
an extra exchange before failing.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110041832.1730924-1-alistair.francis@wdc.com?part=19
next prev parent reply other threads:[~2026-11-10 4:40 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 [this message]
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
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-206225@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