提交 169cc12f 编写于 作者: P Peter Xu 提交者: Cheng Jian

mm/mempolicy: Allow lookup_node() to handle fatal signal

mainline inclusion
from mainline-v5.7-rc1
commit ba841078
category: bugfix
bugzilla: 47439
CVE: NA
---------------------------

lookup_node() uses gup to pin the page and get node information.  It
checks against ret>=0 assuming the page will be filled in.  However it's
also possible that gup will return zero, for example, when the thread is
quickly killed with a fatal signal.  Teach lookup_node() to gracefully
return an error -EFAULT if it happens.

Meanwhile, initialize "page" to NULL to avoid potential risk of
exploiting the pointer.

Fixes: 4426e945 ("mm/gup: allow VM_FAULT_RETRY for multiple times")
Reported-by: syzbot+693dc11fcb53120b5559@syzkaller.appspotmail.com
Signed-off-by: NPeter Xu <peterx@redhat.com>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
 Conflicts:
	mm/mempolicy.c
Signed-off-by: NXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: NJing Xiangfeng <jingxiangfeng@huawei.com>
Reviewed-by: NKefeng  Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 bcfd7200
...@@ -897,11 +897,14 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes) ...@@ -897,11 +897,14 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
static int lookup_node(unsigned long addr) static int lookup_node(unsigned long addr)
{ {
struct page *p; struct page *p = NULL;
int err; int err;
err = get_user_pages(addr & PAGE_MASK, 1, 0, &p, NULL); err = get_user_pages(addr & PAGE_MASK, 1, 0, &p, NULL);
if (err >= 0) { if (err == 0) {
/* E.g. GUP interrupted by fatal signal */
err = -EFAULT;
} else if (err > 0) {
err = page_to_nid(p); err = page_to_nid(p);
put_page(p); put_page(p);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册