diff mbox series

[v3] fs: add the tuncate check of exfat

Message ID 20230316142753.6628-1-congmingyi@gmail.com
State New
Headers show
Series [v3] fs: add the tuncate check of exfat | expand

Commit Message

Mingyi Cong March 16, 2023, 2:27 p.m. UTC
EXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.

Signed-off-by: MIngyi Cong <congmingyi@gmail.com>
---
 V1 -> V2: add the truncate check of hfs and remove EXFAT_SUPER_MAGIC in magic.h
 V2 -> V3: remove the truncate  check of hfs and hfsplus 
 fs/ksmbd/smb2pdu.c         | 3 ++-
 include/uapi/linux/magic.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig March 16, 2023, 2:47 p.m. UTC | #1
On Thu, Mar 16, 2023 at 10:27:53PM +0800, MIngyi Cong wrote:
> EXFAT will fill zero data in truncated range.
> Fix this by adding EXFAT_SUPER_MAGIC check.

None of these is correct.  We need to find a way to communicate
this information without looking at magic numbers.
Christoph Hellwig March 20, 2023, 1:44 p.m. UTC | #2
On Thu, Mar 16, 2023 at 11:15:10PM +0800, Mingyi Cong wrote:
> After my analysis, the reason is that the truncate system call of some file
> systems will be filled with 0 data. We should add some conditional
> judgments to avoid the use of some file systems for truncate. Do you have a
> better suggestion for revision?

As Ń•aid we need a flag, be that per-file system or per-inode to flag
the behavior instead of guessing it from the major number.
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 0685c1c77b9f..3f2e34936b8d 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -5746,7 +5746,8 @@  static int set_end_of_file_info(struct ksmbd_work *work, struct ksmbd_file *fp,
 	 * truncate of some filesystem like FAT32 fill zero data in
 	 * truncated range.
 	 */
-	if (inode->i_sb->s_magic != MSDOS_SUPER_MAGIC) {
+	if (inode->i_sb->s_magic != MSDOS_SUPER_MAGIC ||
+		inode->i_sb->s_magic != EXFAT_SUPER_MAGIC) {
 		ksmbd_debug(SMB, "truncated to newsize %lld\n", newsize);
 		rc = ksmbd_vfs_truncate(work, fp, newsize);
 		if (rc) {
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
index 6325d1d0e90f..309cb3b5c5c4 100644
--- a/include/uapi/linux/magic.h
+++ b/include/uapi/linux/magic.h
@@ -46,6 +46,7 @@ 
 
 #define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
 #define EXFAT_SUPER_MAGIC	0x2011BAB0
+#define HFS_SUPER_MAGIC	0x4244		/* "BD": HFS MDB (super block) */
 #define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
 #define NFS_SUPER_MAGIC		0x6969
 #define OCFS2_SUPER_MAGIC	0x7461636f