Skip to content

Commit

Permalink
hugetlbfs: fix bug in pgoff overflow checking
Browse files Browse the repository at this point in the history
This is a fix for a regression in 32 bit kernels caused by an invalid
check for pgoff overflow in hugetlbfs mmap setup.  The check incorrectly
specified that the size of a loff_t was the same as the size of a long.
The regression prevents mapping hugetlbfs files at offsets greater than
4GB on 32 bit kernels.

On 32 bit kernels conversion from a page based unsigned long can not
overflow a loff_t byte offset.  Therefore, skip this check if
sizeof(unsigned long) != sizeof(loff_t).

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 63489f8 ("hugetlbfs: check for pgoff value overflow")
Reported-by: Dan Rue <[email protected]>
Signed-off-by: Mike Kravetz <[email protected]>
Tested-by: Anders Roxell <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Yisheng Xie <[email protected]>
Cc: "Kirill A . Shutemov" <[email protected]>
Cc: Nic Losby <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mjkravetz authored and torvalds committed Apr 6, 2018
1 parent 7bbaf27 commit 5df63c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fs/hugetlbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)

/*
* page based offset in vm_pgoff could be sufficiently large to
* overflow a (l)off_t when converted to byte offset.
* overflow a loff_t when converted to byte offset. This can
* only happen on architectures where sizeof(loff_t) ==
* sizeof(unsigned long). So, only check in those instances.
*/
if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
return -EINVAL;
if (sizeof(unsigned long) == sizeof(loff_t)) {
if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
return -EINVAL;
}

/* must be huge page aligned */
if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
Expand Down

0 comments on commit 5df63c2

Please sign in to comment.