From: Hungyu Lin <dennylin0707@gmail.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: daehojeong@google.com, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, dennylin0707@gmail.com
Subject: [PATCH] f2fs: reject immutable and append-only files in atomic replace
Date: Fri, 20 Nov 2026 08:38:57 +0000 [thread overview]
Message-ID: <20261120083857.40170-1-dennylin0707@gmail.com> (raw)
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
reply other threads:[~2026-11-20 8:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120083857.40170-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=chao@kernel.org \
--cc=daehojeong@google.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®