exfat: fix handling of damaged volume in exfat_create_upcase_table()
Subsystems (2)
PATCH 1/1 exfat: fix handling of damaged volume in exfat_create_upcase_table()
When the size of the upcase table is set to zero in the dentry for any reason(e.g. corrupted media or misbehaving device), an integer overflow causes the module to loop indefinitely.
If the size of the upcase table is read zero, do not attempt to load the table. Instead, fallback to loading the default upcase table. If the size of the upcase table is zero or no upcase table is found, raise exfat_fs_error() to mark the volume read-only.
--- fs/exfat/nls.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
fs/exfat/nls.c +13 -6
@@ -769,13 +769,18 @@ int exfat_create_upcase_table(struct super_block *sb) tbl_clu =le32_to_cpu (ep->dentry.upcase.start_clu); tbl_size =le64_to_cpu (ep->dentry.upcase.size); - - sector =exfat_cluster_to_sector (sbi, tbl_clu); - num_sectors = ((tbl_size -1 ) >> blksize_bits) +1 ; - ret =exfat_load_upcase_table (sb, sector, num_sectors, -le32_to_cpu (ep->dentry.upcase.checksum)); - +if (tbl_size) { + sector =exfat_cluster_to_sector (sbi, tbl_clu); + num_sectors = ((tbl_size -1 ) >> blksize_bits) +1 ; + ret =exfat_load_upcase_table (sb, sector, num_sectors, +le32_to_cpu (ep->dentry.upcase.checksum)); + }else { +exfat_fs_error (sb, +"bad upcase table size (0 bytes). Please run fsck" ); + ret = -EINVAL ; + }brelse (bh); +if (ret && ret != -EIO ) {/* free memory from exfat_load_upcase_table call */ exfat_free_upcase_table (sbi);
@@ -790,6 +795,8 @@ int exfat_create_upcase_table(struct super_block *sb)return -EIO ; } +exfat_fs_error (sb,"no upcase table entry. Please run fsck" ); + load_default:/* load default upcase table */ return exfat_load_default_upcase_table (sb);
Signature · 1 line
2.53.0.1.ga224b40d3f.dirty
Quoted 11 lines · David Timber
When the size of the upcase table is set to zero in the dentry for any reason(e.g. corrupted media or misbehaving device), an integer overflow causes the module to loop indefinitely.
If the size of the upcase table is read zero, do not attempt to load the table. Instead, fallback to loading the default upcase table. If the size of the upcase table is zero or no upcase table is found, raise
exfat_fs_error()to mark the volume read-only.Signed-off-by David Timber <[email protected]>
Applied it to #dev.
Thanks.