linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation
@ 2025-06-17  3:57 wangzijie
  2025-06-17  3:57 ` [f2fs-dev] [PATCH 2/2] f2fs: cleanup F2FS_I_SB in f2fs_setattr() wangzijie
  2025-06-17  5:22 ` [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation Chao Yu via Linux-f2fs-devel
  0 siblings, 2 replies; 6+ messages in thread
From: wangzijie @ 2025-06-17  3:57 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: feng.han, linux-kernel, linux-f2fs-devel, wangzijie

To prevent non-section-aligned size pinned file generated from truncation,
add check condition in setattr.

Signed-off-by: wangzijie <wangzijie1@honor.com>
---
 fs/f2fs/file.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 6bd3de64f..72f7d1b4a 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1026,6 +1026,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 {
 	struct inode *inode = d_inode(dentry);
 	struct f2fs_inode_info *fi = F2FS_I(inode);
+	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	int err;
 
 	if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
@@ -1047,6 +1048,11 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 			!IS_ALIGNED(attr->ia_size,
 			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
 			return -EINVAL;
+		if (f2fs_is_pinned_file(inode) &&
+			attr->ia_size < i_size_read(inode) &&
+			!IS_ALIGNED(attr->ia_size,
+			F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
+			return -EINVAL;
 	}
 
 	err = setattr_prepare(idmap, dentry, attr);
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-17 10:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17  3:57 [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation wangzijie
2025-06-17  3:57 ` [f2fs-dev] [PATCH 2/2] f2fs: cleanup F2FS_I_SB in f2fs_setattr() wangzijie
2025-06-17  5:22 ` [f2fs-dev] [PATCH 1/2] f2fs: avoid non-section-aligned size pinned file generation Chao Yu via Linux-f2fs-devel
2025-06-17  7:36   ` wangzijie
2025-06-17  9:30     ` Chao Yu via Linux-f2fs-devel
2025-06-17 10:05       ` wangzijie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).