Skip to contentSkip to conversation

exfat: tighten down num_fats check

PATCH In review Valdis Klētnieks 2 participants 3 messages Feb 14, 2020 – Feb 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exfat: tighten down num_fats check

Change the test for num_fats from != 0 to a check for specifically 1.

Although it's theoretically possible that num_fats == 2 for a TexFAT volume (or an implementation that doesn't do the full TexFAT but does support 2 FAT tables), the rest of the code doesn't currently DTRT if it's 2 (in particular, not handling the case of ActiveFat pointing at the second FAT area), so we'll disallow that as well, as well as dealing with corrupted images that have a trash non-zero value.

fs/exfat/super.c +1 -1
@@ -450,7 +450,7 @@ static int __exfat_fill_super(struct sup
 	}
 
 	p_bpb = (struct pbr64 *)p_pbr;
-	if (!p_bpb->bsx.num_fats) {
+	if (p_bpb->bsx.num_fats  != 1) {
 		exfat_msg(sb, KERN_ERR, "bogus number of FAT structure");
 		ret = -EINVAL;
 		goto free_bh;
#1 lore raw
Quoted 14 lines

Change the test for num_fats from != 0 to a check for specifically 1.

Although it's theoretically possible that num_fats == 2 for a TexFAT volume (or an implementation that doesn't do the full TexFAT but does support 2 FAT tables), the rest of the code doesn't currently DTRT if it's 2 (in particular, not handling the case of ActiveFat pointing at the second FAT area), so we'll disallow that as well, as well as dealing with corrupted images that have a trash non-zero value.

fs/exfat/super.c static int __exfat_fill_super(struct sup · line 454

Quoted 6 lines
fs/exfat/super.c +1 -1
@@ -450,7 +450,7 @@ static int __exfat_fill_super(struct sup
 	}
 
 	p_bpb = (struct pbr64 *)p_pbr;
-	if (!p_bpb->bsx.num_fats) {
+	if (p_bpb->bsx.num_fats  != 1) {
 		exfat_msg(sb, KERN_ERR, "bogus number of FAT structure");

Could you please update error message for the reason why num_fats is allowed only 1?

fs/exfat/super.c static int __exfat_fill_super(struct sup · line 456

Quoted 2 lines
fs/exfat/super.c +0 -0
 		ret = -EINVAL;
 		goto free_bh;

Let's remove exfat_mirror_bh(), FAT2_start_sector variable and the below related codes together.

sbi->FAT2_start_sector = p_bpb->bsx.num_fats == 1 ?

                sbi->FAT1_start_sector :
                        sbi->FAT1_start_sector + sbi->num_FAT_sectors;

Thanks for your patch!

Quoted 4 lines
#2 lore raw
Quoted 2 lines · Namjae Jeon

Could you please update error message for the reason why num_fats is allowed only 1?

Sure.. No problem..

Quoted 8 lines

fs/exfat/super.c static int __exfat_fill_super(struct sup · line 456

Quoted 2 lines
fs/exfat/super.c +0 -0
 		ret = -EINVAL;
 		goto free_bh;

Let's remove exfat_mirror_bh(), FAT2_start_sector variable and the below related codes together.

sbi->FAT2_start_sector = p_bpb->bsx.num_fats == 1 ?

                sbi->FAT1_start_sector :
                        sbi->FAT1_start_sector + sbi->num_FAT_sectors;

You might want to hold off on that part for a bit - I've asked Sasha Levin for input on what exactly Windows does with this, and Pali has a not-obviously-wrong suggestion on using the second FAT table. The code tracking FAT2_start_sector looks OK - what would be missing is doing a similar versioning on the FAT the rest of the code references.

We may end up heaving that code over the side in the end, but let's make sure we're doing it with more information in hand....