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 03/21] rust: validate: add `Validate` trait
Date: Tue, 01 Sep 2026 01:16:59 +0000 [thread overview]
Message-ID: <20260901011659.912701F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260901010347.2614656-4-alistair.francis@wdc.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] The small wrapper functions `validate`, `validate_ref`, and `validate_mut` in the `Untrusted` type are missing the `#[inline]` attribute, violating subsystem guidelines.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but transmuting references between `Vec<T, A>` and `Vec<Untrusted<T>, A>` via pointer cast is Undefined Behavior because `Vec` lacks a guaranteed memory layout.
--
commit 6a4bc1cc90cb4c5dd96a67a8f893828d2d0c3473
Author: Benno Lossin <lossin@kernel.org>
rust: validate: add `Validate` trait
Introduce the `Validate<Input>` trait and functions to validate
`Untrusted<T>` using said trait.
> diff --git a/rust/kernel/validate.rs b/rust/kernel/validate.rs
> index 2b28625c25efe..663681b633c86 100644
> --- a/rust/kernel/validate.rs
> +++ b/rust/kernel/validate.rs
> @@ -107,6 +110,30 @@ pub fn new(value: T) -> Self
> {
> Self(value)
> }
> +
> + /// Validate the underlying untrusted data.
> + ///
> + /// See the [`Validate`] trait for more information.
> + pub fn validate<V: Validate<Self>>(self) -> Result<V, V::Err>
> + where
> + T: Sized,
> + {
> + V::validate(self.0)
> + }
> +
> + /// Validate the underlying untrusted data.
> + ///
> + /// See the [`Validate`] trait for more information.
> + pub fn validate_ref<'a, V: Validate<&'a Self>>(&'a self) -> Result<V, V::Err> {
> + V::validate(&self.0)
> + }
> +
> + /// Validate the underlying untrusted data.
> + ///
> + /// See the [`Validate`] trait for more information.
> + pub fn validate_mut<'a, V: Validate<&'a mut Self>>(&'a mut self) -> Result<V, V::Err> {
> + V::validate(&mut self.0)
> + }
[Severity: Low]
Should these small wrapper functions be annotated with #[inline]?
[ ... ]
> impl<T, A: Allocator> Deref for Untrusted<Vec<T, A>> {
> type Target = Vec<Untrusted<T>, A>;
>
> fn deref(&self) -> &Self::Target {
> let ptr: *const Untrusted<Vec<T, A>> = self;
> // CAST: `Untrusted<T>` transparently wraps `T`.
> let ptr: *const Vec<Untrusted<T>, A> = ptr.cast();
> // SAFETY: `ptr` is derived from the reference `self`.
> unsafe { &*ptr }
> }
> }
>
> impl<T, A: Allocator> DerefMut for Untrusted<Vec<T, A>> {
> fn deref_mut(&mut self) -> &mut Self::Target {
> let ptr: *mut Untrusted<Vec<T, A>> = self;
> // CAST: `Untrusted<T>` transparently wraps `T`.
> let ptr: *mut Vec<Untrusted<T>, A> = ptr.cast();
> // SAFETY: `ptr` is derived from the reference `self`.
> unsafe { &mut *ptr }
> }
> }
[Severity: High]
This isn't a bug introduced by this patch, but does casting pointers between
Vec<T, A> and Vec<Untrusted<T>, A> cause Undefined Behavior?
Since Vec<T, A> uses the default #[repr(rust)] representation, it does not
guarantee stable field ordering. The Rust Reference explicitly states that
pointer-casting between two generic types with the default representation is
Undefined Behavior, even if their type arguments share identical memory
layouts.
If the compiler orders fields differently between Vec<T, A> and
Vec<Untrusted<T>, A>, could dereferencing the casted pointer or swapping
values corrupt memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260901010347.2614656-1-alistair.francis@wdc.com?part=3
next prev parent reply other threads:[~2026-09-01 1:17 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 [this message]
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
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=20260901011659.912701F00A3E@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