[PATCH 4/4] drm/tyr: vm: check the remaining length in pt_unmap()
From: Alice Ryhl
Date: Tue Nov 17 2026 - 14:35:55 EST
From: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
pt_unmap() subtracts each unmapped chunk from the remaining length and
relies on unmap_pages() never unmapping more than it was asked to.
Check this subtraction and fail with EINVAL on underflow.
Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
[aliceryhl: use safe casts instead of 'as']
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
drivers/gpu/drm/tyr/vm.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index bcc864b17428..acbca552d133 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -41,6 +41,7 @@
ARM64LPAES1, //
},
new_mutex,
+ num::casts::FromSafeCast,
prelude::*,
ptr::{
Alignable,
@@ -1063,8 +1064,9 @@ fn pt_unmap(dev: &Device, pt: &IoPageTable<'_, ARM64LPAES1>, range: Range<u64>)
return Err(EINVAL);
}
- bytes_left_to_unmap -= unmapped as u64;
- iova += unmapped as u64;
+ let unmapped = u64::from_safe_cast(unmapped);
+ bytes_left_to_unmap = bytes_left_to_unmap.checked_sub(unmapped).ok_or(EINVAL)?;
+ iova += unmapped;
}
Ok(())
--
2.56.1.703.gf848ed807c-goog