Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 9abd30b

Browse files
Maxim Patlasovgregkh
authored andcommitted
fuse: fix fallocate vs. ftruncate race
commit 0ab08f5 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 <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent eb12ca3 commit 9abd30b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/fuse/file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
24682468
{
24692469
struct fuse_file *ff = file->private_data;
24702470
struct inode *inode = file->f_inode;
2471+
struct fuse_inode *fi = get_fuse_inode(inode);
24712472
struct fuse_conn *fc = ff->fc;
24722473
struct fuse_req *req;
24732474
struct fuse_fallocate_in inarg = {
@@ -2496,6 +2497,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
24962497
}
24972498
}
24982499

2500+
if (!(mode & FALLOC_FL_KEEP_SIZE))
2501+
set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2502+
24992503
req = fuse_get_req_nopages(fc);
25002504
if (IS_ERR(req)) {
25012505
err = PTR_ERR(req);
@@ -2528,6 +2532,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
25282532
fuse_invalidate_attr(inode);
25292533

25302534
out:
2535+
if (!(mode & FALLOC_FL_KEEP_SIZE))
2536+
clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2537+
25312538
if (lock_inode)
25322539
mutex_unlock(&inode->i_mutex);
25332540

0 commit comments

Comments
 (0)