linux-stable/rust/kernel
Laine Taffin Altman 2ce4005d93 rust: init: remove impl Zeroable for Infallible
commit 49ceae68a0 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-05-02 16:35:25 +02:00
..
init rust: init: update expanded macro explanation 2023-08-21 14:31:49 +02:00
net rust: phy: implement `Send` for `Registration` 2024-05-02 16:35:24 +02:00
sync rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00
allocator.rs rust: bindings: rename const binding using sed 2023-12-14 20:14:01 +01:00
build_assert.rs rust: upgrade to Rust 1.68.2 2023-05-31 17:35:03 +02:00
error.rs rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00
init.rs rust: init: remove impl Zeroable for Infallible 2024-05-02 16:35:25 +02:00
ioctl.rs rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00
kunit.rs rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00
lib.rs rust: kernel: require `Send` for `Module` implementations 2024-05-02 16:35:24 +02: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: kernel: str: Implement Debug for CString 2023-12-13 00:13:49 +01:00
sync.rs rust: sync: introduce `CondVar` 2023-04-22 01:46:45 +02:00
task.rs rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00
types.rs Rust changes for v6.6 2023-08-29 08:19:46 -07:00
workqueue.rs rust: support `srctree`-relative links 2023-12-21 20:54:17 +01:00