Re: [PATCH] bcachefs: fix divide by zero error in util.c

From: Kent Overstreet
Date: Sun Sep 22 2024 - 21:26:49 EST


On Sun, Sep 22, 2024 at 07:33:44PM GMT, Dennis Lam wrote:
> This patch aims to fix a bug found by syzbot where a crash occurs due to
> a divide by zero error in the bcachefs subsystem [1].
>
> Bcachefs has a file called util.c that uses the function div_u64 to perform
> division using 64-bit values. The function's parameters uses a 64-bit dividend
> and a 32-bit divisor to perform its division, however sometimes in this file
> a 64-bit divisor is passed using this function. When in use, the 64-bit value
> is passed as a 32-bit value, creating the possibility of a division by zero error.
>
> Therefore, this fix replaces the function div_u64 with div64_u64 where the
> dividend and divisor is a 64-bit value to perform the correct division.
>
> [1] https://syzkaller.appspot.com/bug?extid=24beef64217854da05a4
>
> Reported-and-tested-by: syzbot+24beef64217854da05a4@xxxxxxxxxxxxxxxxxxxxxxxxx
> Signed-off-by: Dennis Lam <dennis.lamerice@xxxxxxxxx>

We already have this, from Reed Riley

27663d7784b5 bcachefs: Replace div_u64 with div64_u64 where second param is u64