f2fs: reject immutable and append-only files in atomic replace
PATCH 1/1 f2fs: reject immutable and append-only files in atomic replace
F2FS_IOC_START_ATOMIC_REPLACE truncates the file when the atomic write starts, and the commit drops the old blocks. It only checks that the file is open for writing and that the caller owns it. It does not look at the inode flags.
An append-only file can be opened for writing with O_APPEND, so the owner of such a file can remove the data that is already there, which ftruncate() and open() with O_TRUNC do not allow. For an immutable file the same works through a file descriptor that was opened for writing before the flag was set, although f2fs_write_checks() refuses writes through it.
Return -EPERM if the file is immutable or append-only. F2FS_IOC_START_ATOMIC_WRITE does not truncate the file and is not changed.
--- fs/f2fs/file.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/f2fs/file.c +5 -0
@@ -2597,6 +2597,11 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)inode_lock (inode); +if (truncate && (IS_IMMUTABLE (inode) ||IS_APPEND (inode))) { + ret = -EPERM ; + goto out; + } +if (!f2fs_disable_compressed_file (inode) ||f2fs_is_pinned_file (inode)) { ret = -EINVAL ;
Signature · 1 line
2.43.0