Thread (5 messages) 5 messages, 3 authors, 2021-03-25

Re: [PATCH] userfaultfd/shmem: fix minor fault page leak

From: Andrew Morton <akpm@linux-foundation.org>
Date: 2021-03-24 23:21:13
Also in: linux-fsdevel, linux-kselftest, lkml

On Mon, 22 Mar 2021 13:48:35 -0700 Axel Rasmussen [off-list ref] wrote:
This fix is analogous to Peter Xu's fix for hugetlb [0]. If we don't
put_page() after getting the page out of the page cache, we leak the
reference.

The fix can be verified by checking /proc/meminfo and running the
userfaultfd selftest in shmem mode. Without the fix, we see MemFree /
MemAvailable steadily decreasing with each run of the test. With the
fix, memory is correctly freed after the test program exits.

Fixes: 00da60b9d0a0 ("userfaultfd: support minor fault handling for shmem")
Confused.  The affected code:
quoted hunk ↗ jump to hunk
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1831,6 +1831,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
 
 	if (page && vma && userfaultfd_minor(vma)) {
 		unlock_page(page);
+		put_page(page);
 		*fault_type = handle_userfault(vmf, VM_UFFD_MINOR);
 		return 0;
 	}
Is added by Peter's "page && vma && userfaultfd_minor".  I assume that
"Fixes:" is incorrect?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help