jfs: Fix shift-out-of-bounds in dbDiscardAG
PATCH 1/1 jfs: Fix shift-out-of-bounds in dbDiscardAG
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 [email protected]
Signed-off-by Pei Li <[email protected]>
---
Syzbot reported the following error:
UBSAN: shift-out-of-bounds in fs/jfs/jfs_dmap.c:1629:18
shift exponent -1 is negative
If BLKSTOL2() returned 0, the shift exponent will be -1.
The solution is to check the exponent and if it is smaller than 0, exit the loop directly.
--- fs/jfs/jfs_dmap.c | 2 ++ 1 file changed, 2 insertions(+)
fs/jfs/jfs_dmap.c +2 -0
@@ -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 */
---
base-commit: 2ccbdf43d5e758f8493a95252073cf9078a5fea5
change-id: 20240625-bug0-11e890f449af
Best regards,
Signature · 1 line
Pei Li <[email protected]>