Linux Modules
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: ojeda@kernel.org, linux-modules@vger.kernel.org
Subject: Re: [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()`
Date: Wed, 22 Jul 2026 09:23:00 +0000	[thread overview]
Message-ID: <20260722092301.1B01D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722-setonce-populate-v1-1-fa7455c26c42@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] `ModuleParamAccess` lacks `#[repr(C)]`, leading to potential Undefined Behavior and memory corruption when its pointer is cast to `SetOnce<T>`.
--

--- Patch [1]: [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()` ---
commit e0d10f7a2c42bcda24ee9851cc2fda3d4c4bc480
Author: Alice Ryhl <aliceryhl@google.com>

rust: sync: return Result<&T, T> from SetOnce::populate()

This commit changes the return value of SetOnce::populate() from a boolean
to a Result to allow infallible access to the inserted value on success.
It also ensures the inserted value is not dropped under a lock if populate()
fails, and updates ModuleParam and Binder to handle the new return type.

> diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs
> index 6541af218390c..8f0bd085badfe 100644
> --- a/rust/kernel/module_param.rs
> +++ b/rust/kernel/module_param.rs
> @@ -77,10 +77,10 @@ pub trait ModuleParam: Sized + Copy {
>          // SAFETY: By function safety requirements, this access is safe.
>          let container = unsafe { &*((*param).__bindgen_anon_1.arg.cast::<SetOnce<T>>()) };

[Severity: High]
This is a pre-existing issue, but since we are modifying this code block, is
it safe to cast this void pointer directly to SetOnce<T>?

Looking at the definition of ModuleParamAccess<T>, it lacks a #[repr(C)]
annotation:

rust/kernel/module_param.rs:ModuleParamAccess {
    value: SetOnce<T>,
    default: T,
}

Since it uses the default Rust layout, the compiler is free to reorder these
fields. When as_void_ptr() passes a pointer to the entire struct into the
C kernel parameters API:

rust/kernel/module_param.rs:ModuleParamAccess::as_void_ptr() {
    core::ptr::from_ref(self).cast_mut().cast()
}

And set_param casts it back directly to SetOnce<T> (assuming it sits at
offset 0), could this lead to memory corruption if the compiler decides to
place default before value?

> -        container
> -            .populate(new_value)
> -            .then_some(0)
> -            .ok_or(kernel::error::code::EEXIST)
> +        match container.populate(new_value) {
> +            Ok(_) => Ok(0),
> +            Err(_) => Err(EEXIST),
> +        }
>      })
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722-setonce-populate-v1-0-fa7455c26c42@google.com?part=1

       reply	other threads:[~2026-07-22  9:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260722-setonce-populate-v1-0-fa7455c26c42@google.com>
     [not found] ` <20260722-setonce-populate-v1-1-fa7455c26c42@google.com>
2026-07-22  9:23   ` sashiko-bot [this message]
     [not found] ` <20260722-setonce-populate-v1-2-fa7455c26c42@google.com>
2026-07-22  9:27   ` [PATCH 2/3] rust: sync: add SetOnce::try_get_or_populate() 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=20260722092301.1B01D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=linux-modules@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