Skip to contentSkip to conversation

rust: security: use `pin_init::zeroed()` for LSM context initialization

PATCH In review Atharv Dubey 3 participants 3 messages Nov 29, 2025 – Jan 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: security: use `pin_init::zeroed()` for LSM context initialization

Replace the previous unsafe { core::mem::zeroed() } initialization of bindings::lsm_context with pin_init::zeroed().

---
 rust/kernel/security.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
rust/kernel/security.rs +1 -2
index 9d271695265f..4dc3eba6ce84 100644
@@ -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) })?;
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization of bindings::lsm_context with pin_init::zeroed().

---
 rust/kernel/security.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
rust/kernel/security.rs +0 -0
index 9d271695265f..4dc3eba6ce84 100644

rust/kernel/security.rs impl SecurityCtx { · line 65

Quoted 6 lines
rust/kernel/security.rs +1 -2
@@ -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();
#2 lore raw
In reply to Atharv Dubey
Quoted 6 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization of bindings::lsm_context with pin_init::zeroed().

These were also sent by Benno, and in the issue he mentions "re-sending", which usually means just adding your Signed-off-by below his:

    https://lore.kernel.org/all/[email protected]/

Otherwise, if he is OK without authorship, this should most likely have:

Cheers,
Miguel