From: Dan Carpenter <dan.carpenter@linaro.org>
To: linke li <lilinke99@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>,
David Hildenbrand <david@redhat.com>,
Linke Li <lilinke99@foxmail.com>,
linux-mm@kvack.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org, trix@redhat.com,
ndesaulniers@google.com, nathan@kernel.org,
muchun.song@linux.dev
Subject: Re: [PATCH] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap()
Date: Thu, 13 Jul 2023 18:10:08 +0300 [thread overview]
Message-ID: <6c3191e1-23fd-4f9e-9b5e-321c51599897@moroto.mountain> (raw)
In-Reply-To: <CAKdjhyD4RVHFVLrcfcuEnvwrjjxAk_GL=kjcm1iw3WTrmmFb9Q@mail.gmail.com>
On Thu, Jul 13, 2023 at 03:57:00PM +0800, linke li wrote:
> > However, if this is a real issue it would make more
> > sense to look for and change all such checks rather than one single occurrence.
>
> Hi, Mike. I have checked the example code you provided, and the
> difference between
> those codes and the patched code is that those checks are checks for
> unsigned integer
> overflow, which is well-defined. Only undefined behavior poses a
> security risk. So they
> don't need any modifications. I have only found one occurrence of
> signed number
> overflow so far.
I used to have a similar check to that but I eventually deleted it
because I decided that the -fno-strict-overflow option works. It didn't
produce a lot of warnings.
Historically we have done a bad job at open coding integer overflow
checks. Some that I wrote turned out to be incorrect. And even when
I write them correctly a couple times people have "fixed" them even
harder without CCing me or asking me why I wrote them the way I did.
What about using the check_add_overflow() macro?
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 7b17ccfa039d..c512165736e0 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -155,9 +155,8 @@ 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);
next prev parent reply other threads:[~2023-07-13 15:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-10 8:32 Linke Li
2023-07-10 16:12 ` Markus Elfring
2023-07-11 11:49 ` David Hildenbrand
2023-07-12 23:58 ` Mike Kravetz
2023-07-13 7:57 ` linke li
2023-07-13 15:10 ` Dan Carpenter [this message]
2023-07-19 23:22 ` Mike Kravetz
2023-07-20 6:25 ` linke li
2023-07-13 7:55 ` linke li
2023-07-14 12:52 ` Matthew Wilcox
2023-07-17 7:33 ` linke li
2023-07-10 9:02 Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c3191e1-23fd-4f9e-9b5e-321c51599897@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=david@redhat.com \
--cc=lilinke99@foxmail.com \
--cc=lilinke99@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=trix@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox