Skip to contentSkip to conversation

mm-gup-memfd-stop-leaking-pinned-pages-in-low-memory-conditions.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Oct 24, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/gup: memfd: stop leaking pinned pages in low memory conditions
has been removed from the -mm tree. Its filename was
mm-gup-memfd-stop-leaking-pinned-pages-in-low-memory-conditions.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: John Hubbard <[email protected]>
Subject: mm/gup: memfd: stop leaking pinned pages in low memory conditions
Date: Thu, 17 Oct 2024 18:17:11 -0700

If check_and_migrate_movable_pages() fails, typically with -ENOMEM, then memfd_pin_folios() will leave pages pinned. Those are leaked forever, and are visible to user space as a memory leak.

Fix this by unpinning the folios that try_grab_folio(FOLL_PIN) has pinned, in such error cases.

Fixes 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
Cc Alistair Popple <[email protected]>
Cc Vivek Kasireddy <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Dave Airlie <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Peter Xu <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Junxiao Chang <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Pasha Tatashin <[email protected]>
Cc Shigeru Yoshida <[email protected]>

---

 mm/gup.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-memfd-stop-leaking-pinned-pages-in-low-memory-conditions +3 -5
@@ -3724,12 +3724,10 @@ long memfd_pin_folios(struct file *memfd
 		ret = check_and_migrate_movable_folios(nr_folios, folios);
 	} while (ret == -EAGAIN);
 
-	memalloc_pin_restore(flags);
-	return ret ? ret : nr_folios;
 err:
 	memalloc_pin_restore(flags);
-	unpin_folios(folios, nr_folios);
-
-	return ret;
+	if (ret)
+		unpin_folios(folios, nr_folios);
+	return ret ? ret : nr_folios;
 }
 EXPORT_SYMBOL_GPL(memfd_pin_folios);

_

Patches currently in -mm which might be from [email protected] are

kaslr-rename-physmem_end-and-physmem_end-to-direct_map_physmem_end.patch