exfat: fix integer overflow in exfat_create_upcase_table()
Subsystems (2)
PATCH 1/1 exfat: fix integer overflow 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 and raise exfat_fs_error() to mark the volume read-only. This is also the behaviour of MS Windows.
--- fs/exfat/nls.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
fs/exfat/nls.c +11 -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);
Signature · 1 line
2.53.0.1.ga224b40d3f.dirty
On the second thought,
Most implementations also reject volumes with no upcase table at all and fsck attempts to fix this. Linux kernel should do the same. Will reroll.
Quoted 43 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 and raise
exfat_fs_error()to mark the volume read-only. This is also the behaviour of MS Windows.Signed-off-by David Timber <[email protected]>--- fs/exfat/nls.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)fs/exfat/nls.c +11
-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);