Skip to contentSkip to conversation

mm: memfd_luo: fix PFN conversion in retrieve cleanup

PATCH In review DaeMyung Kang 2 participants 2 messages Apr 13 – Apr 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: memfd_luo: fix PFN conversion in retrieve cleanup

memfd_luo_retrieve_folios()'s error-path cleanup loop passes the raw PFN to kho_restore_folio(), but the function expects a physical address. The two other call sites in the same file (the discard path and the main retrieve loop) correctly convert with PFN_PHYS() before calling. Without the conversion the cleanup operates on the wrong address and fails to release the folios that were preserved but not yet inserted into the address space, leaking them across the live update.

Apply PFN_PHYS() to match the other call sites.

Fixes b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
---
 mm/memfd_luo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memfd_luo.c +1 -1
index b8edb9f981d7..6d8aa429f553 100644
@@ -467,7 +467,7 @@ static int memfd_luo_retrieve_folios(struct file *file,
 	for (long j = i + 1; j < nr_folios; j++) {
 		const struct memfd_luo_folio_ser *pfolio = &folios_ser[j];
 
-		folio = kho_restore_folio(pfolio->pfn);
+		folio = kho_restore_folio(PFN_PHYS(pfolio->pfn));
 		if (folio)
 			folio_put(folio);
 	}
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi DaeMyung,

Quoted 9 lines · DaeMyung Kang

memfd_luo_retrieve_folios()'s error-path cleanup loop passes the raw PFN to kho_restore_folio(), but the function expects a physical address. The two other call sites in the same file (the discard path and the main retrieve loop) correctly convert with PFN_PHYS() before calling. Without the conversion the cleanup operates on the wrong address and fails to release the folios that were preserved but not yet inserted into the address space, leaking them across the live update.

Quoted 4 lines

Apply PFN_PHYS() to match the other call sites.

Fixes b3749f174d68 ("mm: memfd_luo: allow preserving memfd")

Thanks, but this bug is also already fixed, by this patch [0].

[0] https://lore.kernel.org/linux-mm/[email protected]/

[...]

Signature · 2 lines
Regards,
Pratyush Yadav