summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-07-11 16:22:21 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-07-11 18:23:46 -0400
commit7249fabe63b6106225c11c401fdc17cd4b03ad5e (patch)
tree4d30a09ee2813d3f5703f26dc9cb676c4f002536 /firmware/drivers
parentaa20b6af7a860bc40662e141c12fec098048b8c0 (diff)
downloadrockbox-7249fabe63b6106225c11c401fdc17cd4b03ad5e.tar.gz
rockbox-7249fabe63b6106225c11c401fdc17cd4b03ad5e.zip
fat: Validate FS Info Sector signature when attempting to mount volume
The "try to mount as superfloppy" fails with some partitioning layouts because sector 0 can have a mostly-valid FAT32 signature. However, in all dumps I've looked at, sector 0's fsinfo offset value points at a place which lacks the fsinfo signature. Resolves FS#13213, no known regressions. Change-Id: Ib323d35cca6ca54e11aca6ba77041bf33a05a277
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index b14e461a65..cc6dbf517c 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -178,9 +178,12 @@ struct fsinfo
178 clusters, or 0xffffffff for no hint */ 178 clusters, or 0xffffffff for no hint */
179}; 179};
180/* fsinfo offsets */ 180/* fsinfo offsets */
181#define FSINFO_SIGNATURE 0
181#define FSINFO_FREECOUNT 488 182#define FSINFO_FREECOUNT 488
182#define FSINFO_NEXTFREE 492 183#define FSINFO_NEXTFREE 492
183 184
185#define FSINFO_SIGNATURE_VAL 0x41615252
186
184#ifdef HAVE_FAT16SUPPORT 187#ifdef HAVE_FAT16SUPPORT
185#define BPB_FN_SET16(bpb, fn) (bpb)->fn##__ = fn##16 188#define BPB_FN_SET16(bpb, fn) (bpb)->fn##__ = fn##16
186#define BPB_FN_SET32(bpb, fn) (bpb)->fn##__ = fn##32 189#define BPB_FN_SET32(bpb, fn) (bpb)->fn##__ = fn##32
@@ -1251,6 +1254,14 @@ static int fat_mount_internal(struct bpb *fat_bpb)
1251 FAT_ERROR(rc * 10 - 8); 1254 FAT_ERROR(rc * 10 - 8);
1252 } 1255 }
1253 1256
1257 /* Sanity check FS info */
1258 long info = BYTES2INT32(buf, FSINFO_SIGNATURE);
1259 if (info != FSINFO_SIGNATURE_VAL) {
1260 DEBUGF("%S() FSInfo signature mismatch (%x)\n",
1261 __func__, info);
1262 FAT_ERROR(-9);
1263 }
1264
1254 fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT); 1265 fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
1255 fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE); 1266 fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE);
1256 } 1267 }