Skip to content

Commit ba84107

Browse files
xzpetertorvalds
authored andcommitted
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: 4426e94 ("mm/gup: allow VM_FAULT_RETRY for multiple times") Reported-by: [email protected] Signed-off-by: Peter Xu <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 63bef48 commit ba84107

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mm/mempolicy.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,12 +896,15 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
896896

897897
static int lookup_node(struct mm_struct *mm, unsigned long addr)
898898
{
899-
struct page *p;
899+
struct page *p = NULL;
900900
int err;
901901

902902
int locked = 1;
903903
err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked);
904-
if (err >= 0) {
904+
if (err == 0) {
905+
/* E.g. GUP interrupted by fatal signal */
906+
err = -EFAULT;
907+
} else if (err > 0) {
905908
err = page_to_nid(p);
906909
put_page(p);
907910
}

0 commit comments

Comments
 (0)