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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]