Re: [PATCH] mm: allow unmapped hole at head side of mbind range

From: Michal Hocko
Date: Thu Oct 24 2019 - 08:26:01 EST


On Thu 24-10-19 07:35:06, Li Xinhai wrote:
> From: Li Xinhai <xinhai.li@xxxxxxxxxxx>
>
> mbind_range silently ignore unmapped hole at middle and tail of the
> specified range, but report EFAULT if hole at head side.
> It is more reasonable to support silently ignore holes at any part of
> the range, only report EFAULT if the whole range is in hole.

The changelog is a bit cryptic but you are right. find_vma returns the
first vma that ends above the given address. If vm_start > start
then there is still an overlap possible
[ vma ]
[start end]
and we should mbind [vma->vm_start, end] at least. I haven't checked
whether changing the condition is sufficient for the rest of the code to
work properly. I am pretty sure a test case shouldn't be really hard
to construct and add to the kernel testing machinery.

Btw. when writing a changelog then it is always preferred to describe
user visible effect of the patch. In this case it would be an unexpected
EFAULT on a range that starts before an existing VMA while still
overlapping it. Make sure to note that.

Fixes: 9d8cebd4bcd7 ("mm: fix mbind vma merge problem")
> Signed-off-by: Li Xinhai <xinhai.li@xxxxxxxxxxx>
> ---
>
> mm/mempolicy.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4ae967bcf954..ae160d9936d9 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -738,7 +738,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
> unsigned long vmend;
>
> vma = find_vma(mm, start);
> - if (!vma || vma->vm_start > start)
> + if (!vma || vma->vm_start >= end)
> return -EFAULT;
>
> prev = vma->vm_prev;
>

--
Michal Hocko
SUSE Labs