Skip to content

Commit 28e4d96

Browse files
Nick PigginLinus Torvalds
authored andcommitted
[PATCH] mm: remove_mapping() safeness
Some users of remove_mapping had been unsafe. Modify the remove_mapping precondition to ensure the caller has locked the page and obtained the correct mapping. Modify callers to ensure the mapping is the correct one. [[email protected]: swapper_space fix] Signed-off-by: Nick Piggin <[email protected]> Signed-off-by: Hugh Dickins <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bfa5bf6 commit 28e4d96

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/vmscan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ static pageout_t pageout(struct page *page, struct address_space *mapping)
377377

378378
int remove_mapping(struct address_space *mapping, struct page *page)
379379
{
380-
if (!mapping)
381-
return 0; /* truncate got there first */
380+
BUG_ON(!PageLocked(page));
381+
BUG_ON(mapping != page_mapping(page));
382382

383383
write_lock_irq(&mapping->tree_lock);
384384

@@ -547,7 +547,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
547547
goto free_it;
548548
}
549549

550-
if (!remove_mapping(mapping, page))
550+
if (!mapping || !remove_mapping(mapping, page))
551551
goto keep_locked;
552552

553553
free_it:

0 commit comments

Comments
 (0)