Skip to contentSkip to conversation

f2fs: reject immutable and append-only files in secure trim

PATCH New Hungyu Lin 1 participant 1 message Nov 19 F2FS file system

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 f2fs: reject immutable and append-only files in secure trim

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")
---
 fs/f2fs/file.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/file.c +5 -0
index e2c0f5083313..ba131c6f9a54 100644
@@ -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;
Signature · 1 line
2.43.0