Skip to content

Commit 65291dc

Browse files
davidhildenbrandakpm00
authored andcommitted
mm/secretmem: fix GUP-fast succeeding on secretmem folios
folio_is_secretmem() currently relies on secretmem folios being LRU folios, to save some cycles. However, folios might reside in a folio batch without the LRU flag set, or temporarily have their LRU flag cleared. Consequently, the LRU flag is unreliable for this purpose. In particular, this is the case when secretmem_fault() allocates a fresh page and calls filemap_add_folio()->folio_add_lru(). The folio might be added to the per-cpu folio batch and won't get the LRU flag set until the batch was drained using e.g., lru_add_drain(). Consequently, folio_is_secretmem() might not detect secretmem folios and GUP-fast can succeed in grabbing a secretmem folio, crashing the kernel when we would later try reading/writing to the folio, because the folio has been unmapped from the directmap. Fix it by removing that unreliable check. Link: https://lkml.kernel.org/r/[email protected] Fixes: 1507f51 ("mm: introduce memfd_secret system call to create "secret" memory areas") Signed-off-by: David Hildenbrand <[email protected]> Reported-by: xingwei lee <[email protected]> Reported-by: yue sun <[email protected]> Closes: https://lore.kernel.org/lkml/CABOYnLyevJeravW=QrH0JUPYEcDN160aZFb7kwndm-J2rmz0HQ@mail.gmail.com/ Debugged-by: Miklos Szeredi <[email protected]> Tested-by: Miklos Szeredi <[email protected]> Reviewed-by: Mike Rapoport (IBM) <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 39cd87c commit 65291dc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/linux/secretmem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ static inline bool folio_is_secretmem(struct folio *folio)
1313
/*
1414
* Using folio_mapping() is quite slow because of the actual call
1515
* instruction.
16-
* We know that secretmem pages are not compound and LRU so we can
16+
* We know that secretmem pages are not compound, so we can
1717
* save a couple of cycles here.
1818
*/
19-
if (folio_test_large(folio) || !folio_test_lru(folio))
19+
if (folio_test_large(folio))
2020
return false;
2121

2222
mapping = (struct address_space *)

0 commit comments

Comments
 (0)