[lkml]   [2018]   [Mar]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [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

 \ /
  Last update: 2018-03-08 22:09    [W:0.033 / U:1.308 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site