]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jfs: Fix shift-out-of-bounds in dbDiscardAG
authorPei Li <peili.dev@gmail.com>
Tue, 25 Jun 2024 16:42:05 +0000 (09:42 -0700)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Wed, 26 Jun 2024 17:57:32 +0000 (12:57 -0500)
When searching for the next smaller log2 block, BLKSTOL2() returned 0,
causing shift exponent -1 to be negative.

This patch fixes the issue by exiting the loop directly when negative
shift is found.

Reported-by: syzbot+61be3359d2ee3467e7e4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=61be3359d2ee3467e7e4
Signed-off-by: Pei Li <peili.dev@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/jfs/jfs_dmap.c

index cb3cda1390adb16e1ad8031783849ba59022db87..5713994328cbcbde653193a7250cbcc6ffc7e377 100644 (file)
@@ -1626,6 +1626,8 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
                } else if (rc == -ENOSPC) {
                        /* search for next smaller log2 block */
                        l2nb = BLKSTOL2(nblocks) - 1;
+                       if (unlikely(l2nb < 0))
+                               break;
                        nblocks = 1LL << l2nb;
                } else {
                        /* Trim any already allocated blocks */