From 169cc12fac3f32a122a5d6f8aa80cbe08f283c22 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Wed, 14 Apr 2021 11:58:59 +0800 Subject: [PATCH] mm/mempolicy: Allow lookup_node() to handle fatal signal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mainline inclusion from mainline-v5.7-rc1 commit ba841078cd0557b43b59c63f5c048b12168f0db2 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: 4426e945df58 ("mm/gup: allow VM_FAULT_RETRY for multiple times") Reported-by: syzbot+693dc11fcb53120b5559@syzkaller.appspotmail.com Signed-off-by: Peter Xu Signed-off-by: Linus Torvalds Conflicts: mm/mempolicy.c Signed-off-by: Xiongfeng Wang Reviewed-by: Jing Xiangfeng Reviewed-by: KefengĀ  Wang Signed-off-by: Yang Yingliang Signed-off-by: Cheng Jian --- mm/mempolicy.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 8f420c64934e..59c7e6069c1e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -897,11 +897,14 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes) static int lookup_node(unsigned long addr) { - struct page *p; + struct page *p = NULL; int err; 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); put_page(p); } -- GitLab