Skip to content

Commit 5df63c2

Browse files
mjkravetztorvalds
authored andcommitted
hugetlbfs: fix bug in pgoff overflow checking
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/20180330145402.5053-1-mike.kravetz@oracle.com Fixes: 63489f8 ("hugetlbfs: check for pgoff value overflow") Reported-by: Dan Rue <dan.rue@linaro.org> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Tested-by: Anders Roxell <anders.roxell@linaro.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Yisheng Xie <xieyisheng1@huawei.com> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com> Cc: Nic Losby <blurbdust@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7bbaf27 commit 5df63c2

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎fs/hugetlbfs/inode.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
138138

139139
/*
140140
* page based offset in vm_pgoff could be sufficiently large to
141-
* overflow a (l)off_t when converted to byte offset.
141+
* overflow a loff_t when converted to byte offset. This can
142+
* only happen on architectures where sizeof(loff_t) ==
143+
* sizeof(unsigned long). So, only check in those instances.
142144
*/
143-
if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
144-
return -EINVAL;
145+
if (sizeof(unsigned long) == sizeof(loff_t)) {
146+
if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
147+
return -EINVAL;
148+
}
145149

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

0 commit comments

Comments
 (0)