Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-pci@vger.kernel.org, ojeda@kernel.org, lee@kernel.org,
	linux-leds@vger.kernel.org
Subject: Re: [PATCH RESEND v23 2/3] rust: leds: add Mode trait
Date: Wed, 19 Aug 2026 19:11:19 +0000	[thread overview]
Message-ID: <20260819191119.F19A51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819-rust_leds-v23-2-2716a4ef89a4@posteo.de>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Unsound conversion of potentially aliased C pointers to `&mut usize` in `blink_set_callback`.
- [High] Relying on PinnedDrop and unmanaged led_classdev_unregister introduces a Use-After-Free (UAF) vulnerability on driver unbind if the Device instance outlives the parent device.
- [Low] The commit message description starts with a lowercase letter, violating LED subsystem conventions.
--

--- Patch [2]: [PATCH RESEND v23 2/3] rust: leds: add Mode trait ---
commit 8b1c998241db82c99cdf6f28eac6bffb4a27cef4
Author: Markus Probst <markus.probst@posteo.de>

rust: leds: add Mode trait

Add the led::Mode trait to allow for other types of led class devices
in led::LedOps.

> rust: leds: add Mode trait

[Severity: Low]
Is this commit subject formatted correctly? The LED subsystem guidelines
require capitalizing the description after the subsystem prefix.

> diff --git a/rust/kernel/led/normal.rs b/rust/kernel/led/normal.rs
> index 816db7c576894..25190486a62d0 100644
> --- a/rust/kernel/led/normal.rs
> +++ b/rust/kernel/led/normal.rs
[ ... ]
> @@ -20,7 +28,7 @@ pub struct Device<'bound, T: LedOps + 'bound> {
>  
>  impl<'init, S: DeviceBuilderState> DeviceBuilder<'init, S> {
>      /// Registers a new [`Device`].
> -    pub fn build<'bound: 'init, T: LedOps + 'bound>(
> +    pub fn build<'bound: 'init, T: LedOps<Mode = Normal> + 'bound>(
>          self,
>          parent: &'bound T::Bus,
>          ops: impl PinInit<T, Error> + 'init,

[Severity: High]
Can relying on PinnedDrop to unregister the LED device result in a
use-after-free regression?

In this build function, the code calls bindings::led_classdev_register_ext()
and later relies on bindings::led_classdev_unregister() in PinnedDrop:

rust/kernel/led/normal.rs:DeviceBuilder::build() {
                to_result(unsafe {
                    bindings::led_classdev_register_ext( ... )
                })?;
...

rust/kernel/led/normal.rs:PinnedDrop for Device {
    fn drop(self: Pin<&mut Self>) {
...
        unsafe { bindings::led_classdev_unregister(raw) };
    }

If the Device instance outlives the parent device (for example, if it is
wrapped in an Arc and kept alive by another thread), the Drop
implementation will not execute at driver unbind time.

Because led_classdev_unregister is not called during unbind, the LED sysfs
attributes would remain active. Subsequent sysfs accesses could then invoke
callbacks that dereference the freed parent device pointer.

Should devm_led_classdev_register_ext() be used to explicitly tie the
teardown to the unbind lifecycle?

[ ... ]
> @@ -107,17 +115,17 @@ fn parent(&self) -> &'bound device::Device<Bound> {
>  }
>  
[ ... ]
>  struct Adapter<T: LedOps> {
>      _p: PhantomData<T>,
>  }
>  
> -impl<T: LedOps> Adapter<T> {
> +impl<T: LedOps<Mode = Normal>> Adapter<T> {
>      /// # Safety
>      /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
>      /// `led::Device`.

[Severity: High]
Does this Adapter contain an unsound conversion of potentially aliased
C pointers?

In blink_set_callback(), the function unconditionally converts delay_on and
delay_off pointers into mutable references:

rust/kernel/led/normal.rs:blink_set_callback()
                unsafe { &mut *delay_on },
                ...
                unsafe { &mut *delay_off },

The C function led_blink_set() and its callback signature accept these
pointers without the restrict keyword. This means C callers are legally
permitted to pass the same pointer for both arguments.

Could a C caller aliasing these pointers create overlapping mutable
references and trigger undefined behavior?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-rust_leds-v23-0-2716a4ef89a4@posteo.de?part=2

  reply	other threads:[~2026-08-19 19:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 18:58 [PATCH RESEND v23 0/3] rust: leds: add led classdev abstractions Markus Probst
2026-08-19 18:58 ` [PATCH RESEND v23 1/3] rust: leds: add basic " Markus Probst
2026-08-19 19:14   ` sashiko-bot
2026-08-19 18:58 ` [PATCH RESEND v23 2/3] rust: leds: add Mode trait Markus Probst
2026-08-19 19:11   ` sashiko-bot [this message]
2026-08-19 18:58 ` [PATCH RESEND v23 3/3] rust: leds: add multicolor classdev abstractions Markus Probst
2026-08-19 19:10   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-08-05 19:34 [PATCH RESEND v23 0/3] rust: leds: add led " Markus Probst via B4 Relay
2026-08-05 19:34 ` [PATCH RESEND v23 2/3] rust: leds: add Mode trait Markus Probst via B4 Relay
2026-08-05 20:42   ` 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=20260819191119.F19A51F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=markus.probst@posteo.de \
    --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