aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMaxim Patlasov <MPatlasov@parallels.com>2013-09-13 11:20:16 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-13 19:08:32 -0400
commit9abd30b435085cf2d897a77d657a4b6b8a56fd2c (patch)
tree2bcfd27e40bfe19c5cf01e3b4ea581a6045e6859 /fs
parenteb12ca30f11b89eab811b23562e976c1c954c7f3 (diff)
fuse: fix fallocate vs. ftruncate race
commit 0ab08f576b9e6a6b689fc6b4e632079b978e619b upstream. A former patch introducing FUSE_I_SIZE_UNSTABLE flag provided detailed description of races between ftruncate and anyone who can extend i_size: > 1. As in the previous scenario fuse_dentry_revalidate() discovered that i_size > changed (due to our own fuse_do_setattr()) and is going to call > truncate_pagecache() for some 'new_size' it believes valid right now. But by > the time that particular truncate_pagecache() is called ... > 2. fuse_do_setattr() returns (either having called truncate_pagecache() or > not -- it doesn't matter). > 3. The file is extended either by write(2) or ftruncate(2) or fallocate(2). > 4. mmap-ed write makes a page in the extended region dirty. This patch adds necessary bits to fuse_file_fallocate() to protect from that race. Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fuse/file.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 12ea203d9511..4fafb8484bbc 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2468,6 +2468,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2468{ 2468{
2469 struct fuse_file *ff = file->private_data; 2469 struct fuse_file *ff = file->private_data;
2470 struct inode *inode = file->f_inode; 2470 struct inode *inode = file->f_inode;
2471 struct fuse_inode *fi = get_fuse_inode(inode);
2471 struct fuse_conn *fc = ff->fc; 2472 struct fuse_conn *fc = ff->fc;
2472 struct fuse_req *req; 2473 struct fuse_req *req;
2473 struct fuse_fallocate_in inarg = { 2474 struct fuse_fallocate_in inarg = {
@@ -2496,6 +2497,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2496 } 2497 }
2497 } 2498 }
2498 2499
2500 if (!(mode & FALLOC_FL_KEEP_SIZE))
2501 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2502
2499 req = fuse_get_req_nopages(fc); 2503 req = fuse_get_req_nopages(fc);
2500 if (IS_ERR(req)) { 2504 if (IS_ERR(req)) {
2501 err = PTR_ERR(req); 2505 err = PTR_ERR(req);
@@ -2528,6 +2532,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2528 fuse_invalidate_attr(inode); 2532 fuse_invalidate_attr(inode);
2529 2533
2530out: 2534out:
2535 if (!(mode & FALLOC_FL_KEEP_SIZE))
2536 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2537
2531 if (lock_inode) 2538 if (lock_inode)
2532 mutex_unlock(&inode->i_mutex); 2539 mutex_unlock(&inode->i_mutex);
2533 2540