Commit cc30042
hugetlb, userfaultfd: fix reservation restore on userfaultfd error
Currently in the is_continue case in hugetlb_mcopy_atomic_pte(), if we
bail out using "goto out_release_unlock;" in the cases where idx >=
size, or !huge_pte_none(), the code will detect that new_pagecache_page
== false, and so call restore_reserve_on_error(). In this case I see
restore_reserve_on_error() delete the reservation, and the following
call to remove_inode_hugepages() will increment h->resv_hugepages
causing a 100% reproducible leak.
We should treat the is_continue case similar to adding a page into the
pagecache and set new_pagecache_page to true, to indicate that there is
no reservation to restore on the error path, and we need not call
restore_reserve_on_error(). Rename new_pagecache_page to
page_in_pagecache to make that clear.
Link: https://lkml.kernel.org/r/20211117193825.378528-1-almasrymina@google.com
Fixes: c7b1850 ("hugetlb: don't pass page cache pages to restore_reserve_on_error")
Signed-off-by: Mina Almasry <almasrymina@google.com>
Reported-by: James Houghton <jthoughton@google.com>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Wei Xu <weixugc@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent afe041c commit cc30042
1 file changed
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5736 | 5736 | | |
5737 | 5737 | | |
5738 | 5738 | | |
5739 | | - | |
| 5739 | + | |
5740 | 5740 | | |
5741 | 5741 | | |
5742 | 5742 | | |
5743 | 5743 | | |
5744 | 5744 | | |
5745 | 5745 | | |
| 5746 | + | |
5746 | 5747 | | |
5747 | 5748 | | |
5748 | 5749 | | |
| |||
5830 | 5831 | | |
5831 | 5832 | | |
5832 | 5833 | | |
5833 | | - | |
| 5834 | + | |
5834 | 5835 | | |
5835 | 5836 | | |
5836 | 5837 | | |
| |||
5894 | 5895 | | |
5895 | 5896 | | |
5896 | 5897 | | |
5897 | | - | |
| 5898 | + | |
5898 | 5899 | | |
5899 | 5900 | | |
5900 | 5901 | | |
| |||
0 commit comments