[PATCH v1] exfat: zero the reserved fields of file and stream extension dentries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From exFAT specification, the reserved fields should initialize
to zero and should not use for any purpose.

If create a new dentry set in the UNUSED dentries, all fields
had been zeroed when allocating cluster to parent directory.

But if create a new dentry set in the DELETED dentries, the
reserved fields in file and stream extension dentries may be
non-zero. Because only the valid bit of the type field of the
dentry is cleared in exfat_remove_entries(), if the type of
dentry is different from the original(For example, a dentry that
was originally a file name dentry, then set to deleted dentry,
and then set as a file dentry), the reserved fields is non-zero.

So this commit zeroes the reserved fields when createing file
dentry and stream extension dentry.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx>
Reviewed-by: Andy Wu <Andy.Wu@xxxxxxxx>
Reviewed-by: Aoyama Wataru <wataru.aoyama@xxxxxxxx>
---
 fs/exfat/dir.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 077944d3c2c0..cbdd9b59053d 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -428,6 +428,10 @@ static void exfat_init_stream_entry(struct exfat_dentry *ep,
 	ep->dentry.stream.start_clu = cpu_to_le32(start_clu);
 	ep->dentry.stream.valid_size = cpu_to_le64(size);
 	ep->dentry.stream.size = cpu_to_le64(size);
+
+	ep->dentry.stream.reserved1 = 0;
+	ep->dentry.stream.reserved2 = 0;
+	ep->dentry.stream.reserved3 = 0;
 }
 
 static void exfat_init_name_entry(struct exfat_dentry *ep,
@@ -474,6 +478,9 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es,
 			&ep->dentry.file.access_date,
 			NULL);
 
+	ep->dentry.file.reserved1 = 0;
+	memset(ep->dentry.file.reserved2, 0, sizeof(ep->dentry.file.reserved2));
+
 	ep = exfat_get_dentry_cached(es, ES_IDX_STREAM);
 	exfat_init_stream_entry(ep, start_clu, size);
 }
-- 
2.34.1
From a44117862361870f994029f8a8424905fe3cc0f0 Mon Sep 17 00:00:00 2001
From: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx>
Date: Fri, 12 Jan 2024 14:48:46 +0800
Subject: [PATCH v1] exfat: zero the reserved fields of file and stream
 extension dentries

From exFAT specification, the reserved fields should initialize
to zero and should not use for any purpose.

If create a new dentry set in the UNUSED dentries, all fields
had been zeroed when allocating cluster to parent directory.

But if create a new dentry set in the DELETED dentries, the
reserved fields in file and stream extension dentries may be
non-zero. Because only the valid bit of the type field of the
dentry is cleared in exfat_remove_entries(), if the type of
dentry is different from the original(For example, a dentry that
was originally a file name dentry, then set to deleted dentry,
and then set as a file dentry), the reserved fields is non-zero.

So this commit zeroes the reserved fields when createing file
dentry and stream extension dentry.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx>
Reviewed-by: Andy Wu <Andy.Wu@xxxxxxxx>
Reviewed-by: Aoyama Wataru <wataru.aoyama@xxxxxxxx>
---
 fs/exfat/dir.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 077944d3c2c0..cbdd9b59053d 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -428,6 +428,10 @@ static void exfat_init_stream_entry(struct exfat_dentry *ep,
 	ep->dentry.stream.start_clu = cpu_to_le32(start_clu);
 	ep->dentry.stream.valid_size = cpu_to_le64(size);
 	ep->dentry.stream.size = cpu_to_le64(size);
+
+	ep->dentry.stream.reserved1 = 0;
+	ep->dentry.stream.reserved2 = 0;
+	ep->dentry.stream.reserved3 = 0;
 }
 
 static void exfat_init_name_entry(struct exfat_dentry *ep,
@@ -474,6 +478,9 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es,
 			&ep->dentry.file.access_date,
 			NULL);
 
+	ep->dentry.file.reserved1 = 0;
+	memset(ep->dentry.file.reserved2, 0, sizeof(ep->dentry.file.reserved2));
+
 	ep = exfat_get_dentry_cached(es, ES_IDX_STREAM);
 	exfat_init_stream_entry(ep, start_clu, size);
 }
-- 
2.34.1


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux