Skip to content

Commit

Permalink
f2fs: fix fallocate to use file_modified to update permissions consis…
Browse files Browse the repository at this point in the history
…tently

commit 958ed92 upstream.

This patch tries to fix permission consistency issue as all other
mainline filesystems.

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, collapse, insert 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.

Cc: stable@kernel.org
Signed-off-by: Chao Yu <chao.yu@oppo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
chaseyu authored and gregkh committed Jun 9, 2022
1 parent f6497f5 commit 421f5c5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/f2fs/file.c
Expand Up @@ -1774,6 +1774,10 @@ static long f2fs_fallocate(struct file *file, int mode,

inode_lock(inode);

ret = file_modified(file);
if (ret)
goto out;

if (mode & FALLOC_FL_PUNCH_HOLE) {
if (offset >= inode->i_size)
goto out;
Expand Down

0 comments on commit 421f5c5

Please sign in to comment.