]> Git Repo - linux.git/commit
rust: init: remove impl Zeroable for Infallible
authorLaine Taffin Altman <[email protected]>
Wed, 3 Apr 2024 21:06:59 +0000 (14:06 -0700)
committerMiguel Ojeda <[email protected]>
Thu, 4 Apr 2024 10:56:16 +0000 (12:56 +0200)
commit49ceae68a0df9a92617a61e9ce8a0efcf6419585
tree6fc29f6283b355f0aa00991c8fb61eb49dba682d
parent01848eee20c6396e5a96cfbc9061dc37481e06fd
rust: init: remove impl Zeroable for Infallible

In Rust, producing an invalid value of any type is immediate undefined
behavior (UB); this includes via zeroing memory.  Therefore, since an
uninhabited type has no valid values, producing any values at all for it is
UB.

The Rust standard library type `core::convert::Infallible` is uninhabited,
by virtue of having been declared as an enum with no cases, which always
produces uninhabited types in Rust.

The current kernel code allows this UB to be triggered, for example by code
like `Box::<core::convert::Infallible>::init(kernel::init::zeroed())`.

Thus, remove the implementation of `Zeroable` for `Infallible`, thereby
avoiding the unsoundness (potential for future UB).

Cc: [email protected]
Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function")
Closes: https://github.com/Rust-for-Linux/pinned-init/pull/13
Signed-off-by: Laine Taffin Altman <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Boqun Feng <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Reformatted the comment slightly. ]
Signed-off-by: Miguel Ojeda <[email protected]>
rust/kernel/init.rs
This page took 0.074181 seconds and 4 git commands to generate.