linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: Yisheng Xie <xieyisheng1@huawei.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	bugzilla-daemon@bugzilla.kernel.org
Cc: Michal Hocko <mhocko@kernel.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Nic Losby <blurbdust@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] hugetlbfs: check for pgoff value overflow
Date: Thu, 8 Mar 2018 13:03:21 -0800	[thread overview]
Message-ID: <91e7b7af-a9b5-3a13-74d4-34868e7befd9@oracle.com> (raw)
In-Reply-To: <c41368dd-1566-c69f-ee98-8e89fdc16eeb@oracle.com>

On 03/07/2018 08:25 PM, Mike Kravetz wrote:
> On 03/07/2018 05:35 PM, Yisheng Xie wrote:
>> However, region_chg makes me a litter puzzle that when its return value < 0, sometime
>> adds_in_progress is added like this case, while sometime it is not. so why not just
>> change at the beginning of region_chg ?
>> 	if (f > t)
>> 		return -EINVAL;
> 
> If region_chg returns a value < 0, this indicates an error and adds_in_progress
> should not be incremented.  In the case of this bug, region_chg was passed
> values where f > t.  Of course, this should never happen.  But, because it
> assumed f <= t, it returned a negative count needed huge page reservations.
> The calling code interpreted the negative value as an error and a subsequent
> region_add or region_abort.
> 
> I am not opposed to adding the suggested "if (f > t)".  However, the
> region tracking routines are simple helpers only used by the hugetlbfs
> code and the assumption is that they are being called correctly.  As
> such, I would prefer to leave off the check.  But, this is the second
> time they have been called incorrectly due to insufficient argument
> checking.  If we do add this to region_chg, I would also add the check
> to all region_* routines for consistency.

I really did not want to add the (f > t) check to the region_* routines.
As mentioned we should never encounter this condition.  Adding the check
here says that we missed discovering an error at higher levels.  Therefore,
I went back and examined the callers of region_chg.  There are only 2:
hugetlb_reserve_pages and __vma_reservation_common.  hugetlb_reserve_pages
is called to set up a reservation for a mapping.  __vma_reservation_common
is called to check on an existing reservation, and only operates on a
single huge page.  With this in mind, a check in hugetlb_reserve_pages
would be sufficient.  Therefore, I added an explicit check to that routine
and printed a warning if ever encountered.

> I will send out a V2 of this patch tomorrow with the corrected overflow
> checking and possibly checks added to the region_* routines.

v2 will be sent shortly.  In v2 I Cc stable as this is an issue for
stable branches as well.

-- 
Mike Kravetz

  reply	other threads:[~2018-03-08 21:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-199037-27@https.bugzilla.kernel.org/>
2018-03-06 21:31 ` [Bug 199037] New: Kernel bug at mm/hugetlb.c:741 Andrew Morton
2018-03-06 21:46   ` Mike Kravetz
2018-03-07  0:31     ` Mike Kravetz
2018-03-07  2:49       ` Nic Losby
2018-03-07  4:19       ` Mike Kravetz
2018-03-07 16:39         ` Mike Kravetz
2018-03-07 23:59   ` [PATCH] hugetlbfs: check for pgoff value overflow Mike Kravetz
2018-03-08  0:57     ` Nic Losby
2018-03-08  1:35     ` Yisheng Xie
2018-03-08  4:25       ` Mike Kravetz
2018-03-08 21:03         ` Mike Kravetz [this message]
2018-03-08 21:05   ` [PATCH v2] " Mike Kravetz
2018-03-08 22:15     ` Andrew Morton
2018-03-08 23:37       ` Mike Kravetz
2018-03-08 23:53         ` Andrew Morton
2018-03-09  0:27   ` [PATCH v3] " Mike Kravetz
2018-03-09  1:05     ` Andrew Morton
2018-03-16 10:17     ` Michal Hocko
2018-03-16 16:19       ` Mike Kravetz
2018-03-16 16:53         ` Michal Hocko

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=91e7b7af-a9b5-3a13-74d4-34868e7befd9@oracle.com \
    --to=mike.kravetz@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=blurbdust@gmail.com \
    --cc=bugzilla-daemon@bugzilla.kernel.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=xieyisheng1@huawei.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