Linux PCI subsystem development
 help / color / mirror / Atom feed
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 20/25] rust: public_key: Add crypto public key bindings
Date: Tue, 10 Nov 2026 04:47:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-206239@kernel.org> (raw)
In-Reply-To: <20261110041832.1730924-21-alistair.francis@wdc.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] rust: public_key: missing Invariants and incomplete Safety in
  from_raw()
- [Low] rust: public_key: split kernel import blocks violate vertical
  import style
--

commit 5a9f44bbde86bec3d5be61549a4f56d64bb30ac2
Author: Alistair Francis <alistair.francis@wdc.com>

rust: public_key: Add crypto public key bindings

This commit adds Rust bindings and a PublicKey wrapper for the kernel
crypto public key APIs, providing PublicKey::from_raw(),
PublicKey::verify_signature(), and a Drop implementation.

> diff --git a/rust/kernel/public_key.rs b/rust/kernel/public_key.rs
> new file mode 100644
> index 0000000000000..0c0d4c98bb570
> --- /dev/null
> +++ b/rust/kernel/public_key.rs
> @@ -0,0 +1,83 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +// Copyright (C) 2026 Western Digital
> +
> +//! Wrappers around the Linux kernel crypto public key APIs.
> +//!
> +//! C headers: [`include/crypto/public_key.h`](srctree/include/crypto/public_key.h).
> +//!
> +//! Reference: <https://www.kernel.org/doc/html/latest/crypto/asymmetric-keys.html>
> +
> +use core::ptr::NonNull;
> +use kernel::prelude::*;
> +use kernel::{
> +    bindings,
> +    error::to_result, //
> +};

[Severity: Low]
This isn't a bug, but the two kernel crate imports can be combined into a
single vertical import block per Documentation/rust/coding-guidelines.rst.

> +
> +/// Owned `struct public_key` wrapper.
> +pub struct PublicKey {
> +    key: NonNull<bindings::public_key>,
> +}
> +
> +impl PublicKey {
> +    /// Create a Rust `PublicKey` from a valid C `struct public_key` pointer.
> +    ///
> +    /// # Safety
> +    ///
> +    /// `key` must point to a valid, exclusively-owned `struct public_key`
> +    /// whose ownership is transferred to the returned `PublicKey`. The key
> +    /// is freed with `public_key_free()` when the `PublicKey` is dropped,
> +    /// so the caller must not free it itself or pass the same pointer to
> +    /// `from_raw()` again.
> +    #[inline]
> +    pub unsafe fn from_raw(key: NonNull<bindings::public_key>) -> Self {
> +        Self { key }
> +    }
> +
> +    /// Verify a signature using this public key.
> +    #[inline]
> +    pub fn verify_signature(
> +        &self,
> +        signature: &[u8],
> +        encoding: &'static CStr,
> +        hash_algo: &'static CStr,
> +        message: &[u8],
> +    ) -> Result {
> +        // SAFETY: `self.key` is valid per the struct invariants; its
> +        // `pkey_algo` is populated by the key parser.
> +        let pkey_algo = unsafe { (*self.key.as_ptr()).pkey_algo };

[Severity: Low]
Should PublicKey document an # Invariants section and PublicKey::from_raw()
require those invariants in its # Safety section (with a matching
// INVARIANT: comment in from_raw())?

verify_signature() cites struct invariants for self.key and pkey_algo that
are not documented on PublicKey, and public_key_verify_signature() and
public_key_free() also require pkey_algo to be a valid NUL-terminated string
and key (keylen bytes), params (paramlen bytes), and the struct public_key
itself to be valid kmalloc allocations.

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

  reply	other threads:[~2026-11-10  4:47 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
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 [this message]
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-206239@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