Rust for Linux List
 help / color / mirror / Atom feed
From: Aksh Garg <a-garg7@ti.com>
To: <alistair23@gmail.com>, <linux-pci@vger.kernel.org>,
	<Jonathan.Cameron@huawei.com>, <djbw@kernel.org>,
	<rust-for-linux@vger.kernel.org>, <lukas@wunner.de>,
	<alistair@alistair23.me>, <jic23@kernel.org>,
	<linux-cxl@vger.kernel.org>, <bhelgaas@google.com>,
	<akpm@linux-foundation.org>, <linux-kernel@vger.kernel.org>
Cc: <gary@garyguo.net>, <ojeda@kernel.org>, <benno.lossin@proton.me>,
	<a.hindborg@kernel.org>, <wilfred.mallawa@wdc.com>,
	<tmgross@umich.edu>, <boqun.feng@gmail.com>,
	<bjorn3_gh@protonmail.com>, <alex.gaynor@gmail.com>,
	<aliceryhl@google.com>
Subject: Re: [PATCH v3 16/21] lib: rspdm: Support SPDM negotiate_algorithms
Date: Fri, 4 Sep 2026 10:31:55 +0530	[thread overview]
Message-ID: <6930c5ad-c2de-4cf2-b96e-61079f07e455@ti.com> (raw)
In-Reply-To: <20260901010347.2614656-17-alistair.francis@wdc.com>



On 01/09/26 06:33, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair@alistair23.me>
> 
> Support the NEGOTIATE_ALGORITHMS SPDM command.
> 
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>   lib/rspdm/consts.rs    |  56 +++++++++-
>   lib/rspdm/lib.rs       |   9 +-
>   lib/rspdm/state.rs     | 243 ++++++++++++++++++++++++++++++++++++++++-
>   lib/rspdm/validator.rs | 110 ++++++++++++++++++-
>   4 files changed, 412 insertions(+), 6 deletions(-)

[...]

> +
> +    pub(crate) fn negotiate_algs(&mut self) -> Result<(), Error> {
> +        let mut request = NegotiateAlgsReq::default();
> +        request.version = self.version;
> +
> +        if self.version >= SPDM_VER_12 && (self.rsp_caps & SPDM_KEY_EX_CAP) == SPDM_KEY_EX_CAP {
> +            request.other_params_support = SPDM_OPAQUE_DATA_FMT_GENERAL;
> +        }
> +
> +        let req_sz = core::mem::size_of::<NegotiateAlgsReq>();
> +        let rsp_sz = core::mem::size_of::<NegotiateAlgsRsp>();
> +
> +        request.length = (req_sz as u16).to_le();
> +
> +        // SAFETY: `request` is repr(C) and packed, so we can convert it to a slice
> +        let request_buf = unsafe { from_raw_parts_mut(&mut request as *mut _ as *mut u8, req_sz) };
> +
> +        let mut response_vec: KVec<u8> = KVec::from_elem(0u8, rsp_sz, GFP_KERNEL)?;
> +
> +        let rc = self.spdm_exchange(request_buf, response_vec.as_mut_slice())? as usize;
> +
> +        // The transport must report a length within the buffer we provided.
> +        if rc > response_vec.len() {
> +            pr_err!("Overflowed capabilities response\n");
> +            return Err(EIO);
> +        }
> +        response_vec.truncate(rc);
> +
> +        let response: &NegotiateAlgsRsp = Untrusted::new(response_vec.as_slice()).validate()?;
> +
> +        self.base_asym_alg = u32::from_le(response.base_asym_sel);
> +        self.base_hash_alg = u32::from_le(response.base_hash_sel);
> +        self.meas_hash_alg = u32::from_le(response.measurement_hash_algo);
> +
> +        if self.base_asym_alg & SPDM_ASYM_ALGOS == 0 || self.base_hash_alg & SPDM_HASH_ALGOS == 0 {
> +            pr_err!("No common supported algorithms\n");
> +            return Err(EPROTO);
> +        }
> +
> +        // /* Responder shall select exactly 1 alg (SPDM 1.0.0 table 14) */
> +        if self.base_asym_alg.count_ones() != 1
> +            || self.base_hash_alg.count_ones() != 1
> +            || self.meas_hash_alg.count_ones() != 1

Hi Alistair,

As per the SPDM spec v1.4.0 Table 25 (ALGORITHMS response message
format), description of the field 'MeasurementHashAlgo' states "If the
Responder supports measurements (MEAS_CAP=01b or MEAS_CAP=10b in its
CAPABILITIES response) and if MeasurementSpecificationSel is non-zero,
then exactly one bit in this bit field shall be set. Otherwise, the
Responder shall set this field to 0".

Currently, the code unconditionally checks for exactly one bit. If a
responder does not support measurements, it will legitimately set this
field to 0, which causes the current check to incorrectly fail.

A change somewhat similar to the diff shown below might help here:


              return Err(EPROTO);
          }

+        let meas_hash_valid = if self.rsp_caps & SPDM_MEAS_CAP != 0
+            && response.measurement_specification_sel != 0
+        {
+            self.meas_hash_alg.count_ones() == 1
+        } else {
+            self.meas_hash_alg == 0
+        };
+
          // /* Responder shall select exactly 1 alg (SPDM 1.0.0 table 
14) */
          if self.base_asym_alg.count_ones() != 1
              || self.base_hash_alg.count_ones() != 1
-            || self.meas_hash_alg.count_ones() != 1
+            || !meas_hash_valid
              || response.ext_asym_sel_count != 0
              || response.ext_hash_sel_count != 0
              || response.param1 > request.param1

Regards,
Aksh Garg

> +            || response.ext_asym_sel_count != 0
> +            || response.ext_hash_sel_count != 0
> +            || response.param1 > request.param1
> +            || response.other_params_sel != request.other_params_support
> +        {
> +            pr_err!("Malformed algorithms response\n");
> +            return Err(EPROTO);
> +        }
> +
> +        self.update_response_algs()?;
> +
> +        Ok(())
> +    }

  reply	other threads:[~2026-09-04  5:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  1:03 [PATCH v3 00/21] lib: Rust implementation of SPDM alistair23
2026-09-01  1:03 ` [PATCH v3 01/21] rust: transmute: add `cast_slice[_mut]` functions alistair23
2026-09-01  1:03 ` [PATCH v3 02/21] rust: create basic untrusted data API alistair23
2026-09-01  1:03 ` [PATCH v3 03/21] rust: validate: add `Validate` trait alistair23
2026-09-01  1:03 ` [PATCH v3 04/21] X.509: Make certificate parser public alistair23
2026-09-01  1:03 ` [PATCH v3 05/21] X.509: Parse Subject Alternative Name in certificates alistair23
2026-09-01  1:03 ` [PATCH v3 06/21] X.509: Move certificate length retrieval into new helper alistair23
2026-09-01  1:03 ` [PATCH v3 07/21] rust: add bindings for hash.h alistair23
2026-09-01  1:03 ` [PATCH v3 08/21] rust: error: impl From<FromBytesWithNulError> for Kernel Error alistair23
2026-09-01  1:03 ` [PATCH v3 09/21] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-09-01  1:03 ` [PATCH v3 10/21] PCI/TSM: Rename pf0 to host alistair23
2026-09-01  1:03 ` [PATCH v3 11/21] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-09-01  1:03 ` [PATCH v3 12/21] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-09-01  1:03 ` [PATCH v3 13/21] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-09-01  1:03 ` [PATCH v3 14/21] lib: rspdm: Support SPDM get_version alistair23
2026-09-01  1:03 ` [PATCH v3 15/21] lib: rspdm: Support SPDM get_capabilities alistair23
2026-09-01  1:03 ` [PATCH v3 16/21] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-09-04  5:01   ` Aksh Garg [this message]
2026-09-01  1:03 ` [PATCH v3 17/21] lib: rspdm: Support SPDM get_digests alistair23
2026-09-01  1:03 ` [PATCH v3 18/21] lib: rspdm: Support SPDM get_certificate alistair23
2026-09-01  1:03 ` [PATCH v3 19/21] lib: rspdm: Support SPDM certificate validation alistair23
2026-09-01  1:03 ` [PATCH v3 20/21] rust: allow extracting the buffer from a CString alistair23
2026-09-01  1:03 ` [PATCH v3 21/21] lib: rspdm: Support SPDM challenge 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=6930c5ad-c2de-4cf2-b96e-61079f07e455@ti.com \
    --to=a-garg7@ti.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=a.hindborg@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=alistair23@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=benno.lossin@proton.me \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=djbw@kernel.org \
    --cc=gary@garyguo.net \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=wilfred.mallawa@wdc.com \
    /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