Skip to content

Commit 05fd956

Browse files
Darrick J. Wongkdave
authored andcommitted
btrfs: fix fallocate to use file_modified to update permissions consistently
Since the initial introduction of (posix) fallocate back at the turn of the century, it has been possible to use this syscall to change the user-visible contents of files. This can happen by extending the file size during a preallocation, or through any of the newer modes (punch, zero range). Because the call can be used to change file contents, we should treat it like we do any other modification to a file -- update the mtime, and drop set[ug]id privileges/capabilities. The VFS function file_modified() does all this for us if pass it a locked inode, so let's make fallocate drop permissions correctly. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bbac586 commit 05fd956

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/btrfs/file.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,8 +2957,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,
29572957
return ret;
29582958
}
29592959

2960-
static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
2960+
static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len)
29612961
{
2962+
struct inode *inode = file_inode(file);
29622963
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
29632964
struct btrfs_root *root = BTRFS_I(inode)->root;
29642965
struct extent_state *cached_state = NULL;
@@ -2990,6 +2991,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
29902991
goto out_only_mutex;
29912992
}
29922993

2994+
ret = file_modified(file);
2995+
if (ret)
2996+
goto out_only_mutex;
2997+
29932998
lockstart = round_up(offset, btrfs_inode_sectorsize(BTRFS_I(inode)));
29942999
lockend = round_down(offset + len,
29953000
btrfs_inode_sectorsize(BTRFS_I(inode))) - 1;
@@ -3430,7 +3435,7 @@ static long btrfs_fallocate(struct file *file, int mode,
34303435
return -EOPNOTSUPP;
34313436

34323437
if (mode & FALLOC_FL_PUNCH_HOLE)
3433-
return btrfs_punch_hole(inode, offset, len);
3438+
return btrfs_punch_hole(file, offset, len);
34343439

34353440
/*
34363441
* Only trigger disk allocation, don't trigger qgroup reserve
@@ -3452,6 +3457,10 @@ static long btrfs_fallocate(struct file *file, int mode,
34523457
goto out;
34533458
}
34543459

3460+
ret = file_modified(file);
3461+
if (ret)
3462+
goto out;
3463+
34553464
/*
34563465
* TODO: Move these two operations after we have checked
34573466
* accurate reserved space, or fallocate can still fail but

0 commit comments

Comments
 (0)