Commit c3c6850
rust: init: remove impl Zeroable for Infallible
stable inclusion
from stable-v6.6.30
commit c34a8052afe5f0250d443d3f4ce56dafbf9cf8a0
bugzilla: https://gitee.com/openeuler/kernel/issues/I9MPZ8
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c34a8052afe5f0250d443d3f4ce56dafbf9cf8a0
--------------------------------
commit 49ceae68a0df9a92617a61e9ce8a0efcf6419585 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: [email protected]
Fixes: 38cde0b ("rust: init: add `Zeroable` trait and `init::zeroed` function")
Closes: Rust-for-Linux/pin-init#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]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: ZhangPeng <[email protected]>1 parent ac05d44 commit c3c6850
1 file changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1292 | 1292 | | |
1293 | 1293 | | |
1294 | 1294 | | |
1295 | | - | |
1296 | | - | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
1297 | 1304 | | |
1298 | 1305 | | |
1299 | 1306 | | |
| |||
0 commit comments