[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_710619B2865DE8AC059D51A027D919CBD00A@qq.com>
Date: Thu, 20 Jul 2023 21:49:39 +0800
From: Linke Li <lilinke99@...mail.com>
To: linux-mm@...ck.org
Cc: mike.kravetz@...cle.com, muchun.song@...ux.dev, nathan@...nel.org,
ndesaulniers@...gle.com, trix@...hat.com,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
dan.carpenter@...aro.org, Linke Li <lilinke99@...il.com>
Subject: [PATCH v2] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap()
From: Linke Li <lilinke99@...il.com>
```
vma_len = (loff_t)(vma->vm_end - vma->vm_start);
len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
/* check for overflow */
if (len < vma_len)
return -EINVAL;
```
There is a signed integer overflow in the code, which is undefined
behavior according to the C stacnard. Although kernel disables some
optimizations by using the "-fno-strict-overflow" option, there is
still a risk.
Using macro "check_add_overflow" to do the overflow check can
effectively detect integer overflow and avoid any undefined behavior.
Signed-off-by: Linke Li <lilinke99@...il.com>
---
fs/hugetlbfs/inode.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 7b17ccfa039d..60f3010b0f71 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -155,9 +155,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
return -EINVAL;
vma_len = (loff_t)(vma->vm_end - vma->vm_start);
- len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
- /* check for overflow */
- if (len < vma_len)
+ if (check_add_overflow(vma_len, (loff_t)vma->vm_pgoff << PAGE_SHIFT, &len))
return -EINVAL;
inode_lock(inode);
--
2.25.1
Powered by blists - more mailing lists