From: Zhi Wang <zhiw@nvidia.com>
To: Joel Fernandes <joelagnelf@nvidia.com>
Cc: linux-kernel@vger.kernel.org,
"Danilo Krummrich" <dakr@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Alistair Popple" <apopple@nvidia.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH v1 5/5] gpu: nova-core: use checked arithmetic in RISC-V firmware parsing
Date: Mon, 26 Jan 2026 10:01:32 +0200 [thread overview]
Message-ID: <20260126100132.7e566316.zhiw@nvidia.com> (raw)
In-Reply-To: <20260124231830.3088323-6-joelagnelf@nvidia.com>
On Sat, 24 Jan 2026 18:18:30 -0500
Joel Fernandes <joelagnelf@nvidia.com> wrote:
> Use checked_add() when computing offsets from firmware-provided values
> in the RISC-V firmware parsing code. These values come from the BinHdr
> structure parsed from the firmware file header.
>
> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
> ---
> drivers/gpu/nova-core/firmware/riscv.rs | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/firmware/riscv.rs
> b/drivers/gpu/nova-core/firmware/riscv.rs index
> 28dfef63657a..97030bdd9991 100644 ---
> a/drivers/gpu/nova-core/firmware/riscv.rs +++
> b/drivers/gpu/nova-core/firmware/riscv.rs @@ -47,10 +47,11 @@ impl
> RmRiscvUCodeDesc { /// Fails if the header pointed at by `bin_fw` is not
> within the bounds of the firmware image. fn new(bin_fw:
> &BinFirmware<'_>) -> Result<Self> { let offset =
> usize::from_safe_cast(bin_fw.hdr.header_offset);
> + let end = offset.checked_add(size_of::<Self>()).ok_or(EINVAL)?;
>
> bin_fw
> .fw
> - .get(offset..offset + size_of::<Self>())
> + .get(offset..end)
> .and_then(Self::from_bytes_copy)
> .ok_or(EINVAL)
> }
> @@ -80,8 +81,9 @@ pub(crate) fn new(dev: &device::Device<device::Bound>,
> fw: &Firmware) -> Result< let ucode = {
> let start = usize::from_safe_cast(bin_fw.hdr.data_offset);
> let len = usize::from_safe_cast(bin_fw.hdr.data_size);
> + let end = start.checked_add(len).ok_or(EINVAL)?;
>
> - DmaObject::from_data(dev, fw.data().get(start..start +
> len).ok_or(EINVAL)?)?
> + DmaObject::from_data(dev,
> fw.data().get(start..end).ok_or(EINVAL)?)? };
>
> Ok(Self {
Reviewed-by: Zhi Wang <zhiw@nvidia.com>
prev parent reply other threads:[~2026-01-26 8:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-24 23:18 [PATCH v1 0/5] gpu: nova-core: use checked arithmetic for firmware parsing robustness Joel Fernandes
2026-01-24 23:18 ` [PATCH v1 1/5] gpu: nova-core: use checked arithmetic in FWSEC firmware parsing Joel Fernandes
2026-01-25 9:09 ` Dirk Behme
2026-01-25 15:13 ` Joel Fernandes
2026-01-24 23:18 ` [PATCH v1 2/5] gpu: nova-core: use checked arithmetic in Booter signature parsing Joel Fernandes
2026-01-26 8:08 ` Zhi Wang
2026-01-26 11:00 ` Joel Fernandes
2026-01-24 23:18 ` [PATCH v1 3/5] gpu: nova-core: use checked arithmetic in frombytes_at helper Joel Fernandes
2026-01-26 8:00 ` Zhi Wang
2026-01-24 23:18 ` [PATCH v1 4/5] gpu: nova-core: use checked arithmetic in BinFirmware::data Joel Fernandes
2026-01-26 8:01 ` Zhi Wang
2026-01-24 23:18 ` [PATCH v1 5/5] gpu: nova-core: use checked arithmetic in RISC-V firmware parsing Joel Fernandes
2026-01-26 8:01 ` Zhi Wang [this message]
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=20260126100132.7e566316.zhiw@nvidia.com \
--to=zhiw@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=alex@ghiti.fr \
--cc=aliceryhl@google.com \
--cc=aou@eecs.berkeley.edu \
--cc=apopple@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®