Re: [syzbot] [PATCH v3] jfs: UBSAN: shift-out-of-bounds in dbFindBits

From: syzbot
Date: Fri Oct 25 2024 - 12:30:35 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.

***

Subject: [PATCH v3] jfs: UBSAN: shift-out-of-bounds in dbFindBits
Author: zoo868e@xxxxxxxxx

The starting bit number of free bits should not be >= 32 as it is
0-indexed.Assert that the number of bits is < 32, or if it is 32, the
input word must be 0.

#syz test

Reported-by: syzbot+9e90a1c5eedb9dc4c6cc@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Matt Jan <zoo868e@xxxxxxxxx>
---
Changes in v3: return the result earlier instead of assert
Changes in v2: Test if the patch resolve the issue through syzbot and
reference the reporter.

fs/jfs/jfs_dmap.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 974ecf5e0d95..346f2617b744 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -3017,6 +3017,9 @@ static int dbFindBits(u32 word, int l2nb)
nb = 1 << l2nb;
assert(nb <= DBWORD);

+ if (nb == DBWORD)
+ return (!!word) << BUDMIN;
+
/* complement the word so we can use a mask (i.e. 0s represent
* free bits) and compute the mask.
*/
--
2.25.1