diff options
author | Maxim Patlasov <MPatlasov@parallels.com> | 2013-09-13 11:20:16 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2013-09-18 08:19:59 -0400 |
commit | 0ab08f576b9e6a6b689fc6b4e632079b978e619b (patch) | |
tree | 5256bdda3a818970473c71b33f14bd8564708e14 /fs/fuse | |
parent | bde52788bdb755b9e4b75db6c434f30e32a0ca0b (diff) |
fuse: fix fallocate vs. ftruncate race
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>
Cc: stable@vger.kernel.org
Diffstat (limited to 'fs/fuse')
-rw-r--r-- | fs/fuse/file.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index f9f07c4fa517..4598345ab87d 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -2467,6 +2467,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, | |||
2467 | { | 2467 | { |
2468 | struct fuse_file *ff = file->private_data; | 2468 | struct fuse_file *ff = file->private_data; |
2469 | struct inode *inode = file->f_inode; | 2469 | struct inode *inode = file->f_inode; |
2470 | struct fuse_inode *fi = get_fuse_inode(inode); | ||
2470 | struct fuse_conn *fc = ff->fc; | 2471 | struct fuse_conn *fc = ff->fc; |
2471 | struct fuse_req *req; | 2472 | struct fuse_req *req; |
2472 | struct fuse_fallocate_in inarg = { | 2473 | struct fuse_fallocate_in inarg = { |
@@ -2495,6 +2496,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, | |||
2495 | } | 2496 | } |
2496 | } | 2497 | } |
2497 | 2498 | ||
2499 | if (!(mode & FALLOC_FL_KEEP_SIZE)) | ||
2500 | set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); | ||
2501 | |||
2498 | req = fuse_get_req_nopages(fc); | 2502 | req = fuse_get_req_nopages(fc); |
2499 | if (IS_ERR(req)) { | 2503 | if (IS_ERR(req)) { |
2500 | err = PTR_ERR(req); | 2504 | err = PTR_ERR(req); |
@@ -2527,6 +2531,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, | |||
2527 | fuse_invalidate_attr(inode); | 2531 | fuse_invalidate_attr(inode); |
2528 | 2532 | ||
2529 | out: | 2533 | out: |
2534 | if (!(mode & FALLOC_FL_KEEP_SIZE)) | ||
2535 | clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); | ||
2536 | |||
2530 | if (lock_inode) | 2537 | if (lock_inode) |
2531 | mutex_unlock(&inode->i_mutex); | 2538 | mutex_unlock(&inode->i_mutex); |
2532 | 2539 | ||