[PATCH] mm/mempolicy: Allow lookup_node() to handle fatal signal
From: Peter Xu
Date: Mon Apr 06 2020 - 20:40:13 EST
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.
Reported-by: syzbot+693dc11fcb53120b5559@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: 4426e945df58 ("mm/gup: allow VM_FAULT_RETRY for multiple times")
Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
mm/mempolicy.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 5fb427aed612..1398578db025 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -902,7 +902,10 @@ static int lookup_node(struct mm_struct *mm, unsigned long addr)
int locked = 1;
err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked);
- if (err >= 0) {
+ if (err == 0) {
+ /* E.g. GUP interupted by fatal signal */
+ err = -EFAULT;
+ } else if (err > 0) {
err = page_to_nid(p);
put_page(p);
}
--
2.24.1
--
Peter Xu