[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <91e7b7af-a9b5-3a13-74d4-34868e7befd9@oracle.com>
Date: Thu, 8 Mar 2018 13:03:21 -0800
From: Mike Kravetz <mike.kravetz@...cle.com>
To: Yisheng Xie <xieyisheng1@...wei.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, bugzilla-daemon@...zilla.kernel.org
Cc: Michal Hocko <mhocko@...nel.org>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Nic Losby <blurbdust@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] hugetlbfs: check for pgoff value overflow
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
Powered by blists - more mailing lists