[PATCH 1/2] erofs-utils: fix undefined behavior shift in erofs_init_devices
Nithurshen
nithurshen.dev at gmail.com
Sun Apr 19 23:16:03 AEST 2026
In erofs_init_devices(), roundup_pow_of_two() can potentially trigger
an undefined behavior shift if the incremented 'ondisk_extradevs'
value results in an overflow or an input that leads to an
out-of-bounds shift.
Promote the argument to u64 before the increment to ensure the
rounding logic operates on a safe bit-width.
Signed-off-by: Nithurshen <nithurshen.dev at gmail.com>
---
lib/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/super.c b/lib/super.c
index 088c9a0..10831a7 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -49,7 +49,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
return 0;
sbi->extra_devices = ondisk_extradevs;
- sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
+ sbi->device_id_mask = roundup_pow_of_two((u64)ondisk_extradevs + 1) - 1;
sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs));
if (!sbi->devs)
return -ENOMEM;
--
2.52.0
More information about the Linux-erofs
mailing list