[PATCH v2 3/4] f2fs: require write permission for F2FS_IOC_RESERVE_COMPRESS_BLOCKS
From: Hungyu Lin
Date: Thu Nov 12 2026 - 17:04:52 EST
F2FS_IOC_RESERVE_COMPRESS_BLOCKS does not check who the caller is, so
any user who can open a file whose compressed blocks were released,
even read-only, can reserve the blocks again, which consumes free
space.
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 reserve the blocks through a read-only file descriptor, as
f2fs_io does.
Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
Suggested-by: Chao Yu <chao@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/f2fs/file.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 93f892b11915..9d09ce597f72 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4436,6 +4436,9 @@ static int f2fs_reserve_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