]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
exfat: fix divide-by-zero in exfat_allocate_bitmap
authorNamjae Jeon <linkinjeon@kernel.org>
Tue, 18 Nov 2025 02:10:26 +0000 (11:10 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Dec 2025 13:03:31 +0000 (14:03 +0100)
[ Upstream commit d70a5804c563b5e34825353ba9927509df709651 ]

The variable max_ra_count can be 0 in exfat_allocate_bitmap(),
which causes a divide-by-zero error in the subsequent modulo operation
(i % max_ra_count), leading to a system crash.
When max_ra_count is 0, it means that readahead is not used. This patch
load the bitmap without readahead.

Fixes: 9fd688678dd8 ("exfat: optimize allocation bitmap loading time")
Reported-by: Jiaming Zhang <r772577952@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/exfat/balloc.c

index 2d2d510f2372cbccbf45574a8fc9b6bb30e4713d..0b6466b3490a063eb77f834b9334f069536946c0 100644 (file)
@@ -106,7 +106,7 @@ static int exfat_allocate_bitmap(struct super_block *sb,
                (PAGE_SHIFT - sb->s_blocksize_bits);
        for (i = 0; i < sbi->map_sectors; i++) {
                /* Trigger the next readahead in advance. */
-               if (0 == (i % max_ra_count)) {
+               if (max_ra_count && 0 == (i % max_ra_count)) {
                        blk_start_plug(&plug);
                        for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
                                sb_breadahead(sb, sector + j);