Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: linux-pci@vger.kernel.org, gary@garyguo.net,
	linux-cxl@vger.kernel.org, ojeda@kernel.org
Subject: Re: [PATCH v4 03/22] rust: create basic untrusted data API
Date: Mon, 28 Sep 2026 01:41:34 +0000	[thread overview]
Message-ID: <20260928014134.BFD7C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928011123.450800-4-alistair.francis@wdc.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] rust: validate: Untrusted Deref implementations violate cast_slice safety contract
- [Low] rust: validate: typo in module documentation
- [Low] rust: validate: imports do not follow vertical style
--

commit faffe058082273ce8374694a0c1cc53da4578ae7
Author: Benno Lossin <lossin@kernel.org>

rust: create basic untrusted data API

This commit introduces the Untrusted<T> wrapper type to explicitly mark data
originating from untrusted sources, such as userspace. It allows validating
the data before making logical decisions based on its value.

Link: Message-ID: <20250814124424.516191-3-lossin@kernel.org>

> diff --git a/rust/kernel/validate.rs b/rust/kernel/validate.rs
> new file mode 100644
> index 0000000000000..ca2e5abda3e25
> --- /dev/null
> +++ b/rust/kernel/validate.rs
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Untrusted data API.

[ ... ]

> +use core::ops::{Deref, DerefMut};

[Severity: Low]
Does this import follow the vertical import style? The subsystem guidelines
request following the vertical style for imports.

> +
> +use crate::{

[ ... ]

> +/// The reason for this is that `&mut Untrusted<[u8]>` can beconverted into `&mut [Untrusted<u8>]`

[Severity: Low]
There appears to be a typo here ("beconverted" instead of "be converted").

> +/// very easily, but the converse is not possible.

[ ... ]

> +impl<T> Deref for Untrusted<[T]> {
> +    type Target = [Untrusted<T>];
> +
> +    #[inline]
> +    fn deref(&self) -> &Self::Target {
> +        // SAFETY: `Untrusted<T>` transparently wraps `T`.
> +        unsafe { cast_slice(&self.0) }

[Severity: High]
Does this violate the safety contract of cast_slice? The documented safety
precondition of kernel::transmute::cast_slice requires that neither T nor U
have interior mutability. However, Untrusted::new and this Deref implementation
don't place any trait bounds on T preventing interior mutability, which could
allow safely constructing and dereferencing something like
Untrusted<Vec<Cell<u8>>>.

> +    }
> +}
> +
> +impl<T> DerefMut for Untrusted<[T]> {
> +    #[inline]
> +    fn deref_mut(&mut self) -> &mut Self::Target {
> +        // SAFETY: `Untrusted<T>` transparently wraps `T`.
> +        unsafe { cast_slice_mut(&mut self.0) }

[Severity: High]
Similarly, does this violate the safety contract of cast_slice_mut by lacking
a check against interior mutability?

> +    }
> +}
> +
> +impl<T, A: Allocator> Deref for Untrusted<Vec<T, A>> {
> +    type Target = [Untrusted<T>];
> +
> +    #[inline]
> +    fn deref(&self) -> &Self::Target {
> +        // SAFETY: `Untrusted<T>` transparently wraps `T`.
> +        unsafe { cast_slice(self.0.as_slice()) }

[Severity: High]
Does this violate the interior mutability ban for cast_slice?

> +    }
> +}
> +
> +impl<T, A: Allocator> DerefMut for Untrusted<Vec<T, A>> {
> +    #[inline]
> +    fn deref_mut(&mut self) -> &mut Self::Target {
> +        // SAFETY: `Untrusted<T>` transparently wraps `T`.
> +        unsafe { cast_slice_mut(self.0.as_mut_slice()) }

[Severity: High]
Does this violate the interior mutability ban for cast_slice_mut?

> +    }
> +}

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

  reply	other threads:[~2026-09-28  1:41 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 [this message]
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
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=20260928014134.BFD7C1F000FF@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