Skip to content

Commit b555895

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: fix list corruption in put_pages_list
My recent change to put_pages_list() dereferences folio->lru.next after returning the folio to the page allocator. Usually this is now on the pcp list with other free folios, so we try to free an already-free folio. This only happens with lists that have more than 15 entries, so it wasn't immediately discovered. Revert to using list_for_each_safe() so we dereference lru.next before disposing of the folio. Link: https://lkml.kernel.org/r/[email protected] Fixes: 24835f8 ("mm: use free_unref_folios() in put_pages_list()") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reported-by: "Borah, Chaitanya Kumar" <[email protected]> Closes: https://lore.kernel.org/intel-gfx/SJ1PR11MB61292145F3B79DA58ADDDA63B9232@SJ1PR11MB6129.namprd11.prod.outlook.com/ Signed-off-by: Andrew Morton <[email protected]>
1 parent 47932e7 commit b555895

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/swap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ EXPORT_SYMBOL(__folio_put);
152152
void put_pages_list(struct list_head *pages)
153153
{
154154
struct folio_batch fbatch;
155-
struct folio *folio;
155+
struct folio *folio, *next;
156156

157157
folio_batch_init(&fbatch);
158-
list_for_each_entry(folio, pages, lru) {
158+
list_for_each_entry_safe(folio, next, pages, lru) {
159159
if (!folio_put_testzero(folio))
160160
continue;
161161
if (folio_test_large(folio)) {

0 commit comments

Comments
 (0)