libexfat: restore the original DIV_ROUND_UP type
Subsystems (2)
PATCH 1/1 libexfat: restore the original DIV_ROUND_UP type
Casting the first argument of DIV_ROUND_UP() to uint64_t changes the result type for every caller and causes a signedness warning in fsck.
The malformed boot-sector arithmetic is protected by the validation added in the same commit, so restore the original type-preserving macro.
--- include/libexfat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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) (((uint64_t)(__i) + (__d) - 1) / (__d)) +#define DIV_ROUND_UP (__i, __d) (((__i) + (__d) - 1) / (__d))#define EXFAT_MIN_NUM_SEC_VOL (2048)#define EXFAT_MAX_NUM_SEC_VOL ((2 << 64) - 1)
Signature · 1 line
2.34.1
Namjae Jeon
maintainerQuoted 9 lines · Yang Wen
Casting the first argument of
DIV_ROUND_UP()touint64_tchanges the result type for every caller and causes a signedness warning in fsck.The malformed boot-sector arithmetic is protected by the validation added in the same commit, so restore the original type-preserving macro.
Fixes 69a8482f3492 ("fsck: prevent overflows from invalid clu_count and vol_length")Signed-off-by Yang Wen <[email protected]>
I will apply an attached patch instead of this patch. Can you check it? Thanks!
From 85fb58f6699b82821d3b7db2a0d9afffb4820116 Mon Sep 17 00:00:00 2001
From: Yang Wen <[email protected]>
Date: Sat, 24 Oct 2026 21:43:42 +0800
Subject: [PATCH] libexfat: avoid DIV_ROUND_UP overflow
Casting the first argument of DIV_ROUND_UP() to uint64_t makes every call return uint64_t and causes a signedness warning in fsck. Removing the cast alone can overflow for 32-bit values.
Use division and remainder to round up without an overflowing addition. This keeps the result type expected by each caller. Also check clu_count in read_boot_sect(), used by exfat2img and defrag. The check in fsck's read_boot_region() does not cover those programs.
--- include/libexfat.h | 2 +- lib/libexfat.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
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) (((uint64_t)(__i) + (__d) - 1) / (__d)) +#define DIV_ROUND_UP (__i, __d) ((__i) / (__d) + ((__i) % (__d) != 0))#define EXFAT_MIN_NUM_SEC_VOL (2048)#define EXFAT_MAX_NUM_SEC_VOL ((2 << 64) - 1)
lib/libexfat.c +6 -0
@@ -1959,6 +1959,12 @@ int read_boot_sect(struct exfat_blk_dev *bdev, struct pbr **bs) goto err; } +if (le32_to_cpu (pbr->bsx.clu_count) >EXFAT_MAX_NUM_CLUSTER ) { +exfat_err ("too large cluster count: %u, max allowed: %u\n" , +le32_to_cpu (pbr->bsx.clu_count),EXFAT_MAX_NUM_CLUSTER ); + goto err; + } + sect_size =1 << pbr->bsx.sect_size_bits; clu_size =1 << (pbr->bsx.sect_size_bits + pbr->bsx.sect_per_clus_bits);
Signature · 1 line
2.34.1
Quoted 11 lines · Namjae Jeon
Quoted 8 lines · Yang Wen
Casting the first argument of
DIV_ROUND_UP()touint64_tchanges the result type for every caller and causes a signedness warning in fsck.The malformed boot-sector arithmetic is protected by the validation added in the same commit, so restore the original type-preserving macro.
Fixes 69a8482f3492 ("fsck: prevent overflows from invalid clu_count and vol_length")Signed-off-by Yang Wen <[email protected]>I will apply an attached patch instead of this patch. Can you check it? Thanks!
Hi, all.
Github recently bumped the "ubuntu-latest" runner to 26.04. The CI isn't working at the moment because of some missing packages. I'm working on it because I also have some patches to send through.
Davo
Namjae Jeon
maintainerQuoted 6 lines · David Timber
Quoted 4 lines · Namjae Jeon
Quoted 3 lines · Yang Wen
Casting the first argument of
DIV_ROUND_UP()touint64_tchanges the result type for every caller and causes a signedness warning in fsck.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
The malformed boot-sector arithmetic is protected by the validation added in the same commit, so restore the original type-preserving macro.
Fixes 69a8482f3492 ("fsck: prevent overflows from invalid clu_count and vol_length")Signed-off-by Yang Wen <[email protected]>I will apply an attached patch instead of this patch. Can you check it? Thanks!
Hi, all.
Hi David,
Quoted 4 lines
Github recently bumped the "ubuntu-latest" runner to 26.04. The CI isn't working at the moment because of some missing packages. I'm working on it because I also have some patches to send through.
Okay, Really thanks for the work!
Quoted 2 lines
Davo