Re: [RFC PATCH RESEND] mm: munlock: Prevent walking off the end ofa pagetable in no-pmd configuration

From: Vlastimil Babka
Date: Fri Sep 20 2013 - 05:05:17 EST


On 09/18/2013 03:17 AM, Bob Liu wrote:
> On 09/17/2013 10:22 PM, Vlastimil Babka wrote:

>> --- a/mm/mlock.c
>> +++ b/mm/mlock.c
>> @@ -379,10 +379,14 @@ static unsigned long __munlock_pagevec_fill(struct pagevec *pvec,
>>
>> /*
>> * Initialize pte walk starting at the already pinned page where we
>> - * are sure that there is a pte.
>> + * are sure that there is a pte, as it was pinned under the same
>> + * mmap_sem write op.
>> */
>> pte = get_locked_pte(vma->vm_mm, start, &ptl);
>> - end = min(end, pmd_addr_end(start, end));
>> + /* Make sure we do not cross the page table boundary */
>> + end = pgd_addr_end(start, end);
>> + end = pud_addr_end(start, end);
>> + end = pmd_addr_end(start, end);
>>
>
> Nitpick, how about unfolding pmd_addr_end(start, end) directly? Like:
>
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -376,13 +376,14 @@ static unsigned long __munlock_pagevec_fill(struct
> pagevec *pvec,
> {
> pte_t *pte;
> spinlock_t *ptl;
> + unsigned long pmd_end = (start + PMD_SIZE) & PMD_MASK;
> + end = (pmd_end - 1 < end - 1) ? pmd_end : end;
>
> /*
> * Initialize pte walk starting at the already pinned page where we
> * are sure that there is a pte.
> */
> pte = get_locked_pte(vma->vm_mm, start, &ptl);
> - end = min(end, pmd_addr_end(start, end));
>
> /* The page next to the pinned page is the first we will try to
> get */
> start += PAGE_SIZE;
>

That should also work but for maintainability reasons I wouldn't like to
special case it like this, instead of using standard functions as they
would be used in a full pagewalk.

> Anyway,
> Reviewed-by: Bob Liu <bob.liu@xxxxxxxxxx>

Thanks.

Vlastimil


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/