summaryrefslogtreecommitdiffstats
path: root/mm/mempolicy.c
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2020-04-08 03:40:09 +0200
committerLinus Torvalds <torvalds@linux-foundation.org>2020-04-08 04:34:31 +0200
commitba841078cd0557b43b59c63f5c048b12168f0db2 (patch)
tree3697b4a407d713c5aca73827a2d34574865508e8 /mm/mempolicy.c
parentMerge branch 'akpm' (patches from Andrew) (diff)
downloadlinux-ba841078cd0557b43b59c63f5c048b12168f0db2.tar.xz
linux-ba841078cd0557b43b59c63f5c048b12168f0db2.zip
mm/mempolicy: Allow lookup_node() to handle fatal signal
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 <peterx@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mempolicy.c')
-rw-r--r--mm/mempolicy.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index b4a039d779b0..fb678a7254f0 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -896,12 +896,15 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
static int lookup_node(struct mm_struct *mm, unsigned long addr)
{
- struct page *p;
+ struct page *p = NULL;
int err;
int locked = 1;
err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked);
- 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);
}