From: Nick Piggin Date: Tue, 26 Sep 2006 06:31:23 +0000 (-0700) Subject: [PATCH] mm: remove_mapping() safeness X-Git-Tag: v3.12-rc1~33966 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28e4d965e6131ace1e813e93aebca89ac6b82dc1;p=kernel%2Fkernel-generic.git [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. [hugh@veritas.com: swapper_space fix] Signed-off-by: Nick Piggin Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/vmscan.c b/mm/vmscan.c index 41a3da3..1618058 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -377,8 +377,8 @@ static pageout_t pageout(struct page *page, struct address_space *mapping) int remove_mapping(struct address_space *mapping, struct page *page) { - if (!mapping) - return 0; /* truncate got there first */ + BUG_ON(!PageLocked(page)); + BUG_ON(mapping != page_mapping(page)); write_lock_irq(&mapping->tree_lock); @@ -547,7 +547,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, goto free_it; } - if (!remove_mapping(mapping, page)) + if (!mapping || !remove_mapping(mapping, page)) goto keep_locked; free_it: