Skip to contentSkip to conversation

fs: add the tuncate check of exfat and hfsplus

PATCH Superseded MIngyi Cong 3 participants 10 messages Mar 4, 2023 – Mar 28, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index ac029dfd2..10ab929ad 100644
@@ -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
index 35687dcb1..687b7f584 100644
@@ -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
maintainer
#1 lore raw

2023-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_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
index ac029dfd2..10ab929ad 100644
@@ -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 -0
 		rc = ksmbd_vfs_truncate(work, fp, newsize);
include/uapi/linux/magic.h +0 -0
index 35687dcb1..687b7f584 100644

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

#4 lore raw

PATCH v2 1/1 fs: add the tuncate check of hfs, exfat and hfsplus

In reply to MIngyi Cong

HFS, 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
index 0685c1c77b9f..881a2b37fab0 100644
@@ -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
index 6325d1d0e90f..db2c81755025 100644
@@ -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
#5 lore raw

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
index 0685c1c77b9f..3f2e34936b8d 100644
@@ -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
index 6325d1d0e90f..309cb3b5c5c4 100644
@@ -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
#9 lore raw

PATCH v3 1/1 fs: add the tuncate check of exfat

In reply to MIngyi Cong

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 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
index 0685c1c77b9f..3f2e34936b8d 100644
@@ -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
#10 lore raw

PATCH v3 1/1 fs: add the tuncate check of exfat

In reply to MIngyi Cong

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 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
index 0685c1c77b9f..3f2e34936b8d 100644
@@ -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
#6 lore raw

Re: [PATCH v3] fs: add the tuncate check of exfat

In reply to MIngyi Cong
Quoted 2 lines · MIngyi Cong

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.

#8 lore raw

Re: [PATCH v3] fs: add the tuncate check of exfat

In reply to a message not in the archive
Quoted 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.

#2 lore raw

PATCH v3 1/1 fs: add the tuncate check of exfat

In reply to Namjae Jeon

From: 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
index 0685c1c77b9f..3f2e34936b8d 100644
@@ -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
#3 lore raw

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.