mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: reject immutable and append-only files in atomic replace
@ 2026-11-20  8:38 Hungyu Lin
  0 siblings, 0 replies; only message in thread
From: Hungyu Lin @ 2026-11-20  8:38 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: daehojeong, linux-f2fs-devel, linux-kernel, dennylin0707

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")
Cc: stable@kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 fs/f2fs/file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index a150de19b60f..ef7dc420fdde 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -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;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20  8:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  8:38 [PATCH] f2fs: reject immutable and append-only files in atomic replace Hungyu Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®