All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Gary Guo <gary@garyguo.net>
Cc: Priya Bala Govindasamy <pgovind2@uci.edu>,
	m.wilczynski@samsung.com,  ojeda@kernel.org, boqun@kernel.org,
	bjorn3_gh@protonmail.com, lossin@kernel.org,
	 a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
	dakr@kernel.org,  daniel.almeida@collabora.com,
	tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev,
	 elle@weathered-steel.dev, linux-pwm@vger.kernel.org,
	rust-for-linux@vger.kernel.org,  ardalan@uci.edu,
	zhiyunq@cs.ucr.edu, dzueck@uci.edu
Subject: Re: [PATCH 1/1] rust: pwm: reject over-aligned driver data in `Chip::new()`
Date: Wed, 25 Nov 2026 18:32:27 +0100	[thread overview]
Message-ID: <awcbICD_lN4uJrKo@monoceros> (raw)
In-Reply-To: <DN4FFKMFI488.187QX5RI55L8S@garyguo.net>

[-- Attachment #1: Type: text/plain, Size: 2109 bytes --]

On Wed, Nov 25, 2026 at 04:19:30PM +0000, Gary Guo wrote:
> On Fri Nov 13, 2026 at 8:25 PM GMT, Priya Bala Govindasamy wrote:
> > `Chip::new()` does not check the alignment of the driver data type `T`.
> > This allows a Rust kernel module to choose an arbitrary alignment for `T`.
> >
> > `pwmchip_alloc()` reserves `size_of::<T>()` bytes for the driver's
> > private data. `pwmchip_priv()` aligns this storage to `PWMCHIP_ALIGN`,
> > which is defined as `ARCH_DMA_MINALIGN`. But, `PwmOps` does not restrict
> > the alignment of `T`, so a caller may provide a `T` whose required
> > alignment is greater than `ARCH_DMA_MINALIGN`.
> 
> The commit message is overly verbose slop, please simplify it. Just state the
> issue (`pwmchip_alloc` aligns to `PWMCHIP_ALIGN` only) and the fix (reject
> drvdata with higher alignment with const_assert).
> 
> >
> > This can result in `drvdata_ptr` pointing to misaligned storage for `T`
> > in the underlying C allocation.
> > If `drvdata_ptr` is misaligned for `T`, that breaks the safety
> > requirements of `pin_init::raw_try_init()` which requires a valid,
> > aligned pointer as an argument. This is undefined behavior.
> >
> > Additionally, `Chip::drvdata()` can be called using the `Chip` produced by
> > `Chip::new()`. It creates a reference to `T` from the misaligned storage
> > which is also undefined behavior.
> 
> These all follows from underalignments and there's no need to do this
> explicitly.
> 
> >
> > Reject over-aligned types at compile time by asserting that T's alignment
> > does not exceed ARCH_DMA_MINALIGN.
> >
> > This issue was detected by FerroLens, an LLM-assisted analysis tool, and
> > was then manually analyzed and reproduced.
> 
> This should be a note and not commit message. Move it below the ---.

FTR: While I agree that the commit log is very verbose (and being only
half Rust-literate I still don't understand it completely :-), but I
like the info that this was found using a tool (in contrast to being a
real problem triggering with mainline) in the commit log.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-11-25 17:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 20:25 [PATCH 0/1] rust: pwm: reject over-aligned driver data in `Chip::new()` Priya Bala Govindasamy
2026-11-13 20:25 ` [PATCH 1/1] " Priya Bala Govindasamy
2026-11-25 15:42   ` Michal Wilczynski
2026-11-26 17:38     ` Priya Bala Govindasamy
2026-11-27  9:28       ` Uwe Kleine-König
2026-11-27  9:31         ` Uwe Kleine-König
2026-11-27 14:44           ` Gary Guo
2026-11-25 16:19   ` Gary Guo
2026-11-25 17:32     ` Uwe Kleine-König [this message]
2026-11-25 17:45       ` Gary Guo
2026-11-25 23:15         ` Uwe Kleine-König

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=awcbICD_lN4uJrKo@monoceros \
    --to=ukleinek@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=ardalan@uci.edu \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dzueck@uci.edu \
    --cc=elle@weathered-steel.dev \
    --cc=gary@garyguo.net \
    --cc=linux-pwm@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=m.wilczynski@samsung.com \
    --cc=ojeda@kernel.org \
    --cc=pgovind2@uci.edu \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=zhiyunq@cs.ucr.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.