diff options
author | Hugh Dickins <hugh@veritas.com> | 2007-10-29 17:37:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-30 11:06:55 -0400 |
commit | 487e9bf25cbae11b131d6a14bdbb3a6a77380837 (patch) | |
tree | 0b6666750274aadd22b29b1282aa779831976ca1 | |
parent | 8bca44bbd39007065cc6a4e3a50201475629a6cf (diff) |
fix tmpfs BUG and AOP_WRITEPAGE_ACTIVATE
It's possible to provoke unionfs (not yet in mainline, though in mm and
some distros) to hit shmem_writepage's BUG_ON(page_mapped(page)). I expect
it's possible to provoke the 2.6.23 ecryptfs in the same way (but the
2.6.24 ecryptfs no longer calls lower level's ->writepage).
This came to light with the recent find that AOP_WRITEPAGE_ACTIVATE could
leak from tmpfs via write_cache_pages and unionfs to userspace. There's
already a fix (e423003028183df54f039dfda8b58c49e78c89d7 - writeback: don't
propagate AOP_WRITEPAGE_ACTIVATE) in the tree for that, and it's okay so
far as it goes; but insufficient because it doesn't address the underlying
issue, that shmem_writepage expects to be called only by vmscan (relying on
backing_dev_info capabilities to prevent the normal writeback path from
ever approaching it).
That's an increasingly fragile assumption, and ramdisk_writepage (the other
source of AOP_WRITEPAGE_ACTIVATEs) is already careful to check
wbc->for_reclaim before returning it. Make the same check in
shmem_writepage, thereby sidestepping the page_mapped BUG also.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: Erez Zadok <ezk@cs.sunysb.edu>
Cc: <stable@kernel.org>
Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | mm/shmem.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index 404e53bb2127..253d205914ba 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -915,6 +915,21 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) | |||
915 | struct inode *inode; | 915 | struct inode *inode; |
916 | 916 | ||
917 | BUG_ON(!PageLocked(page)); | 917 | BUG_ON(!PageLocked(page)); |
918 | /* | ||
919 | * shmem_backing_dev_info's capabilities prevent regular writeback or | ||
920 | * sync from ever calling shmem_writepage; but a stacking filesystem | ||
921 | * may use the ->writepage of its underlying filesystem, in which case | ||
922 | * we want to do nothing when that underlying filesystem is tmpfs | ||
923 | * (writing out to swap is useful as a response to memory pressure, but | ||
924 | * of no use to stabilize the data) - just redirty the page, unlock it | ||
925 | * and claim success in this case. AOP_WRITEPAGE_ACTIVATE, and the | ||
926 | * page_mapped check below, must be avoided unless we're in reclaim. | ||
927 | */ | ||
928 | if (!wbc->for_reclaim) { | ||
929 | set_page_dirty(page); | ||
930 | unlock_page(page); | ||
931 | return 0; | ||
932 | } | ||
918 | BUG_ON(page_mapped(page)); | 933 | BUG_ON(page_mapped(page)); |
919 | 934 | ||
920 | mapping = page->mapping; | 935 | mapping = page->mapping; |