Skip to content

Commit 62bc7aa

Browse files
authored
Merge pull request #375 from wedsonaf/underflow
binder: Check for underflow when subtracting from user-provided value.
2 parents 5dd07d5 + 483683d commit 62bc7aa

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/android/process.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl Process {
545545
pub(crate) fn buffer_get(&self, ptr: usize) -> Option<Allocation> {
546546
let mut inner = self.inner.lock();
547547
let mapping = inner.mapping.as_mut()?;
548-
let offset = ptr - mapping.address;
548+
let offset = ptr.checked_sub(mapping.address)?;
549549
let (size, odata) = mapping.alloc.reserve_existing(offset).ok()?;
550550
let mut alloc = Allocation::new(self, offset, size, ptr, mapping.pages.clone());
551551
if let Some(data) = odata {
@@ -557,12 +557,17 @@ impl Process {
557557
pub(crate) fn buffer_raw_free(&self, ptr: usize) {
558558
let mut inner = self.inner.lock();
559559
if let Some(ref mut mapping) = &mut inner.mapping {
560-
if mapping
561-
.alloc
562-
.reservation_abort(ptr - mapping.address)
563-
.is_err()
560+
if ptr < mapping.address
561+
|| mapping
562+
.alloc
563+
.reservation_abort(ptr - mapping.address)
564+
.is_err()
564565
{
565-
pr_warn!("Offset {} failed to free\n", ptr - mapping.address);
566+
pr_warn!(
567+
"Pointer {:x} failed to free, base = {:x}\n",
568+
ptr,
569+
mapping.address
570+
);
566571
}
567572
}
568573
}

0 commit comments

Comments
 (0)