summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fernandes <joelagnelf@nvidia.com>2026-01-26 15:23:03 -0500
committerAlexandre Courbot <acourbot@nvidia.com>2026-02-25 08:16:55 +0900
commit457c70b7dde5c14f940664fdc7f0e1998aff56be (patch)
treeadfd123f07ab926c7ed78c6f6d1b942dbdd2a60d
parent4f2609685418cc995ff6a2d558ed62214dec75dc (diff)
downloadlinux-457c70b7dde5c14f940664fdc7f0e1998aff56be.tar.gz
linux-457c70b7dde5c14f940664fdc7f0e1998aff56be.zip
gpu: nova-core: use checked arithmetic in frombytes_at helper
Use checked_add() when computing the end offset in the frombytes_at() helper function. This function is called with firmware-provided offsets. Reviewed-by: Zhi Wang <zhiw@nvidia.com> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260126202305.2526618-4-joelagnelf@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
-rw-r--r--drivers/gpu/nova-core/firmware/booter.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
index 21cd437a3c95..ab374026b1f4 100644
--- a/drivers/gpu/nova-core/firmware/booter.rs
+++ b/drivers/gpu/nova-core/firmware/booter.rs
@@ -43,8 +43,9 @@ use crate::{
/// Local convenience function to return a copy of `S` by reinterpreting the bytes starting at
/// `offset` in `slice`.
fn frombytes_at<S: FromBytes + Sized>(slice: &[u8], offset: usize) -> Result<S> {
+ let end = offset.checked_add(size_of::<S>()).ok_or(EINVAL)?;
slice
- .get(offset..offset + size_of::<S>())
+ .get(offset..end)
.and_then(S::from_bytes_copy)
.ok_or(EINVAL)
}