Skip to contentSkip to conversation

userfaultfd/hugetlbfs: Fix minor fault page leak

PATCH In review Peter Xu 3 participants 3 messages Mar 22, 2021

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 userfaultfd/hugetlbfs: Fix minor fault page leak

When uffd-minor enabled, we need to put the page cache before handling the userfault in hugetlb_no_page(), otherwise the page refcount got leaked.

This can be reproduced by running userfaultfd selftest with hugetlb_shared mode, then cat /proc/meminfo.

Cc Axel Rasmussen <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Andrew Morton <[email protected]>
Fixes f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
---
 mm/hugetlb.c | 1 +
 1 file changed, 1 insertion(+)
mm/hugetlb.c +1 -0
index 408dbc08298a..56b78a206913 100644
@@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
 		/* Check for page in userfault range. */
 		if (userfaultfd_minor(vma)) {
 			unlock_page(page);
+			put_page(page);
 			ret = hugetlb_handle_userfault(vma, mapping, idx,
 						       flags, haddr,
 						       VM_UFFD_MINOR);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Peter Xu

When uffd-minor enabled, we need to put the page cache before handling the userfault in hugetlb_no_page(), otherwise the page refcount got leaked.

This can be reproduced by running userfaultfd selftest with hugetlb_shared mode, then cat /proc/meminfo.

Cc Axel Rasmussen <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Andrew Morton <[email protected]>
Fixes f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
Quoted 3 lines
---
 mm/hugetlb.c | 1 +
 1 file changed, 1 insertion(+)

Thanks for finding/fixing.

I think this is just in Andrew's tree. So it will need to be fixed there.

Signature · 1 line
Mike Kravetz
Quoted 14 lines
mm/hugetlb.c +1 -0
index 408dbc08298a..56b78a206913 100644
@@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
 		/* Check for page in userfault range. */
 		if (userfaultfd_minor(vma)) {
 			unlock_page(page);
+			put_page(page);
 			ret = hugetlb_handle_userfault(vma, mapping, idx,
 						       flags, haddr,
 						       VM_UFFD_MINOR);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Xu
Quoted 31 lines · Peter Xu

When uffd-minor enabled, we need to put the page cache before handling the userfault in hugetlb_no_page(), otherwise the page refcount got leaked.

This can be reproduced by running userfaultfd selftest with hugetlb_shared mode, then cat /proc/meminfo.

Cc Axel Rasmussen <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Andrew Morton <[email protected]>
Fixes f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
---
 mm/hugetlb.c | 1 +
 1 file changed, 1 insertion(+)
mm/hugetlb.c +1 -1
index 408dbc08298a..56b78a206913 100644
@@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
                /* Check for page in userfault range. */
                if (userfaultfd_minor(vma)) {
                        unlock_page(page);
+                       put_page(page);
                        ret = hugetlb_handle_userfault(vma, mapping, idx,
                                                       flags, haddr,
                                                       VM_UFFD_MINOR);
--
Quoted 2 lines

2.26.2

Thanks for the fix, Peter! I applied the patch and verified it does indeed fix the issue.