linux/rust/kernel
Laine Taffin Altman 49ceae68a0 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: stable@vger.kernel.org
Fixes: 38cde0bd7b ("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 <alexanderaltman@me.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/CA160A4E-561E-4918-837E-3DCEBA74F808@me.com
[ Reformatted the comment slightly. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-04-04 12:56:16 +02:00
..
init rust: init: update expanded macro explanation 2023-08-21 14:31:49 +02:00
net rust: phy: use VTABLE_DEFAULT_ERROR 2024-01-27 14:28:00 +00:00
sync rust: kernel: stop using ptr_metadata feature 2024-02-18 21:22:27 +01:00
allocator.rs rust: kernel: fix multiple typos in documentation 2024-02-18 21:22:27 +01:00
build_assert.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
error.rs rust: error: improve unsafe code in example 2024-02-18 21:22:27 +01:00
init.rs rust: init: remove impl Zeroable for Infallible 2024-04-04 12:56:16 +02:00
ioctl.rs rust: kernel: mark code fragments in docs with backticks 2024-02-18 21:22:27 +01:00
kunit.rs rust: support srctree-relative links 2023-12-21 20:54:17 +01:00
lib.rs rust: add container_of! macro 2024-02-25 19:17:31 +01:00
net.rs rust: core abstractions for network PHY drivers 2023-12-15 09:35:50 +00:00
prelude.rs rust: add derive macro for Zeroable 2023-08-21 14:31:48 +02:00
print.rs rust: support srctree-relative links 2023-12-21 20:54:17 +01:00
static_assert.rs rust: static_assert: add static_assert! macro 2022-12-04 01:59:16 +01:00
std_vendor.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
str.rs rust: str: implement Display and Debug for BStr 2024-02-25 19:17:31 +01:00
sync.rs rust: kernel: add reexports for macros 2024-02-18 21:22:27 +01:00
task.rs rust: kernel: mark code fragments in docs with backticks 2024-02-18 21:22:27 +01:00
time.rs rust: time: add msecs to jiffies conversion 2024-01-28 19:50:48 +01:00
types.rs rust: types: add try_from_foreign() method 2024-02-25 19:17:31 +01:00
workqueue.rs workqueue: Changes for v6.9 2024-03-11 12:50:42 -07:00