]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpu: nova-core: use checked arithmetic in frombytes_at helper
authorJoel Fernandes <joelagnelf@nvidia.com>
Mon, 26 Jan 2026 20:23:03 +0000 (15:23 -0500)
committerAlexandre Courbot <acourbot@nvidia.com>
Tue, 24 Feb 2026 23:16:55 +0000 (08:16 +0900)
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>
drivers/gpu/nova-core/firmware/booter.rs

index 21cd437a3c9543ad85650da889050c85af9c63f2..ab374026b1f49e5bc22a6eb0ec70f474a679e851 100644 (file)
@@ -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)
 }