Skip to content

Commit 184fa50

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: fix out-of-bounds access of directory entries
In the case of the directory size is greater than or equal to the cluster size, if start_clu becomes an EOF cluster(an invalid cluster) due to file system corruption, then the directory entry where ei->hint_femp.eidx hint is outside the directory, resulting in an out-of-bounds access, which may cause further file system corruption. This commit adds a check for start_clu, if it is an invalid cluster, the file or directory will be treated as empty. Cc: [email protected] Signed-off-by: Yuezhang Mo <[email protected]> Co-developed-by: Namjae Jeon <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 9f16d5e commit 184fa50

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

fs/exfat/namei.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,26 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
637637
info->size = le64_to_cpu(ep2->dentry.stream.valid_size);
638638
info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
639639
info->size = le64_to_cpu(ep2->dentry.stream.size);
640+
641+
info->start_clu = le32_to_cpu(ep2->dentry.stream.start_clu);
642+
if (!is_valid_cluster(sbi, info->start_clu) && info->size) {
643+
exfat_warn(sb, "start_clu is invalid cluster(0x%x)",
644+
info->start_clu);
645+
info->size = 0;
646+
info->valid_size = 0;
647+
}
648+
649+
if (info->valid_size > info->size) {
650+
exfat_warn(sb, "valid_size(%lld) is greater than size(%lld)",
651+
info->valid_size, info->size);
652+
info->valid_size = info->size;
653+
}
654+
640655
if (info->size == 0) {
641656
info->flags = ALLOC_NO_FAT_CHAIN;
642657
info->start_clu = EXFAT_EOF_CLUSTER;
643-
} else {
658+
} else
644659
info->flags = ep2->dentry.stream.flags;
645-
info->start_clu =
646-
le32_to_cpu(ep2->dentry.stream.start_clu);
647-
}
648660

649661
exfat_get_entry_time(sbi, &info->crtime,
650662
ep->dentry.file.create_tz,

0 commit comments

Comments
 (0)