mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 secure trim
Date: Thu, 19 Nov 2026 13:08:14 +0000	[thread overview]
Message-ID: <20261119130814.79404-1-dennylin0707@gmail.com> (raw)

F2FS_IOC_SEC_TRIM_FILE only checks that the file is open for writing. It
does not look at the inode flags, so it discards or zeroes the blocks of
the file even if the file is append-only or immutable.

An append-only file can be opened for writing with O_APPEND, so a user
with write permission on such a file can erase the data that is already
there, which ftruncate() and fallocate() 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.

Fixes: 9af846486d78 ("f2fs: add F2FS_IOC_SEC_TRIM_FILE ioctl")
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 e2c0f5083313..ba131c6f9a54 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4582,6 +4582,11 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
 		return ret;
 	inode_lock(inode);
 
+	if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
+		ret = -EPERM;
+		goto err;
+	}
+
 	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
 			range.start >= inode->i_size) {
 		ret = -EINVAL;
-- 
2.43.0


                 reply	other threads:[~2026-11-19 13:09 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=20261119130814.79404-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®