Skip to content

Commit 4b4dc43

Browse files
committed
exfat: handle wrong stream entry size in exfat_readdir()
The compatibility issue between linux exfat and exfat of some camera company was reported from Florian. In their exfat, if the number of files exceeds any limit, the DataLength in stream entry of the directory is no longer updated. So some files created from camera does not show in linux exfat. because linux exfat doesn't allow that cpos becomes larger than DataLength of stream entry. This patch check DataLength in stream entry only if the type is ALLOC_NO_FAT_CHAIN and add the check ensure that dentry offset does not exceed max dentries size(256 MB) to avoid the circular FAT chain issue. Reported-by: Florian Cramer <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 2314f3c commit 4b4dc43

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dir.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
6464
static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_entry *dir_entry)
6565
{
6666
int i, dentries_per_clu, dentries_per_clu_bits = 0, num_ext;
67-
unsigned int type, clu_offset;
67+
unsigned int type, clu_offset, max_dentries;
6868
sector_t sector;
6969
struct exfat_chain dir, clu;
7070
struct exfat_uni_name uni_name;
@@ -87,6 +87,8 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
8787

8888
dentries_per_clu = sbi->dentries_per_clu;
8989
dentries_per_clu_bits = ilog2(dentries_per_clu);
90+
max_dentries = (unsigned int)min_t(u64, MAX_EXFAT_DENTRIES,
91+
(u64)sbi->num_clusters << dentries_per_clu_bits);
9092

9193
clu_offset = dentry >> dentries_per_clu_bits;
9294
exfat_chain_dup(&clu, &dir);
@@ -110,7 +112,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
110112
}
111113
}
112114

113-
while (clu.dir != EXFAT_EOF_CLUSTER) {
115+
while (clu.dir != EXFAT_EOF_CLUSTER && dentry < max_dentries) {
114116
i = dentry & (dentries_per_clu - 1);
115117

116118
for ( ; i < dentries_per_clu; i++, dentry++) {
@@ -246,7 +248,7 @@ static int exfat_iterate(struct file *filp, struct dir_context *ctx)
246248
if (err)
247249
goto unlock;
248250
get_new:
249-
if (cpos >= i_size_read(inode))
251+
if (ei->flags == ALLOC_NO_FAT_CHAIN && cpos >= i_size_read(inode))
250252
goto end_of_dir;
251253

252254
err = exfat_readdir(inode, &cpos, &de);

0 commit comments

Comments
 (0)