From: Mike Kravetz <mike.kravetz@oracle.com>
To: David Hildenbrand <david@redhat.com>
Cc: 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, Linke Li <lilinke99@gmail.com>
Subject: Re: [PATCH] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap()
Date: Wed, 12 Jul 2023 16:58:13 -0700 [thread overview]
Message-ID: <20230712235813.GE6354@monkey> (raw)
In-Reply-To: <65f4c60a-9534-56dc-099f-ee7a96e0ccaf@redhat.com>
On 07/11/23 13:49, David Hildenbrand wrote:
> On 10.07.23 10:32, Linke Li wrote:
> > From: Linke Li <lilinke99@gmail.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;
> >
> > The existing code includes an integer overflow check, which indicates
> > that the variable len has the potential to overflow, leading to undefined
> > behavior according to the C standard. However, both GCC and Clang
> > compilers may eliminate this overflow check based on the assumption
> > that there will be no undefined behavior. Although the Linux kernel
> > disables these optimizations by using the -fno-strict-overflow option,
> > there is still a risk if the compilers make mistakes in the future.
>
> So we're adding code to handle eventual future compiler bugs? That sounds
> wrong, but maybe I misunderstood the problem you are trying to solve?
Like David, adding a fix for a potential future compiler bug sounds wrong.
I have no problem with restructuring code to make it more immune to
potential issues. However, it appears there are several places throughout
the kernel that perform similar checks. For example:
do_mmap()
/* offset overflow? */
if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
return -EOVERFLOW;
expand_upwards()
/* Enforce stack_guard_gap */
gap_addr = address + stack_guard_gap;
/* Guard against overflow */
if (gap_addr < address || gap_addr > TASK_SIZE)
gap_addr = TASK_SIZE;
do_madvise()
end = start + len;
if (end < start)
return -EINVAL;
I am not suggesting that these all be changed. The question of a real
issue still remains. 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.
--
Mike Kravetz
next prev parent reply other threads:[~2023-07-12 23:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-10 8:32 [PATCH] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap() Linke Li
2023-07-10 16:12 ` Markus Elfring
2023-07-11 11:49 ` David Hildenbrand
2023-07-12 23:58 ` Mike Kravetz [this message]
2023-07-13 7:57 ` linke li
2023-07-13 15:10 ` Dan Carpenter
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
-- strict thread matches above, loose matches on Subject: below --
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=20230712235813.GE6354@monkey \
--to=mike.kravetz@oracle.com \
--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=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;
as well as URLs for NNTP newsgroup(s).