From: sashiko-bot@kernel.org
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
ojeda@kernel.org, dri-devel@lists.freedesktop.org,
"Alexandre Courbot" <acourbot@nvidia.com>
Subject: Re: [PATCH v2 01/12] rust: num: use const_assert! in Bounded
Date: Mon, 10 Aug 2026 14:07:37 +0000 [thread overview]
Message-ID: <20260810140737.89EAC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810-pramin-split-v2-1-65a00b3c7309@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but Bounded::shr lacks a bound check for SHIFT < T::BITS, allowing wrapping shifts that break safety invariants and lead to Undefined Behavior.
--
--- Patch [1]: [PATCH v2 01/12] rust: num: use const_assert! in Bounded ---
commit afcfa782abd748c8cc818867c320e813e00f8278
Author: Eliot Courtney <ecourtney@nvidia.com>
rust: num: use const_assert! in Bounded
This patch converts the const-block asserts in bounded.rs to use the
const_assert! macro, matching the styling in the rest of the file.
> diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
> index dafe77782d797..9ad7df1a243d9 100644
> --- a/rust/kernel/num/bounded.rs
> +++ b/rust/kernel/num/bounded.rs
> @@ -485,7 +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!(RES + SHIFT >= N) }
> + const_assert!(RES + SHIFT >= N);
[Severity: Critical]
This isn't a bug introduced by this patch, but does Bounded::shr lack a
bounds check for SHIFT being less than the number of bits in the type?
If a caller invokes Bounded::shr with a SHIFT value greater than or equal to
the bit width of the type, the shift amount can be masked in release builds
without overflow checks. This would leave the original value unchanged.
Because the condition RES + SHIFT >= N would still be satisfied, this
unchanged value is unsafely wrapped in the returned Bounded type. If the
value exceeds RES bits, it breaks the safety invariant of the struct.
Subsequent safe calls like Bounded::cast could then trigger undefined
behavior when encountering unwrap_unchecked on a failed try_from conversion.
Could we add an additional bounds check here to prevent wrapping shifts?
>
> // SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
> // represent the shifted value by as much, and just asserted that `RES >= N - SHIFT`.
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-pramin-split-v2-0-65a00b3c7309@nvidia.com?part=1
next prev parent reply other threads:[~2026-08-10 14:07 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 13:55 [PATCH v2 00/12] gpu: nova-core: add PRAMIN window support Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 01/12] rust: num: use const_assert! in Bounded Eliot Courtney
2026-08-10 14:07 ` sashiko-bot [this message]
2026-08-10 14:23 ` Gary Guo
2026-08-10 22:24 ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 02/12] rust: num: reject Bounded::shr overshifts at build time Eliot Courtney
2026-08-10 14:23 ` Gary Guo
2026-08-10 22:25 ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 03/12] rust: num: add Bounded::shr_exact Eliot Courtney
2026-08-10 22:25 ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 04/12] gpu: nova-core: mm: Add VramAddress type Eliot Courtney
2026-08-10 22:24 ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 05/12] gpu: nova-core: mm: Implement Alignable and Debug for VramAddress Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 06/12] gpu: nova-core: mm: Add PRAMIN window registers Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 07/12] gpu: nova-core: mm: Add the memory management HAL Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 08/12] gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 09/12] docs: gpu: nova-core: Document the PRAMIN aperture mechanism Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 10/12] gpu: nova-core: mm: Add GpuMm centralized memory manager Eliot Courtney
2026-08-10 14:09 ` sashiko-bot
2026-08-10 13:55 ` [PATCH v2 11/12] gpu: nova-core: Add self-test assertion macros and config option Eliot Courtney
2026-08-10 14:09 ` sashiko-bot
2026-08-10 13:55 ` [PATCH v2 12/12] gpu: nova-core: mm: Add PRAMIN aperture self-tests Eliot Courtney
2026-08-10 14:16 ` sashiko-bot
2026-08-10 22:26 ` [PATCH v2 00/12] gpu: nova-core: add PRAMIN window support Danilo Krummrich
2026-08-11 12:31 ` Miguel Ojeda
2026-08-11 12:31 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260810140737.89EAC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acourbot@nvidia.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.