FAILED: patch "[PATCH] rust: num: reject Bounded::shr overshifts at build time" failed to apply to 7.2-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x 223aa25aee82e188ddf043a8703b16e5fdfc37d8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090332-lazy-chirpy-4151@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 223aa25aee82e188ddf043a8703b16e5fdfc37d8 Mon Sep 17 00:00:00 2001
From: Eliot Courtney <[email protected]>
Date: Mon, 10 Aug 2026 22:55:24 +0900
Subject: [PATCH] rust: num: reject Bounded::shr overshifts at build time
Make shr reject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.
[ This implies we can break the type invariant, which in turn means
we can trigger UB via Deref, e.g.:
rust_kernel: panicked at rust/kernel/num/bounded.rs:528:22:
unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached
- Miguel ]
rust/kernel/num/bounded.rs +1 -0
@@ -485,6 +485,7 @@ pub fn cast<U>(self) -> Bounded<U, N>/// assert_eq!(v_shifted.get(), 0xff); /// ``` pub fn shr <const SHIFT :u32 ,const RES :u32 >(self) ->Bounded <T ,RES > { +const_assert! (SHIFT <T ::BITS );const_assert! (RES +SHIFT >=N );// SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
Miguel Ojeda
maintainerPATCH 1/1 rust: num: reject Bounded::shr overshifts at build time
From: Eliot Courtney <[email protected]>
Make shr reject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.
[ This implies we can break the type invariant, which in turn means
we can trigger UB via Deref, e.g.:
rust_kernel: panicked at rust/kernel/num/bounded.rs:528:22:
unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached
- Miguel ]
--- rust/kernel/num/bounded.rs | 1 + 1 file changed, 1 insertion(+)
rust/kernel/num/bounded.rs +1 -0
@@ -485,6 +485,7 @@ pub fn cast<U>(self) -> Bounded<U, N>/// assert_eq!(v_shifted.get(), 0xff); /// ``` pub fn shr <const SHIFT :u32 ,const RES :u32 >(self) ->Bounded <T ,RES > { +const_assert! (SHIFT <T ::BITS );const {assert! (RES +SHIFT >=N ) }// SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
Signature · 1 line
2.55.0
Re: [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time
Quoted 2 lines
Make
shrreject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.
Queued for 7.2, thanks.
Signature · 2 lines
Thanks, Sasha