Skip to content

Commit 22c8ca7

Browse files
Nick PigginLinus Torvalds
authored andcommitted
[PATCH] fs: fix nobh data leak
nobh_prepare_write leaks data similarly to how simple_prepare_write did. Fix by not marking the page uptodate until nobh_commit_write time. Again, this could break weird use-cases, but none appear to exist in the tree. We can safely remove the set_page_dirty, because as the comment says, nobh_commit_write does set_page_dirty. If a filesystem wants to allocate backing store for a page dirtied via mmap, page_mkwrite is the suggested approach. Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 955eff5 commit 22c8ca7

1 file changed

Lines changed: 3 additions & 18 deletions

File tree

‎fs/buffer.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,6 @@ int nobh_prepare_write(struct page *page, unsigned from, unsigned to,
22482248
int i;
22492249
int ret = 0;
22502250
int is_mapped_to_disk = 1;
2251-
int dirtied_it = 0;
22522251

22532252
if (PageMappedToDisk(page))
22542253
return 0;
@@ -2285,14 +2284,10 @@ int nobh_prepare_write(struct page *page, unsigned from, unsigned to,
22852284
continue;
22862285
if (buffer_new(&map_bh) || !buffer_mapped(&map_bh)) {
22872286
kaddr = kmap_atomic(page, KM_USER0);
2288-
if (block_start < from) {
2287+
if (block_start < from)
22892288
memset(kaddr+block_start, 0, from-block_start);
2290-
dirtied_it = 1;
2291-
}
2292-
if (block_end > to) {
2289+
if (block_end > to)
22932290
memset(kaddr + to, 0, block_end - to);
2294-
dirtied_it = 1;
2295-
}
22962291
flush_dcache_page(page);
22972292
kunmap_atomic(kaddr, KM_USER0);
22982293
continue;
@@ -2347,17 +2342,6 @@ int nobh_prepare_write(struct page *page, unsigned from, unsigned to,
23472342

23482343
if (is_mapped_to_disk)
23492344
SetPageMappedToDisk(page);
2350-
SetPageUptodate(page);
2351-
2352-
/*
2353-
* Setting the page dirty here isn't necessary for the prepare_write
2354-
* function - commit_write will do that. But if/when this function is
2355-
* used within the pagefault handler to ensure that all mmapped pages
2356-
* have backing space in the filesystem, we will need to dirty the page
2357-
* if its contents were altered.
2358-
*/
2359-
if (dirtied_it)
2360-
set_page_dirty(page);
23612345

23622346
return 0;
23632347

@@ -2387,6 +2371,7 @@ int nobh_commit_write(struct file *file, struct page *page,
23872371
struct inode *inode = page->mapping->host;
23882372
loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
23892373

2374+
SetPageUptodate(page);
23902375
set_page_dirty(page);
23912376
if (pos > inode->i_size) {
23922377
i_size_write(inode, pos);

0 commit comments

Comments
 (0)