* FAILED: patch "[PATCH] rust: num: reject Bounded::shr overshifts at build time" failed to apply to 7.2-stable tree
@ 2026-09-03 9:55 gregkh
2026-09-03 11:01 ` [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time Miguel Ojeda
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-09-03 9:55 UTC (permalink / raw)
To: ecourtney, acourbot, dakr, gary, ojeda; +Cc: stable
The 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 <stable@vger.kernel.org>.
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 '<stable@vger.kernel.org>' --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 <ecourtney@nvidia.com>
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 ]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Cc: stable@vger.kernel.org
Fixes: c59a2d14cd24 ("rust: num: add `shr` and `shl` methods to `Bounded`")
Link: https://patch.msgid.link/20260810-pramin-split-v2-2-65a00b3c7309@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
index 9ad7df1a243d..90483d2c5374 100644
--- a/rust/kernel/num/bounded.rs
+++ b/rust/kernel/num/bounded.rs
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time
2026-09-03 9:55 FAILED: patch "[PATCH] rust: num: reject Bounded::shr overshifts at build time" failed to apply to 7.2-stable tree gregkh
@ 2026-09-03 11:01 ` Miguel Ojeda
2026-09-04 2:52 ` Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Miguel Ojeda @ 2026-09-03 11:01 UTC (permalink / raw)
To: stable
Cc: Eliot Courtney, Alexandre Courbot, Gary Guo, Danilo Krummrich,
Miguel Ojeda
From: Eliot Courtney <ecourtney@nvidia.com>
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 ]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Cc: stable@vger.kernel.org
Fixes: c59a2d14cd24 ("rust: num: add `shr` and `shl` methods to `Bounded`")
Link: https://patch.msgid.link/20260810-pramin-split-v2-2-65a00b3c7309@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
(cherry picked from commit 223aa25aee82e188ddf043a8703b16e5fdfc37d8)
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
rust/kernel/num/bounded.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
index dafe77782d79..92a17d5aec32 100644
--- a/rust/kernel/num/bounded.rs
+++ b/rust/kernel/num/bounded.rs
@@ -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
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time
2026-09-03 11:01 ` [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time Miguel Ojeda
@ 2026-09-04 2:52 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-09-04 2:52 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Eliot Courtney, Alexandre Courbot, Gary Guo,
Danilo Krummrich, Miguel Ojeda
> 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.
Queued for 7.2, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-04 2:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03 9:55 FAILED: patch "[PATCH] rust: num: reject Bounded::shr overshifts at build time" failed to apply to 7.2-stable tree gregkh
2026-09-03 11:01 ` [PATCH 7.2.y] rust: num: reject Bounded::shr overshifts at build time Miguel Ojeda
2026-09-04 2:52 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).