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 v2 2/4] f2fs: require write permission for F2FS_IOC_RELEASE_COMPRESS_BLOCKS
Date: Thu, 12 Nov 2026 21:43:01 +0000	[thread overview]
Message-ID: <20261112214303.16198-3-dennylin0707@gmail.com> (raw)
In-Reply-To: <20261112214303.16198-1-dennylin0707@gmail.com>

F2FS_IOC_RELEASE_COMPRESS_BLOCKS does not check who the caller is, so
any user who can open a compressed file, even read-only, can release
its compressed blocks. After that, writes to the file fail with -EPERM
until the blocks are reserved again or the file is truncated to zero.

Require write permission on the inode. inode_permission() does not
depend on how the file was opened, so a caller with write permission
can still release the blocks through a read-only file descriptor, as
f2fs_io and Android do.

Fixes: ef8d563f184e ("f2fs: introduce F2FS_IOC_RELEASE_COMPRESS_BLOCKS")
Suggested-by: Chao Yu <chao@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 fs/f2fs/file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index cfd24a5fa271..93f892b11915 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4238,6 +4238,9 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
 	if (f2fs_readonly(sbi->sb))
 		return -EROFS;
 
+	if (inode_permission(file_mnt_idmap(filp), inode, MAY_WRITE))
+		return -EACCES;
+
 	ret = mnt_want_write_file(filp);
 	if (ret)
 		return ret;
-- 
2.43.0


  parent reply	other threads:[~2026-11-12 21:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 21:42 [PATCH v2 0/4] f2fs: require write permission for ioctls that change per-file state Hungyu Lin
2026-11-12 21:43 ` [PATCH v2 1/4] f2fs: require write permission for F2FS_IOC_SET_PIN_FILE Hungyu Lin
2026-11-12 21:43 ` Hungyu Lin [this message]
2026-11-12 21:43 ` [PATCH v2 3/4] f2fs: require write permission for F2FS_IOC_RESERVE_COMPRESS_BLOCKS Hungyu Lin
2026-11-12 21:43 ` [PATCH v2 4/4] f2fs: require write permission for F2FS_IOC_IO_PRIO Hungyu Lin

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=20261112214303.16198-3-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®