lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DEQZLZ9AVCZE.380X3OF521Y5L@kernel.org>
Date: Sat, 06 Dec 2025 09:23:08 +0100
From: "Benno Lossin" <lossin@...nel.org>
To: "Janne Grunau" <j@...nau.net>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
 <alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
 <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, "Andreas Hindborg" <a.hindborg@...nel.org>,
 "Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
 "Danilo Krummrich" <dakr@...nel.org>, "Fiona Behrens" <me@...enk.dev>,
 "Alban Kurti" <kurti@...icto.ai>, <rust-for-linux@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>, <asahi@...ts.linux.de>
Subject: Re: [PATCH] rust: pin-init: add references to previously
 initialized fields

On Wed Dec 3, 2025 at 11:05 PM CET, Janne Grunau wrote:
> On Fri, Sep 05, 2025 at 04:00:46PM +0200, Benno Lossin wrote:
>> After initializing a field in an initializer macro, create a variable
>> holding a reference that points at that field. The type is either
>> `Pin<&mut T>` or `&mut T` depending on the field's structural pinning
>> kind.
>
> just as a heads up: creating references broke part of the agx firmware
> init structs which uses a `#[repr(C, packed)]` struct as field in
> another struct. This fails with
>
> | error[E0793]: reference to packed field is unaligned
> |    --> ../drivers/gpu/drm/asahi/initdata.rs:722:28
> |     |
> | 722 |                       sub <- try_init!(raw::GlobalsSub::ver {
> |     |  ____________________________^
> | 723 | |                         unk_54: cfg.global_unk_54,
> | 724 | |                         unk_56: 40,
> | 725 | |                         unk_58: 0xffff,
> | ...   |
> | 731 | |                         ..Zeroable::init_zeroed()
> | 732 | |                     }),
> |     | |______________________^
> |     |
> |     = note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
> |     = note: creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
> |     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
> |     = note: this error originates in the macro `$crate::__init_internal` which comes from the expansion of the macro `try_init` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> This was easy enough to work around, I don't see how this embedding of a
> `#[repr(C, packed)]` struct was necessary or at least helpful. The code
> is not expected to be included in the upstream driver so it no worth
> spending effort on this.
>
> I don't think it's likely that anyone else will run into this but I
> thought I mention it at least.
>
> The asahi driver also ran into the discussed variable shadowing issue (a
> variable was used to initialize a field of the same name and was later
> used to initialize another field). This was trivially fixed by renaming
> the variable.

Thanks for the report, I expected the latter kind of error, but was not
aware of the packed struct issue. If anyone needs a proper workaround
from pin-init, let me know.

Cheers,
Benno

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ