hugetlbfs: avoid overflow in hugetlbfs_fallocate
Subsystems (3)
PATCH v2 1/1 hugetlbfs: avoid overflow in hugetlbfs_fallocate
luojiajun report a problem[1] two years ago which seems still exists in mainline. vfs_fallocate can avoid 'offset + len' trigger overflow, but 'offset + len + hpage_size - 1' may overflow too and will lead to a wrong 'end'. luojiajun give a solution which can fix the wrong 'end' but leave the overflow still happened. Fix it with DIV_ROUND_UP_ULL.
[1] https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
--- fs/hugetlbfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hugetlbfs/inode.c +1 -1
@@ -651,7 +651,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,* as well as being converted to page offsets. */ start = offset >> hpage_shift; - end = (offset + len + hpage_size -1 ) >> hpage_shift; + end =DIV_ROUND_UP_ULL (offset + len, hpage_size);inode_lock (inode);
Signature · 1 line
2.31.1
Quoted 6 lines · yangerkun
luojiajun report a problem[1] two years ago which seems still exists in mainline.
vfs_fallocatecan avoid 'offset + len' trigger overflow, but 'offset + len +hpage_size- 1' may overflow too and will lead to a wrong 'end'. luojiajun give a solution which can fix the wrong 'end' but leave the overflow still happened. Fix it withDIV_ROUND_UP_ULL.
Quoted 6 lines
[1] https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
Signed-off-by yangerkun <[email protected]>--- fs/hugetlbfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thank you for fixing!
Matthew, thanks for DIV_ROUND_UP_ULL! I did not know that existed.
Signature · 1 line
Mike Kravetz