[PATCH v2 1/4] f2fs: require write permission for F2FS_IOC_SET_PIN_FILE
From: Hungyu Lin
Date: Thu Nov 12 2026 - 17:11:59 EST
F2FS_IOC_SET_PIN_FILE does not check who the caller is. Any user who
can open a file, even read-only, can:
- pin it while it has no data blocks, after which writes that extend
the file fail with -EIO;
- unpin it, so that garbage collection may move blocks that a user of
F2FS_IOC_SET_PIN_FILE expects to stay in place.
The ioctl checked inode_owner_or_capable() when it was added. Commit
aff7b628ac2d ("f2fs: set pin_file under CAP_SYS_ADMIN") replaced that
with a CAP_SYS_ADMIN check, and commit b13bdf03bb80 ("f2fs: allow all
the users to pin a file") then removed the CAP_SYS_ADMIN check, leaving
the ioctl without any permission check.
Require write permission on the inode. Users can still pin files that
they can write to.
Fixes: b13bdf03bb80 ("f2fs: allow all the users to pin a file")
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 e2c0f5083313..cfd24a5fa271 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3664,6 +3664,9 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
if (!pin && IS_DEVICE_ALIASING(inode))
return -EOPNOTSUPP;
+ 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