From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: linux-cxl@vger.kernel.org, ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 16/21] lib: rspdm: Support SPDM negotiate_algorithms
Date: Tue, 01 Sep 2026 01:30:57 +0000 [thread overview]
Message-ID: <20260901013057.C9BC31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901010347.2614656-17-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Memory provenance truncation when storing a dynamically sized C struct as a statically sized Rust reference.
- [Low] Algorithm match arms become dead code under valid Kconfig combinations.
--
commit 8baafb6a67bc3beb2ad7bb9b93fd0f34551c04c9
Author: Alistair Francis <alistair@alistair23.me>
lib: rspdm: Support SPDM negotiate_algorithms
This commit adds support for the SPDM NEGOTIATE_ALGORITHMS command.
It extends SpdmState to negotiate and store cryptographic algorithms,
allocating the corresponding synchronous hash handle and context.
> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> index 5ef14c8ed2375..b78086c753702 100644
> --- a/lib/rspdm/state.rs
> +++ b/lib/rspdm/state.rs
[ ... ]
> @@ -373,4 +452,164 @@ pub(crate) fn get_capabilities(&mut self) -> Result<(), Error> {
>
> Ok(())
> }
> +
> + fn update_response_algs(&mut self) -> Result<(), Error> {
> + match self.base_asym_alg {
> + SPDM_ASYM_RSASSA_2048 => {
> + self.sig_len = 256;
> + self.base_asym_enc = CStr::from_bytes_with_nul(b"pkcs1\0")?;
> + }
[Severity: Low]
Does this match arm become dead code when CONFIG_CRYPTO_RSA is disabled?
If CONFIG_CRYPTO_RSA is disabled, the SPDM_ASYM_RSA constant evaluates to 0.
Consequently, negotiate_algs() will reject RSA algorithms because they are not
present in SPDM_ASYM_ALGOS, making this match arm structurally unreachable.
Should these match arms be conditionally compiled so they don't produce dead
code under valid Kconfig combinations?
[ ... ]
> + let desc_vec: KVec<u8> = KVec::from_elem(0u8, desc_len, GFP_KERNEL)?;
> + // Consume the desc_vec to make sure it isn't dropped, untill we
> + // manually drop it later
> + let (desc_buf, _length, _capacity) = desc_vec.into_raw_parts();
> +
> + // SAFETY: We are casting the allocation to be a shash_desc
> + let desc = unsafe {
> + core::mem::transmute::<*mut c_void, &mut bindings::shash_desc>(desc_buf as *mut c_void)
> + };
> + desc.tfm = self.shash;
> +
> + self.desc = Some(desc);
> +
> + /* Used frequently to compute offsets, so cache H */
> + self.hash_len = unsafe { bindings::crypto_shash_digestsize(self.shash) as usize };
> +
> + if let Some(desc) = &mut self.desc {
> + // SAFETY: `self.desc` is a valid and initalised `shash_desc` sized buffer
> + unsafe { to_result(bindings::crypto_shash_init(*desc)) }
[Severity: High]
Does transmuting the dynamically sized buffer to a static Rust reference here
cause memory provenance truncation?
When the dynamically sized buffer (which includes space for both the header
and a flexible array context) is transmuted into a statically sized Rust
reference &mut bindings::shash_desc, the Rust compiler strictly limits the
memory provenance of this reference to the header's size.
When this restricted reference is coerced back to a pointer and passed to C
functions like crypto_shash_init(), C writes into the trailing context array.
This access is out-of-bounds with respect to the Rust reference's provenance,
which triggers Undefined Behavior.
A similar issue occurs during Drop when the restricted reference is transmuted
back to a pointer to free the full capacity. Checking the end of the patch
series confirms this remains unfixed.
Would it be better to retain a raw pointer (*mut bindings::shash_desc)
instead of materializing a provenance-restricted Rust reference?
> + } else {
> + Err(ENOMEM)
> + }
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260901010347.2614656-1-alistair.francis@wdc.com?part=16
next prev parent reply other threads:[~2026-09-01 1:30 UTC|newest]
Thread overview: 44+ 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:11 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 02/21] rust: create basic untrusted data API alistair23
2026-09-01 1:19 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 03/21] rust: validate: add `Validate` trait alistair23
2026-09-01 1:16 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 04/21] X.509: Make certificate parser public alistair23
2026-09-01 1:12 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 05/21] X.509: Parse Subject Alternative Name in certificates alistair23
2026-09-01 1:12 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 06/21] X.509: Move certificate length retrieval into new helper alistair23
2026-09-01 1:10 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 07/21] rust: add bindings for hash.h alistair23
2026-09-01 1:10 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 08/21] rust: error: impl From<FromBytesWithNulError> for Kernel Error alistair23
2026-09-01 1:10 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 09/21] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-09-01 1:17 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 10/21] PCI/TSM: Rename pf0 to host alistair23
2026-09-01 1:16 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 11/21] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-09-01 1:25 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 12/21] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-09-01 1:20 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 13/21] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-09-01 1:15 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 14/21] lib: rspdm: Support SPDM get_version alistair23
2026-09-01 1:17 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 15/21] lib: rspdm: Support SPDM get_capabilities alistair23
2026-09-01 1:15 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 16/21] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-09-01 1:30 ` sashiko-bot [this message]
2026-09-04 5:01 ` Aksh Garg
2026-09-01 1:03 ` [PATCH v3 17/21] lib: rspdm: Support SPDM get_digests alistair23
2026-09-01 1:20 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 18/21] lib: rspdm: Support SPDM get_certificate alistair23
2026-09-01 1:21 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 19/21] lib: rspdm: Support SPDM certificate validation alistair23
2026-09-01 1:22 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 20/21] rust: allow extracting the buffer from a CString alistair23
2026-09-01 1:19 ` sashiko-bot
2026-09-01 1:03 ` [PATCH v3 21/21] lib: rspdm: Support SPDM challenge alistair23
2026-09-01 1:31 ` 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=20260901013057.C9BC31F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alistair23@gmail.com \
--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