fs: add the tuncate check of exfat and hfsplus
Subsystems (2)
PATCH 1/1 fs: add the tuncate check of exfat and hfsplus
From: Mingyi Cong <[email protected]>
EXFAT and HFSPLUS will fill zero data in truncated range. Fix this by adding *_SUPER_MAGIC check.
--- fs/ksmbd/smb2pdu.c | 4 +++- include/uapi/linux/magic.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +3 -1
@@ -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);
include/uapi/linux/magic.h +2 -0
@@ -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
Signature · 1 line
2.34.1
Namjae Jeon
maintainer2023-03-04 17:35 GMT+09:00, MIngyi Cong <[email protected]>:
Quoted 32 lines
From: Mingyi Cong <[email protected]>
EXFAT and HFSPLUS will fill zero data in truncated range. Fix this by adding
*_SUPER_MAGICcheck.Signed-off-by Mingyi Cong <[email protected]>--- fs/ksmbd/smb2pdu.c | 4 +++- include/uapi/linux/magic.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)fs/ksmbd/smb2pdu.c +3
-1@@ -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);fs/ksmbd/smb2pdu.c +0
-0rc =ksmbd_vfs_truncate (work, fp, newsize);include/uapi/linux/magic.h +0
-0
include/uapi/linux/magic.h line 46
Quoted 4 lines
include/uapi/linux/magic.h +1
-0@@ -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.
include/uapi/linux/magic.h line 47
Quoted 1 line
include/uapi/linux/magic.h +1
-0+#define HFSPLUS_SUPER_MAGIC 0x482b/* HFSPLUS */
Is there no need to add HFS magic?
Quoted 7 lines
include/uapi/linux/magic.h +0
-1#define NCP_SUPER_MAGIC 0x564c/* Guess, what 0x564c is :-) */ #define NFS_SUPER_MAGIC 0x6969#define OCFS2_SUPER_MAGIC 0x7461636f --2.34.1
PATCH v2 1/1 fs: add the tuncate check of hfs, exfat and hfsplus
In reply to MIngyi CongHFS, EXFAT and HFSPLUS will fill zero data in truncated range. Fix this by adding *_SUPER_MAGIC check.
---
V1 -> V2: add the truncate check of hfs and remove EXFAT_SUPER_MAGIC in magic.h
fs/ksmbd/smb2pdu.c | 5 ++++- include/uapi/linux/magic.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +4 -1
@@ -5746,7 +5746,10 @@ 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 || + inode->i_sb->s_magic !=HFS_SUPER_MAGIC ) {ksmbd_debug (SMB ,"truncated to newsize %lld\n" , newsize); rc =ksmbd_vfs_truncate (work, fp, newsize);if (rc) {
include/uapi/linux/magic.h +2 -0
@@ -46,6 +46,8 @@#define MSDOS_SUPER_MAGIC 0x4d44/* MD */ #define EXFAT_SUPER_MAGIC 0x2011BAB0 +#define HFSPLUS_SUPER_MAGIC 0x482b/* HFSPLUS */ +#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
Signature · 1 line
2.34.1
PATCH v3 1/1 fs: add the tuncate check of exfat
EXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.
---
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(-)
fs/ksmbd/smb2pdu.c +2 -1
@@ -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) {
include/uapi/linux/magic.h +1 -0
@@ -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
Signature · 1 line
2.34.1
PATCH v3 1/1 fs: add the tuncate check of exfat
In reply to MIngyi CongEXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.
---
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 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
@@ -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) {
Signature · 1 line
2.34.1
PATCH v3 1/1 fs: add the tuncate check of exfat
In reply to MIngyi CongEXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.
---
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 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
@@ -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) {
Signature · 1 line
2.34.1
Re: [PATCH v3] fs: add the tuncate check of exfat
In reply to MIngyi CongQuoted 2 lines · MIngyi Cong
EXFAT will fill zero data in truncated range.
Fix this by addingEXFAT_SUPER_MAGICcheck.
None of these is correct. We need to find a way to communicate this information without looking at magic numbers.
Re: [PATCH v3] fs: add the tuncate check of exfat
In reply to a message not in the archiveQuoted 4 lines · Mingyi Cong
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.
PATCH v3 1/1 fs: add the tuncate check of exfat
In reply to Namjae JeonFrom: MIngyi Cong <[email protected]>
EXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.
--- fs/ksmbd/smb2pdu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
@@ -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) {
Signature · 1 line
2.34.1
Re: [PATCH v3] fs: add the tuncate check of exfat
NAK again. You must not hardcode file syste magic numbers in consumers of vfs API. Not the existing one, and absolutelt not a new one. I told you a few times what to do but you keep ignoring it.