* [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
@ 2026-08-28 2:44 Nils Lehnen
2026-08-28 6:15 ` Miguel Ojeda
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Nils Lehnen @ 2026-08-28 2:44 UTC (permalink / raw)
To: Paul Moore, James Morris, Serge E . Hallyn, Miguel Ojeda
Cc: Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel,
Nils Lehnen
From: Benno Lossin <lossin@kernel.org>
All types in `bindings` implement `Zeroable` if they can, so use
`pin_init::zeroed` instead of relying on `unsafe` code.
If this ends up not compiling in the future, something in bindgen or on
the C side changed and is most likely incorrect.
Link: https://lore.kernel.org/r/20250814093046.2071971-8-lossin@kernel.org
Link: https://github.com/Rust-for-Linux/linux/issues/1189
Signed-off-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Nils Lehnen <nils.lehnen@proton.me>
---
Resend of Benno's patch from the Zeroable series [1]: only patches 1, 2
and 11 of that series were applied, and the issue [2] asks for the rest
to be re-sent. Rebased onto rust-next; it applied cleanly, and a
defconfig build with CONFIG_RUST=y and CONFIG_SECURITY=y passes.
Two equivalent one-off patches were posted earlier [3][4]; Miguel asked
in [5] for a resend that keeps Benno's authorship, which this is.
Cc'ing the LSM list per Paul's request on the original thread.
[1] https://lore.kernel.org/r/20250814093046.2071971-1-lossin@kernel.org
[2] https://github.com/Rust-for-Linux/linux/issues/1189
[3] https://lore.kernel.org/r/20251129135657.36144-1-atharvd440@gmail.com
[4] https://lore.kernel.org/r/20260120083824.477339-8-sunke@kylinos.cn
[5] https://lore.kernel.org/r/CANiq72nJqFOR9vhPBfZUNrxU+M1HMV6wN9bN6i8e9rf_oOD2qw@mail.gmail.com
rust/kernel/security.rs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/rust/kernel/security.rs b/rust/kernel/security.rs
index 9d271695265f..4dc3eba6ce84 100644
--- a/rust/kernel/security.rs
+++ b/rust/kernel/security.rs
@@ -62,8 +62,7 @@ impl SecurityCtx {
/// Get the security context given its id.
#[inline]
pub fn from_secid(secid: u32) -> Result<Self> {
- // SAFETY: `struct lsm_context` can be initialized to all zeros.
- let mut ctx: bindings::lsm_context = unsafe { core::mem::zeroed() };
+ let mut ctx: bindings::lsm_context = pin_init::zeroed();
// SAFETY: Just a C FFI call. The pointer is valid for writes.
to_result(unsafe { bindings::security_secid_to_secctx(secid, &mut ctx) })?;
base-commit: 73e3f0710014fe6d4ed98cfc02292f6121db7558
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-08-28 2:44 [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed` Nils Lehnen
@ 2026-08-28 6:15 ` Miguel Ojeda
2026-09-09 21:51 ` Paul Moore
2026-09-10 15:15 ` Alice Ryhl
2026-09-10 19:00 ` Paul Moore
2 siblings, 1 reply; 8+ messages in thread
From: Miguel Ojeda @ 2026-08-28 6:15 UTC (permalink / raw)
To: Nils Lehnen
Cc: Paul Moore, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Fri, Aug 28, 2026 at 4:44 AM Nils Lehnen <nils.lehnen@proton.me> wrote:
>
> Two equivalent one-off patches were posted earlier [3][4]; Miguel asked
> in [5] for a resend that keeps Benno's authorship, which this is.
> Cc'ing the LSM list per Paul's request on the original thread.
Looks good, thanks!
Nit: nowadays we typically use a:
Link: https://patch.msgid.link/...
to refer to a patch that was picked from the mailing list (usually
written on top of your Signed-off-by) -- `b4` can do it for you
automatically.
But no need to resend just for that, of course (and Paul/I/we can/may
change it when it gets applied :)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-08-28 6:15 ` Miguel Ojeda
@ 2026-09-09 21:51 ` Paul Moore
2026-09-09 22:43 ` Miguel Ojeda
0 siblings, 1 reply; 8+ messages in thread
From: Paul Moore @ 2026-09-09 21:51 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nils Lehnen, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Fri, Aug 28, 2026 at 2:15 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
> On Fri, Aug 28, 2026 at 4:44 AM Nils Lehnen <nils.lehnen@proton.me> wrote:
> >
> > Two equivalent one-off patches were posted earlier [3][4]; Miguel asked
> > in [5] for a resend that keeps Benno's authorship, which this is.
> > Cc'ing the LSM list per Paul's request on the original thread.
>
> Looks good, thanks!
>
> Nit: nowadays we typically use a:
>
> Link: https://patch.msgid.link/...
>
> to refer to a patch that was picked from the mailing list (usually
> written on top of your Signed-off-by) -- `b4` can do it for you
> automatically.
>
> But no need to resend just for that, of course (and Paul/I/we can/may
> change it when it gets applied :)
Looks fine to me, I'm assuming the Rust folks would prefer to take this patch?
--
paul-moore.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-09-09 21:51 ` Paul Moore
@ 2026-09-09 22:43 ` Miguel Ojeda
2026-09-10 14:20 ` Paul Moore
0 siblings, 1 reply; 8+ messages in thread
From: Miguel Ojeda @ 2026-09-09 22:43 UTC (permalink / raw)
To: Paul Moore
Cc: Nils Lehnen, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Wed, Sep 9, 2026 at 11:51 PM Paul Moore <paul@paul-moore.com> wrote:
>
> Looks fine to me, I'm assuming the Rust folks would prefer to take this patch?
Up to you! If usually patches go through your tree, then that is fine;
otherwise, I am happy to take it of course (ideally with an Acked-by).
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-09-09 22:43 ` Miguel Ojeda
@ 2026-09-10 14:20 ` Paul Moore
2026-09-10 16:13 ` Miguel Ojeda
0 siblings, 1 reply; 8+ messages in thread
From: Paul Moore @ 2026-09-10 14:20 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nils Lehnen, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Wed, Sep 9, 2026 at 6:43 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
> On Wed, Sep 9, 2026 at 11:51 PM Paul Moore <paul@paul-moore.com> wrote:
> >
> > Looks fine to me, I'm assuming the Rust folks would prefer to take this patch?
>
> Up to you! If usually patches go through your tree, then that is fine;
> otherwise, I am happy to take it of course (ideally with an Acked-by).
I'm not sure we have a "usually" yet with the Rust LSM glue code, but
I'm happy to take this patch :)
Since you've already reviewed it, can I add your Reviewed-by tag?
--
paul-moore.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-09-10 14:20 ` Paul Moore
@ 2026-09-10 16:13 ` Miguel Ojeda
0 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2026-09-10 16:13 UTC (permalink / raw)
To: Paul Moore
Cc: Nils Lehnen, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Thu, Sep 10, 2026 at 4:20 PM Paul Moore <paul@paul-moore.com> wrote:
>
> I'm not sure we have a "usually" yet with the Rust LSM glue code, but
> I'm happy to take this patch :)
>
> Since you've already reviewed it, can I add your Reviewed-by tag?
Sure!
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Cheers,
Miguel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-08-28 2:44 [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed` Nils Lehnen
2026-08-28 6:15 ` Miguel Ojeda
@ 2026-09-10 15:15 ` Alice Ryhl
2026-09-10 19:00 ` Paul Moore
2 siblings, 0 replies; 8+ messages in thread
From: Alice Ryhl @ 2026-09-10 15:15 UTC (permalink / raw)
To: Nils Lehnen
Cc: Paul Moore, James Morris, Serge E . Hallyn, Miguel Ojeda,
Benno Lossin, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel
On Fri, Aug 28, 2026 at 4:44 AM Nils Lehnen <nils.lehnen@proton.me> wrote:
>
> From: Benno Lossin <lossin@kernel.org>
>
> All types in `bindings` implement `Zeroable` if they can, so use
> `pin_init::zeroed` instead of relying on `unsafe` code.
>
> If this ends up not compiling in the future, something in bindgen or on
> the C side changed and is most likely incorrect.
>
> Link: https://lore.kernel.org/r/20250814093046.2071971-8-lossin@kernel.org
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Signed-off-by: Benno Lossin <lossin@kernel.org>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
> Signed-off-by: Nils Lehnen <nils.lehnen@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed`
2026-08-28 2:44 [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed` Nils Lehnen
2026-08-28 6:15 ` Miguel Ojeda
2026-09-10 15:15 ` Alice Ryhl
@ 2026-09-10 19:00 ` Paul Moore
2 siblings, 0 replies; 8+ messages in thread
From: Paul Moore @ 2026-09-10 19:00 UTC (permalink / raw)
To: Nils Lehnen, James Morris, Serge E . Hallyn, Miguel Ojeda
Cc: Benno Lossin, Alice Ryhl, Gary Guo, Boqun Feng, Bjorn Roy Baron,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Ozkan, Atharv Dubey,
Ke Sun, linux-security-module, rust-for-linux, linux-kernel,
Nils Lehnen
On Aug 27, 2026 Nils Lehnen <nils.lehnen@proton.me> wrote:
>
> All types in `bindings` implement `Zeroable` if they can, so use
> `pin_init::zeroed` instead of relying on `unsafe` code.
>
> If this ends up not compiling in the future, something in bindgen or on
> the C side changed and is most likely incorrect.
>
> Link: https://lore.kernel.org/r/20250814093046.2071971-8-lossin@kernel.org
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Signed-off-by: Benno Lossin <lossin@kernel.org>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
> Signed-off-by: Nils Lehnen <nils.lehnen@proton.me>
> Link: https://patch.msgid.link/...
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> Resend of Benno's patch from the Zeroable series [1]: only patches 1, 2
> and 11 of that series were applied, and the issue [2] asks for the rest
> to be re-sent. Rebased onto rust-next; it applied cleanly, and a
> defconfig build with CONFIG_RUST=y and CONFIG_SECURITY=y passes.
>
> Two equivalent one-off patches were posted earlier [3][4]; Miguel asked
> in [5] for a resend that keeps Benno's authorship, which this is.
> Cc'ing the LSM list per Paul's request on the original thread.
>
> [1] https://lore.kernel.org/r/20250814093046.2071971-1-lossin@kernel.org
> [2] https://github.com/Rust-for-Linux/linux/issues/1189
> [3] https://lore.kernel.org/r/20251129135657.36144-1-atharvd440@gmail.com
> [4] https://lore.kernel.org/r/20260120083824.477339-8-sunke@kylinos.cn
> [5] https://lore.kernel.org/r/CANiq72nJqFOR9vhPBfZUNrxU+M1HMV6wN9bN6i8e9rf_oOD2qw@mail.gmail.com
>
> rust/kernel/security.rs | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Merged into lsm/dev, thanks everyone!
--
paul-moore.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-09-10 19:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-28 2:44 [PATCH] rust: security: replace `core::mem::zeroed` with `pin_init::zeroed` Nils Lehnen
2026-08-28 6:15 ` Miguel Ojeda
2026-09-09 21:51 ` Paul Moore
2026-09-09 22:43 ` Miguel Ojeda
2026-09-10 14:20 ` Paul Moore
2026-09-10 16:13 ` Miguel Ojeda
2026-09-10 15:15 ` Alice Ryhl
2026-09-10 19:00 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®