Skip to content

Commit 6da2d37

Browse files
ian-abbottgregkh
authored andcommitted
UIO: Take offset into account when determining number of pages that can be mapped
If a UIO memory region does not start on a page boundary but straddles one, the number of actual pages that overlap the memory region may be calculated incorrectly because the offset isn't taken into account. If userspace sets the mmap length to offset+size, it may fail with -EINVAL if UIO thinks it's trying to allocate too many pages. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: Hans J. Koch <hjk@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 1bafeb3 commit 6da2d37

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/uio/uio.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
708708
return -EINVAL;
709709

710710
requested_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
711-
actual_pages = (idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
711+
actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
712+
+ idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
712713
if (requested_pages > actual_pages)
713714
return -EINVAL;
714715

0 commit comments

Comments
 (0)