fsck: prevent overflows from invalid clu_count and vol_length
PATCH 1/1 fsck: prevent overflows from invalid clu_count and vol_length
From: David Anderson <[email protected]>
Malformed exFAT boot-sector values can cause arithmetic overflows in read_boot_region(), resulting in an out-of-bounds read.
Validate vol_length, clu_offset, and clu_count before using them in cluster-count calculations. Also perform DIV_ROUND_UP arithmetic using uint64_t to prevent intermediate overflow.
This issue is tracked as CVE-2026-45531.
--- fsck/fsck.c | 20 ++++++++++++++++++-- include/libexfat.h | 2 +- tests/clu_count_overflow/exfat.img.tar.xz | Bin 0 -> 3636 bytes 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/clu_count_overflow/exfat.img.tar.xz
fsck/fsck.c +18 -2
@@ -447,8 +447,7 @@ static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, goto err; } -if (le64_to_cpu (bs->bsx.vol_length) *EXFAT_SECTOR_SIZE (bs) > - bd->size) { +if (le64_to_cpu (bs->bsx.vol_length) > (bd->size >> bs->bsx.sect_size_bits)) {if (verbose) exfat_err("too large sector count: %" PRIu64 ", expected: %llu\n", le64_to_cpu(bs->bsx.vol_length),
@@ -456,6 +455,23 @@ static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, goto err; } +/* Prevent underflow when subtracting clu_offset from vol_length */ +if (le32_to_cpu (bs->bsx.clu_offset) >=le64_to_cpu (bs->bsx.vol_length)) { +if (verbose) +exfat_err ("cluster offset %u exceeds volume length %" PRIu64"\n" , +le32_to_cpu (bs->bsx.clu_offset), +le64_to_cpu (bs->bsx.vol_length)); + goto err; + } + +/* Cap clu_count to the spec limit to prevent overflow */ +if (le32_to_cpu (bs->bsx.clu_count) >EXFAT_MAX_NUM_CLUSTER ) { +if (verbose) +exfat_err ("too large cluster count: %u, max allowed: %u\n" , +le32_to_cpu (bs->bsx.clu_count),EXFAT_MAX_NUM_CLUSTER ); + goto err; + } + clu_max_count = (le64_to_cpu (bs->bsx.vol_length) -le32_to_cpu (bs->bsx.clu_offset)) >> bs->bsx.sect_per_clus_bits;if (le32_to_cpu (bs->bsx.clu_count) > clu_max_count) {
include/libexfat.h +1 -1
@@ -24,7 +24,7 @@ typedef __u32 clus_t;#define MIN (a, b) ((a) < (b) ? (a) : (b))#define MAX (a, b) ((a) > (b) ? (a) : (b)) -#define DIV_ROUND_UP (__i, __d) (((__i) + (__d) - 1) / (__d)) +#define DIV_ROUND_UP (__i, __d) (((uint64_t)(__i) + (__d) - 1) / (__d))#define EXFAT_MIN_NUM_SEC_VOL (2048)#define EXFAT_MAX_NUM_SEC_VOL ((2 << 64) - 1)
tests/clu_count_overflow/exfat.img.tar.xz new file binary +0 -0
base-commit: 2399fbe848f57aff15ef3a7db4bf852e0de0d0e9
Signature · 1 line
2.34.1
Hi Yang,
2026년 10월 4일 (일) 오후 11:35, Yang Wen <[email protected]>님이 작성:
Quoted 26 lines
From: David Anderson <[email protected]>
Malformed exFAT boot-sector values can cause arithmetic overflows in
read_boot_region(), resulting in an out-of-bounds read.Validate
vol_length,clu_offset, andclu_countbefore using them in cluster-count calculations. Also performDIV_ROUND_UParithmetic usinguint64_tto prevent intermediate overflow.This issue is tracked as CVE-2026-45531.
Signed-off-by Yang Wen <[email protected]>--- fsck/fsck.c | 20 ++++++++++++++++++-- include/libexfat.h | 2 +- tests/clu_count_overflow/exfat.img.tar.xz | Bin 0 -> 3636 bytes 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/clu_count_overflow/exfat.img.tar.xzfsck/fsck.c +0
-0
fsck/fsck.c static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, · line 450
Quoted 6 lines
fsck/fsck.c +1
-2@@ -447,8 +447,7 @@ static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, goto err; } -if (le64_to_cpu (bs->bsx.vol_length) *EXFAT_SECTOR_SIZE (bs) > - bd->size) { +if (le64_to_cpu (bs->bsx.vol_length) > (bd->size >> bs->bsx.sect_size_bits)) {
Could we verify sect_size_bit also?
Quoted 32 lines · Hyunchul Lee
Hi Yang,
2026년 10월 4일 (일) 오후 11:35, Yang Wen <[email protected]>님이 작성:
Quoted 29 lines
From: David Anderson <[email protected]>
Malformed exFAT boot-sector values can cause arithmetic overflows in
read_boot_region(), resulting in an out-of-bounds read.Validate
vol_length,clu_offset, andclu_countbefore using them in cluster-count calculations. Also performDIV_ROUND_UParithmetic usinguint64_tto prevent intermediate overflow.This issue is tracked as CVE-2026-45531.
Signed-off-by Yang Wen <[email protected]>--- fsck/fsck.c | 20 ++++++++++++++++++-- include/libexfat.h | 2 +- tests/clu_count_overflow/exfat.img.tar.xz | Bin 0 -> 3636 bytes 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/clu_count_overflow/exfat.img.tar.xzfsck/fsck.c +0
-0@@ -447,8 +447,7 @@ static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, goto err; }
Quoted 5 lines
fsck/fsck.c static int read_boot_region(struct exfat_blk_dev *bd, struct pbr **pbr, · line 450
Quoted 3 lines
fsck/fsck.c +1
-2-if (le64_to_cpu (bs->bsx.vol_length) *EXFAT_SECTOR_SIZE (bs) > - bd->size) { +if (le64_to_cpu (bs->bsx.vol_length) > (bd->size >> bs->bsx.sect_size_bits)) {Could we verify
sect_size_bitalso?
Yes, good point.
This patch was taken from the official Android exfatprogs tree and was authored by David Anderson. We found it while reviewing recent Android CVE fixes and wanted to sync it upstream, so I would prefer to preserve the original patch and its authorship.
The sect_size_bits validation is also a pre-existing issue, since the current code performs shifts before validating the value. I can submit a separate preparatory patch for that fix, authored and signed off by me, followed by David's original patch as the second patch in the series.
Thanks.
Quoted 4 lines · Yang Wen
This patch was taken from the official Android exfatprogs tree and was authored by David Anderson. We found it while reviewing recent Android CVE fixes and wanted to sync it upstream, so I would prefer to preserve the original patch and its authorship.
I wonder why they decided to silently patch Android without notifying the upstream maintainers? Not very kind of them.
Davo