Skip to content

Commit 4a4ac4e

Browse files
Maxim PatlasovMiklos Szeredi
authored andcommitted
fuse: postpone end_page_writeback() in fuse_writepage_locked()
The patch fixes a race between ftruncate(2), mmap-ed write and write(2): 1) An user makes a page dirty via mmap-ed write. 2) The user performs shrinking truncate(2) intended to purge the page. 3) Before fuse_do_setattr calls truncate_pagecache, the page goes to writeback. fuse_writepage_locked fills FUSE_WRITE request and releases the original page by end_page_writeback. 4) fuse_do_setattr() completes and successfully returns. Since now, i_mutex is free. 5) Ordinary write(2) extends i_size back to cover the page. Note that fuse_send_write_pages do wait for fuse writeback, but for another page->index. 6) fuse_writepage_locked proceeds by queueing FUSE_WRITE request. fuse_send_writepage is supposed to crop inarg->size of the request, but it doesn't because i_size has already been extended back. Moving end_page_writeback to the end of fuse_writepage_locked fixes the race because now the fact that truncate_pagecache is successfully returned infers that fuse_writepage_locked has already called end_page_writeback. And this, in turn, infers that fuse_flush_writepages has already called fuse_send_writepage, and the latter used valid (shrunk) i_size. write(2) could not extend it because of i_mutex held by ftruncate(2). Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Cc: stable@vger.kernel.org
1 parent 6e46645 commit 4a4ac4e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/fuse/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,14 +1529,15 @@ static int fuse_writepage_locked(struct page *page)
15291529

15301530
inc_bdi_stat(mapping->backing_dev_info, BDI_WRITEBACK);
15311531
inc_zone_page_state(tmp_page, NR_WRITEBACK_TEMP);
1532-
end_page_writeback(page);
15331532

15341533
spin_lock(&fc->lock);
15351534
list_add(&req->writepages_entry, &fi->writepages);
15361535
list_add_tail(&req->list, &fi->queued_writes);
15371536
fuse_flush_writepages(inode);
15381537
spin_unlock(&fc->lock);
15391538

1539+
end_page_writeback(page);
1540+
15401541
return 0;
15411542

15421543
err_free:

0 commit comments

Comments
 (0)