linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: add the tuncate check of exfat and hfsplus
@ 2023-03-04  8:35 MIngyi Cong
  2023-03-07  9:38 ` Namjae Jeon
  2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
  0 siblings, 2 replies; 10+ messages in thread
From: MIngyi Cong @ 2023-03-04  8:35 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, hyc.lee
  Cc: congmingyi, linux-kernel, linux-cifs

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 */
+#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
-- 
2.34.1


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

* Re: [PATCH] fs: add the tuncate check of exfat and hfsplus
  2023-03-04  8:35 [PATCH] fs: add the tuncate check of exfat and hfsplus MIngyi Cong
@ 2023-03-07  9:38 ` Namjae Jeon
  2023-03-28 13:13   ` [PATCH v3] fs: add the tuncate check of exfat Mingyi Cong
  2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
  1 sibling, 1 reply; 10+ messages in thread
From: Namjae Jeon @ 2023-03-07  9:38 UTC (permalink / raw)
  To: MIngyi Cong; +Cc: senozhatsky, sfrench, hyc.lee, linux-kernel, linux-cifs

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
>
>

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

* [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus
  2023-03-04  8:35 [PATCH] fs: add the tuncate check of exfat and hfsplus MIngyi Cong
  2023-03-07  9:38 ` Namjae Jeon
@ 2023-03-07 13:57 ` MIngyi Cong
  2023-03-16 14:27   ` [PATCH v3] fs: add the tuncate check of exfat MIngyi Cong
                     ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: MIngyi Cong @ 2023-03-07 13:57 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, tom
  Cc: congmingyi, linux-kernel, linux-cifs

HFS, 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>
---
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(-)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 0685c1c77b9f..881a2b37fab0 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -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) {
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
index 6325d1d0e90f..db2c81755025 100644
--- a/include/uapi/linux/magic.h
+++ b/include/uapi/linux/magic.h
@@ -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
-- 
2.34.1


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

* [PATCH v3] fs: add the tuncate check of exfat
  2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
@ 2023-03-16 14:27   ` MIngyi Cong
  2023-03-16 14:47     ` Christoph Hellwig
  2023-03-16 14:35   ` MIngyi Cong
  2023-03-16 14:45   ` MIngyi Cong
  2 siblings, 1 reply; 10+ messages in thread
From: MIngyi Cong @ 2023-03-16 14:27 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, tom
  Cc: congmingyi, linux-kernel, linux-cifs

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(-)

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
-- 
2.34.1


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

* [PATCH v3] fs: add the tuncate check of exfat
  2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
  2023-03-16 14:27   ` [PATCH v3] fs: add the tuncate check of exfat MIngyi Cong
@ 2023-03-16 14:35   ` MIngyi Cong
  2023-03-16 14:45   ` MIngyi Cong
  2 siblings, 0 replies; 10+ messages in thread
From: MIngyi Cong @ 2023-03-16 14:35 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, tom
  Cc: congmingyi, linux-kernel, linux-cifs

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 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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) {
-- 
2.34.1


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

* [PATCH v3] fs: add the tuncate check of exfat
  2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
  2023-03-16 14:27   ` [PATCH v3] fs: add the tuncate check of exfat MIngyi Cong
  2023-03-16 14:35   ` MIngyi Cong
@ 2023-03-16 14:45   ` MIngyi Cong
  2 siblings, 0 replies; 10+ messages in thread
From: MIngyi Cong @ 2023-03-16 14:45 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, tom
  Cc: congmingyi, linux-kernel, linux-cifs

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 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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) {
-- 
2.34.1


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

* Re: [PATCH v3] fs: add the tuncate check of exfat
  2023-03-16 14:27   ` [PATCH v3] fs: add the tuncate check of exfat MIngyi Cong
@ 2023-03-16 14:47     ` Christoph Hellwig
       [not found]       ` <CAABeQzW++EWfW1rKqqKJCDN5eTceVJ4r380SA6Dg99CRZtUKFw@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2023-03-16 14:47 UTC (permalink / raw)
  To: MIngyi Cong
  Cc: linkinjeon, senozhatsky, sfrench, tom, linux-kernel, linux-cifs

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.

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

* Re: [PATCH v3] fs: add the tuncate check of exfat
       [not found]       ` <CAABeQzW++EWfW1rKqqKJCDN5eTceVJ4r380SA6Dg99CRZtUKFw@mail.gmail.com>
@ 2023-03-20 13:44         ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2023-03-20 13:44 UTC (permalink / raw)
  To: Mingyi Cong
  Cc: Christoph Hellwig, linkinjeon, senozhatsky, sfrench, tom,
	linux-kernel, linux-cifs

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.

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

* [PATCH v3] fs: add the tuncate check of exfat
  2023-03-07  9:38 ` Namjae Jeon
@ 2023-03-28 13:13   ` Mingyi Cong
  2023-03-28 23:54     ` Christoph Hellwig
  0 siblings, 1 reply; 10+ messages in thread
From: Mingyi Cong @ 2023-03-28 13:13 UTC (permalink / raw)
  To: linkinjeon, senozhatsky, sfrench, tom
  Cc: congmingyi, linux-kernel, linux-cifs

From: MIngyi Cong <congmingyi@gmail.com>

EXFAT will fill zero data in truncated range.
Fix this by adding EXFAT_SUPER_MAGIC check.

Signed-off-by: MIngyi Cong <congmingyi@gmail.com>
---
 fs/ksmbd/smb2pdu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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) {
-- 
2.34.1


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

* Re: [PATCH v3] fs: add the tuncate check of exfat
  2023-03-28 13:13   ` [PATCH v3] fs: add the tuncate check of exfat Mingyi Cong
@ 2023-03-28 23:54     ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2023-03-28 23:54 UTC (permalink / raw)
  To: Mingyi Cong
  Cc: linkinjeon, senozhatsky, sfrench, tom, linux-kernel, linux-cifs

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.

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

end of thread, other threads:[~2023-03-28 23:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-04  8:35 [PATCH] fs: add the tuncate check of exfat and hfsplus MIngyi Cong
2023-03-07  9:38 ` Namjae Jeon
2023-03-28 13:13   ` [PATCH v3] fs: add the tuncate check of exfat Mingyi Cong
2023-03-28 23:54     ` Christoph Hellwig
2023-03-07 13:57 ` [PATCH v2] fs: add the tuncate check of hfs, exfat and hfsplus MIngyi Cong
2023-03-16 14:27   ` [PATCH v3] fs: add the tuncate check of exfat MIngyi Cong
2023-03-16 14:47     ` Christoph Hellwig
     [not found]       ` <CAABeQzW++EWfW1rKqqKJCDN5eTceVJ4r380SA6Dg99CRZtUKFw@mail.gmail.com>
2023-03-20 13:44         ` Christoph Hellwig
2023-03-16 14:35   ` MIngyi Cong
2023-03-16 14:45   ` MIngyi Cong

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).