From: Sami Tolvanen <[email protected]> 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 <[email protected]> [aliceryhl: use safe casts instead of 'as'] Signed-off-by: Alice Ryhl <[email protected]> --- 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
