Re: [PATCH v4 02/20] gpu: nova-core: vbios: use checked arithmetic for bios image range end

From: John Hubbard

Date: Fri May 22 2026 - 22:48:59 EST


On 5/18/26 7:54 PM, Eliot Courtney wrote:
> `read_bios_image_at_offset` is called with a length from the VBIOS
> header, so we should be more defensive here and use checked arithmetic.
>
> Fixes: 6fda04e7f0cd ("gpu: nova-core: vbios: Add base support for VBIOS construction and iteration")
> Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
> ---
> drivers/gpu/nova-core/vbios.rs | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>

Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx>

thanks,
--
John Hubbard

> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
> index 7bec81a37340..180928433766 100644
> --- a/drivers/gpu/nova-core/vbios.rs
> +++ b/drivers/gpu/nova-core/vbios.rs
> @@ -238,8 +238,8 @@ fn read_bios_image_at_offset(
> len: usize,
> context: &str,
> ) -> Result<BiosImage> {
> - let data_len = self.data.len();
> - if offset + len > data_len {
> + let end = offset.checked_add(len).ok_or(EINVAL)?;
> + if end > self.data.len() {
> self.read_more_at_offset(offset, len).inspect_err(|e| {
> dev_err!(
> self.dev,
> @@ -250,7 +250,7 @@ fn read_bios_image_at_offset(
> })?;
> }
>
> - BiosImage::new(self.dev, &self.data[offset..offset + len]).inspect_err(|err| {
> + BiosImage::new(self.dev, &self.data[offset..end]).inspect_err(|err| {
> dev_err!(
> self.dev,
> "Failed to {} at offset {:#x}: {:?}\n",
>