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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] rust: ForeignOwnable type mismatch in spdm_destroy()
- [Low] rspdm: needless mutable request_buf in spdm_exchange()
--

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

lib: rspdm: Initial commit of Rust SPDM

This commit adds the initial Rust implementation of the Security Protocol and
Data Model (SPDM) library. It introduces session allocation, authentication
stubs, and session destruction functions exposed via a C API.

> diff --git a/lib/rspdm/lib.rs b/lib/rspdm/lib.rs
> new file mode 100644
> --- /dev/null
> +++ b/lib/rspdm/lib.rs
[ ... ]
> +pub extern "C" fn spdm_create(
> +    dev: *mut bindings::device,
> +    transport: bindings::spdm_transport,
> +    transport_priv: *mut c_void,
> +    transport_sz: u32,
> +    validate: bindings::spdm_validate,
> +) -> *mut spdm_state {
> +    // Wrap the `SpdmState` in a `Mutex` so that concurrent FFI callers (for
> +    // example, two threads racing on `spdm_authenticate()` for the same
> +    // device) serialize on the lock and never form aliased `&mut SpdmState`
> +    // references.
> +    let state = SpdmState::new(dev, transport, transport_priv, transport_sz, validate);
> +    match KBox::pin_init(new_mutex!(state), flags::GFP_KERNEL) {
> +        Ok(b) => b.into_foreign() as *mut spdm_state,
> +        Err(_) => ptr::null_mut(),
> +    }
> +}
[ ... ]
> +pub extern "C" fn spdm_destroy(state_ptr: *mut spdm_state) {
> +    if state_ptr.is_null() {
> +        return;
> +    }
> +
> +    // SAFETY: `state_ptr` was returned from `spdm_create()` which used `into_foreign()`
> +    // to create the pointer.
> +    let mutex: KBox<Mutex<SpdmState>> = unsafe { KBox::from_foreign(state_ptr as *mut c_void) };

[Severity: High]
Does this break the ForeignOwnable safety contract? 

The spdm_create() function converts a Pin<KBox<Mutex<SpdmState>>> into a raw
pointer via into_foreign(), but here in spdm_destroy(), the pointer is
reconstructed as an unpinned KBox<Mutex<SpdmState>>. 

Reconstructing a different type from a raw pointer breaks the strict type
symmetry required by the ForeignOwnable trait and violates Pin invariants.
Should this be reconstructed as a pinned box to match its original allocation?

> +
> +    drop(mutex);
> +}

[ ... ]
> diff --git a/lib/rspdm/state.rs b/lib/rspdm/state.rs
> new file mode 100644
> --- /dev/null
> +++ b/lib/rspdm/state.rs
[ ... ]
> +    pub(crate) fn spdm_exchange(
> +        &self,
> +        request_buf: &mut [u8],

[Severity: Low]
Is it necessary to require a mutable slice for the request buffer here?

The function only appears to use its read-only pointer to pass to the
transport layer:

lib/rspdm/state.rs:spdm_exchange() {
    ...
    let length = unsafe {
        transport_function(
            ...
            request_buf.as_ptr() as *const c_void,
            ...
    ...
}

This enforces mutable access to a buffer that is never modified, creating
unnecessary constraints on callers by forcing them to hold or provide
mutable references to read-only buffers. Could this be changed to &[u8]?

> +        response_buf: &mut [u8],
> +    ) -> Result<i32, Error> {

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

  reply	other threads:[~2026-09-28  1:45 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 [this message]
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   ` [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=20260928014542.3BEA41F000FF@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