“215b1588ec543b2b64699ffc2b5b846c05296daa”上不存在“...native/sun/git@gitcode.net:openanolis/dragonwell8_jdk.git”
提交 13755d5b 编写于 作者: L Li Xinhai 提交者: Yang Yingliang

mm/mempolicy.c: fix checking unmapped holes for mbind

mainline inclusion
from mainline-v5.5-rc1
commit f18da660
category: bugfix
bugzilla: 97910
CVE: NA

-------------------------------------------------

mbind() is required to report EFAULT if range, specified by addr and
len, contains unmapped holes.  In current implementation, below rules
are applied for this checking:

 1: Unmapped holes at any part of the specified range should be reported
    as EFAULT if mbind() for none MPOL_DEFAULT cases;

 2: Unmapped holes at any part of the specified range should be ignored
    (do not reprot EFAULT) if mbind() for MPOL_DEFAULT case;

 3: The whole range in an unmapped hole should be reported as EFAULT;

Note that rule 2 does not fullfill the mbind() API definition, but since
that behavior has existed for long days (the internal flag
MPOL_MF_DISCONTIG_OK is for this purpose), this patch does not plan to
change it.

In current code, application observed inconsistent behavior on rule 1
and rule 2 respectively.  That inconsistency is fixed as below details.

Cases of rule 1:

 - Hole at head side of range. Current code reprot EFAULT, no change by
   this patch.

    [  vma  ][ hole ][  vma  ]
                [  range  ]

 - Hole at middle of range. Current code report EFAULT, no change by
   this patch.

    [  vma  ][ hole ][ vma ]
       [     range      ]

 - Hole at tail side of range. Current code do not report EFAULT, this
   patch fixes it.

    [  vma  ][ hole ][ vma ]
       [  range  ]

Cases of rule 2:

 - Hole at head side of range. Current code reports EFAULT, this patch
   fixes it.

    [  vma  ][ hole ][  vma  ]
                [  range  ]

 - Hole at middle of range. Current code does not report EFAULT, no
   change by this patch.

    [  vma  ][ hole ][ vma]
       [     range      ]

 - Hole at tail side of range. Current code does not report EFAULT, no
   change by this patch.

    [  vma  ][ hole ][ vma]
       [  range  ]

This patch has no changes to rule 3.

The unmapped hole checking can also be handled by using .pte_hole(),
instead of .test_walk().  But .pte_hole() is called for holes inside and
outside vma, which causes more cost, so this patch keeps the original
design with .test_walk().

Link: http://lkml.kernel.org/r/1573218104-11021-3-git-send-email-lixinhai.lxh@gmail.com
Fixes: 6f4576e3 ("mempolicy: apply page table walker on queue_pages_range()")
Signed-off-by: NLi Xinhai <lixinhai.lxh@gmail.com>
Reviewed-by: NNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Cc: linux-man <linux-man@vger.kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NNanyong Sun <sunnanyong@huawei.com>
Reviewed-by: Ntong tiangen <tongtiangen@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 8f4dd0cb
...@@ -449,7 +449,9 @@ struct queue_pages { ...@@ -449,7 +449,9 @@ struct queue_pages {
struct list_head *pagelist; struct list_head *pagelist;
unsigned long flags; unsigned long flags;
nodemask_t *nmask; nodemask_t *nmask;
struct vm_area_struct *prev; unsigned long start;
unsigned long end;
struct vm_area_struct *first;
}; };
/* /*
...@@ -658,14 +660,20 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, ...@@ -658,14 +660,20 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
unsigned long flags = qp->flags; unsigned long flags = qp->flags;
/* range check first */ /* range check first */
if (!(flags & MPOL_MF_DISCONTIG_OK)) { VM_BUG_ON((vma->vm_start > start) || (vma->vm_end < end));
if (!vma->vm_next && vma->vm_end < end)
return -EFAULT; if (!qp->first) {
if (qp->prev && qp->prev->vm_end < vma->vm_start) qp->first = vma;
if (!(flags & MPOL_MF_DISCONTIG_OK) &&
(qp->start < vma->vm_start))
/* hole at head side of range */
return -EFAULT; return -EFAULT;
} }
if (!(flags & MPOL_MF_DISCONTIG_OK) &&
qp->prev = vma; ((vma->vm_end < qp->end) &&
(!vma->vm_next || vma->vm_end < vma->vm_next->vm_start)))
/* hole at middle or tail of range */
return -EFAULT;
/* /*
* Need check MPOL_MF_STRICT to return -EIO if possible * Need check MPOL_MF_STRICT to return -EIO if possible
...@@ -677,8 +685,6 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, ...@@ -677,8 +685,6 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
if (endvma > end) if (endvma > end)
endvma = end; endvma = end;
if (vma->vm_start > start)
start = vma->vm_start;
if (flags & MPOL_MF_LAZY) { if (flags & MPOL_MF_LAZY) {
/* Similar to task_numa_work, skip inaccessible VMAs */ /* Similar to task_numa_work, skip inaccessible VMAs */
...@@ -715,11 +721,14 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end, ...@@ -715,11 +721,14 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,
nodemask_t *nodes, unsigned long flags, nodemask_t *nodes, unsigned long flags,
struct list_head *pagelist) struct list_head *pagelist)
{ {
int err;
struct queue_pages qp = { struct queue_pages qp = {
.pagelist = pagelist, .pagelist = pagelist,
.flags = flags, .flags = flags,
.nmask = nodes, .nmask = nodes,
.prev = NULL, .start = start,
.end = end,
.first = NULL,
}; };
struct mm_walk queue_pages_walk = { struct mm_walk queue_pages_walk = {
.hugetlb_entry = queue_pages_hugetlb, .hugetlb_entry = queue_pages_hugetlb,
...@@ -729,7 +738,13 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end, ...@@ -729,7 +738,13 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,
.private = &qp, .private = &qp,
}; };
return walk_page_range(start, end, &queue_pages_walk); err = walk_page_range(start, end, &queue_pages_walk);
if (!qp.first)
/* whole range in hole */
err = -EFAULT;
return err;
} }
/* /*
...@@ -781,8 +796,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start, ...@@ -781,8 +796,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
unsigned long vmend; unsigned long vmend;
vma = find_vma(mm, start); vma = find_vma(mm, start);
if (!vma || vma->vm_start > start) VM_BUG_ON(!vma);
return -EFAULT;
prev = vma->vm_prev; prev = vma->vm_prev;
if (start > vma->vm_start) if (start > vma->vm_start)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册