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 v5 16/23] rust: kernel: Add crypto hash bindings
Date: Tue, 27 Oct 2026 05:41:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-186135@kernel.org> (raw)
In-Reply-To: <20261027052536.1722081-17-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] rust: kernel: hash module gated on CONFIG_CRYPTO breaks m/n builds
- [Low] rust: kernel: unchecked usize to u32 cast in Shash::digest()
- [Low] rust: kernel: wrong doc comment and missing #[inline] in Shash
--
commit 43861816c7010fda266b93e8a13fd64b1fdc4ecd
Author: Alistair Francis <alistair.francis@wdc.com>
rust: kernel: Add crypto hash bindings
This commit adds initial Rust abstractions in the kernel crate for synchronous
crypto hash transformations (Shash) wrapping the C crypto_shash APIs.
> diff --git a/rust/kernel/hash.rs b/rust/kernel/hash.rs
> new file mode 100644
> index 0000000000000..1800065d98767
> --- /dev/null
> +++ b/rust/kernel/hash.rs
[ ... ]
> + /// Return the name of the hash
> + pub fn name(&self) -> &'static CStr {
> + self.name
> + }
> +
> + /// Return the name of the hash output
> + pub fn hash_len(&self) -> usize {
> + self.hash_len
> + }
[Severity: Low]
This isn't a bug, but the doc comment on Shash::hash_len() says "Return the
name of the hash output" instead of the length of the hash output. Also,
should Shash::name(), Shash::hash_len(), and Shash::digest() in
rust/kernel/hash.rs be annotated with #[inline] as small kernel crate
abstraction functions?
> + /// Computes a one-shot digest into `out`, which must be exactly the digest
> + /// size of the selected hash algorithm.
> + pub fn digest(&self, data: &[u8], out: &mut [u8]) -> Result {
> + if out.len() != self.hash_len {
> + return Err(EINVAL);
> + }
> +
> + // SAFETY: `self.desc` was created by `Shash::new()` and points to a
> + // valid `shash_desc` with a valid `tfm`. `out` is checked above to be
> + // exactly `crypto_shash_digestsize()` bytes.
> + unsafe {
> + to_result(bindings::crypto_shash_digest(
> + self.desc.as_ptr(),
> + data.as_ptr(),
> + data.len() as u32,
> + out.as_mut_ptr(),
> + ))
> + }
> + }
[Severity: Low]
In Shash::digest(), could passing a slice with data.len() > u32::MAX on a
64-bit platform silently truncate the input length via data.len() as u32 and
compute a digest over only a prefix of data? Would u32::try_from(data.len())?
avoid the unchecked narrowing cast?
[ ... ]
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index a3c54971e9dea..f7db5975e7621 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -82,6 +82,8 @@
> pub mod fwctl;
> #[cfg(CONFIG_GPU_BUDDY = "y")]
> pub mod gpu;
> +#[cfg(CONFIG_CRYPTO)]
> +pub mod hash;
[Severity: Medium]
Will gating the built-in hash module in rust/kernel/lib.rs on
#[cfg(CONFIG_CRYPTO)] break the build when CONFIG_CRYPTO=m, or when
CONFIG_CRYPTO=y and CONFIG_CRYPTO_HASH2 is m or n?
Because CONFIG_CRYPTO is a tristate symbol, Kconfig emits --cfg=CONFIG_CRYPTO
for both CONFIG_CRYPTO=y and CONFIG_CRYPTO=m, whereas in C, CONFIG_CRYPTO is
only defined for built-in builds:
rust/helpers/hash.c:
#ifdef CONFIG_CRYPTO
__rust_helper unsigned int rust_helper_crypto_shash_descsize(struct crypto_shash *tfm)
When CONFIG_CRYPTO=m, Shash::new() and Shash::drop() in rust/kernel/hash.rs
are compiled into built-in rust/kernel.o, but bindgen does not generate
bindings::crypto_shash_descsize, bindings::crypto_shash_digestsize, or
bindings::crypto_free_shash from rust/helpers/hash.c.
In addition, Shash::new() and Shash::digest() call crypto_alloc_shash(),
crypto_shash_init(), and crypto_shash_digest(), which are compiled under
CONFIG_CRYPTO_HASH2 rather than CONFIG_CRYPTO:
crypto/Makefile:
crypto_hash-y += ahash.o
crypto_hash-y += shash.o
obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
If CONFIG_CRYPTO=y and CONFIG_CRYPTO_HASH2 is n or m, vmlinux fails to link
with undefined references to those shash symbols from rust/kernel.o.
Should rust/kernel/lib.rs use #[cfg(CONFIG_CRYPTO_HASH2 = "y")] (and
rust/helpers/hash.c guard on CONFIG_CRYPTO_HASH2) to match the other built-in
subsystem modules in rust/kernel/lib.rs?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261027052536.1722081-1-alistair.francis@wdc.com?part=16
next prev parent reply other threads:[~2026-10-27 5:41 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 5:25 [PATCH v5 00/23] lib: Rust implementation of SPDM alistair23
2026-10-27 5:25 ` [PATCH v5 01/23] virt: coco: change tsm_register() to use a const struct alistair23
2026-10-27 5:25 ` [PATCH v5 02/23] rust: create basic untrusted data API alistair23
2026-10-27 5:34 ` sashiko-bot
2026-10-27 13:17 ` Benno Lossin
2026-10-27 5:25 ` [PATCH v5 03/23] rust: validate: add `Validate` trait alistair23
2026-10-27 5:25 ` [PATCH v5 04/23] X.509: Make certificate parser public alistair23
2026-10-27 5:25 ` [PATCH v5 05/23] X.509: Parse Subject Alternative Name in certificates alistair23
2026-10-27 5:25 ` [PATCH v5 06/23] X.509: Move certificate length retrieval into new helper alistair23
2026-10-27 5:25 ` [PATCH v5 07/23] rust: add bindings for hash.h alistair23
2026-10-27 5:25 ` [PATCH v5 08/23] rust: device: Expose Device from_raw() publically alistair23
2026-10-27 5:34 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 09/23] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-10-27 5:42 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 10/23] PCI/TSM: Rename pf0 to host alistair23
2026-10-27 5:25 ` [PATCH v5 11/23] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-10-27 5:50 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 12/23] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-10-27 5:46 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 13/23] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-10-27 5:25 ` [PATCH v5 14/23] lib: rspdm: Support SPDM get_version alistair23
2026-10-27 5:41 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 15/23] lib: rspdm: Support SPDM get_capabilities alistair23
2026-10-27 5:36 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 16/23] rust: kernel: Add crypto hash bindings alistair23
2026-10-27 5:41 ` sashiko-bot [this message]
2026-10-27 5:25 ` [PATCH v5 17/23] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-10-27 5:43 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 18/23] lib: rspdm: Support SPDM get_digests alistair23
2026-10-27 5:25 ` [PATCH v5 19/23] lib: rspdm: Support SPDM get_certificate alistair23
2026-10-27 5:25 ` [PATCH v5 20/23] rust: public_key: Add crypto public key bindings alistair23
2026-10-27 5:41 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 21/23] rust: x509: Add X509 certificate bindings alistair23
2026-10-27 5:45 ` sashiko-bot
2026-10-27 5:25 ` [PATCH v5 22/23] lib: rspdm: Support SPDM certificate validation alistair23
2026-10-27 5:25 ` [PATCH v5 23/23] lib: rspdm: Support SPDM challenge alistair23
2026-10-27 5:43 ` 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-186135@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