Skip to contentSkip to conversation

f2fs: reject immutable and append-only files in atomic replace

PATCH New Hungyu Lin 1 participant 1 message Nov 20 F2FS file system

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

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.

Fixes 41e8f85a75fc ("f2fs: introduce F2FS_IOC_START_ATOMIC_REPLACE")
---
 fs/f2fs/file.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/file.c +5 -0
index a150de19b60f..ef7dc420fdde 100644
@@ -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