diff mbox series

fs: add the tuncate check of exfat and hfsplus

Message ID 20230304083559.172398-1-congmingyi@gmail.com
State New
Headers show
Series fs: add the tuncate check of exfat and hfsplus | expand

Commit Message

Mingyi Cong March 4, 2023, 8:35 a.m. UTC
From: Mingyi Cong <congmingyi@gmail.com>

EXFAT and HFSPLUS will fill zero data in truncated range.
Fix this by adding *_SUPER_MAGIC check.

Signed-off-by: Mingyi Cong <congmingyi@gmail.com>
---
 fs/ksmbd/smb2pdu.c         | 4 +++-
 include/uapi/linux/magic.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Namjae Jeon March 7, 2023, 9:38 a.m. UTC | #1
2023-03-04 17:35 GMT+09:00, MIngyi Cong <congmingyi@gmail.com>:
> From: Mingyi Cong <congmingyi@gmail.com>
>
> EXFAT and HFSPLUS will fill zero data in truncated range.
> Fix this by adding *_SUPER_MAGIC check.
>
> Signed-off-by: Mingyi Cong <congmingyi@gmail.com>
> ---
>  fs/ksmbd/smb2pdu.c         | 4 +++-
>  include/uapi/linux/magic.h | 2 ++
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index ac029dfd2..10ab929ad 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -5738,7 +5738,9 @@ 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 ||
> +		inode->i_sb->s_magic != HFSPLUS_SUPER_MAGIC) {
>  		ksmbd_debug(SMB, "filename : %s truncated to newsize %lld\n",
>  			    fp->filename, newsize);
>  		rc = ksmbd_vfs_truncate(work, fp, newsize);
> diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
> index 35687dcb1..687b7f584 100644
> --- a/include/uapi/linux/magic.h
> +++ b/include/uapi/linux/magic.h
> @@ -43,6 +43,8 @@
>  #define MINIX3_SUPER_MAGIC	0x4d5a		/* minix v3 fs, 60 char names */
>
>  #define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
> +#define EXFAT_SUPER_MAGIC	0x2011BAB0UL		/* EXFAT */
EXFAT_SUPER_MAGIC is already here. Please check it.

> +#define HFSPLUS_SUPER_MAGIC	0x482b		/* HFSPLUS */
Is there no need to add HFS magic?

>  #define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
>  #define NFS_SUPER_MAGIC		0x6969
>  #define OCFS2_SUPER_MAGIC	0x7461636f
> --
> 2.34.1
>
>
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index ac029dfd2..10ab929ad 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -5738,7 +5738,9 @@  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 ||
+		inode->i_sb->s_magic != HFSPLUS_SUPER_MAGIC) {
 		ksmbd_debug(SMB, "filename : %s truncated to newsize %lld\n",
 			    fp->filename, newsize);
 		rc = ksmbd_vfs_truncate(work, fp, newsize);
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
index 35687dcb1..687b7f584 100644
--- a/include/uapi/linux/magic.h
+++ b/include/uapi/linux/magic.h
@@ -43,6 +43,8 @@ 
 #define MINIX3_SUPER_MAGIC	0x4d5a		/* minix v3 fs, 60 char names */
 
 #define MSDOS_SUPER_MAGIC	0x4d44		/* MD */
+#define EXFAT_SUPER_MAGIC	0x2011BAB0UL		/* EXFAT */
+#define HFSPLUS_SUPER_MAGIC	0x482b		/* HFSPLUS */
 #define NCP_SUPER_MAGIC		0x564c		/* Guess, what 0x564c is :-) */
 #define NFS_SUPER_MAGIC		0x6969
 #define OCFS2_SUPER_MAGIC	0x7461636f