summaryrefslogtreecommitdiffstats
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
parentaa20b6af7a860bc40662e141c12fec098048b8c0 (diff)
downloadrockbox-7249fab.tar.gz
rockbox-7249fab.tar.bz2
rockbox-7249fab.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
-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
clusters, or 0xffffffff for no hint */
};
/* fsinfo offsets */
+#define FSINFO_SIGNATURE 0
#define FSINFO_FREECOUNT 488
#define FSINFO_NEXTFREE 492
+#define FSINFO_SIGNATURE_VAL 0x41615252
+
#ifdef HAVE_FAT16SUPPORT
#define BPB_FN_SET16(bpb, fn) (bpb)->fn##__ = fn##16
#define BPB_FN_SET32(bpb, fn) (bpb)->fn##__ = fn##32
@@ -1251,6 +1254,14 @@ static int fat_mount_internal(struct bpb *fat_bpb)
FAT_ERROR(rc * 10 - 8);
}
+ /* Sanity check FS info */
+ long info = BYTES2INT32(buf, FSINFO_SIGNATURE);
+ if (info != FSINFO_SIGNATURE_VAL) {
+ DEBUGF("%S() FSInfo signature mismatch (%x)\n",
+ __func__, info);
+ FAT_ERROR(-9);
+ }
+
fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
fat_bpb->fsinfo.nextfree = BYTES2INT32(buf, FSINFO_NEXTFREE);
}