exfat: zero the reserved fields of file and stream extension dentries
authorYuezhang Mo <Yuezhang.Mo@sony.com>
Fri, 12 Jan 2024 06:48:46 +0000 (14:48 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Thu, 25 Apr 2024 12:59:59 +0000 (21:59 +0900)
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 initializes the dentry to 0 before createing file
dentry and stream extension dentry.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/dir.c

index 077944d3c2c025fa9b74d041f64762ce4c969dcd..84572e11cc05f34ba3bfdf0190654c5d7a8961e0 100644 (file)
@@ -420,6 +420,7 @@ static void exfat_set_entry_type(struct exfat_dentry *ep, unsigned int type)
 static void exfat_init_stream_entry(struct exfat_dentry *ep,
                unsigned int start_clu, unsigned long long size)
 {
+       memset(ep, 0, sizeof(*ep));
        exfat_set_entry_type(ep, TYPE_STREAM);
        if (size == 0)
                ep->dentry.stream.flags = ALLOC_FAT_CHAIN;
@@ -457,6 +458,7 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es,
        struct exfat_dentry *ep;
 
        ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
+       memset(ep, 0, sizeof(*ep));
        exfat_set_entry_type(ep, type);
        exfat_set_entry_time(sbi, ts,
                        &ep->dentry.file.create_tz,