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

Remington Brasga posted 1 patch 1 year, 5 months ago
There is a newer version of this series
fs/jfs/jfs_dmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits
Posted by Remington Brasga 1 year, 5 months ago
Fix issue with UBSAN throwing shift-out-of-bounds warning.

Reported-by: syzbot+e38d703eeb410b17b473@syzkaller.appspotmail.com
Signed-off-by: Remington Brasga <rbrasga@uci.edu>
---
When nb = 32, `mask = mask >> nb` or shorthand `mask >>= nb` throws
shift-out-of-bounds warning.
`mask = (mask >> nb)` removes that warning. 

Link to the syzbot bug report: https://lore.kernel.org/all/0000000000006fc563061cbc7f9c@google.com/T/

 fs/jfs/jfs_dmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index cb3cda1390ad..636aae946e84 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -3020,7 +3020,7 @@ static int dbFindBits(u32 word, int l2nb)
 
 	/* scan the word for nb free bits at nb alignments.
 	 */
-	for (bitno = 0; mask != 0; bitno += nb, mask >>= nb) {
+	for (bitno = 0; mask != 0; bitno += nb, mask = (mask >> nb)) {
 		if ((mask & word) == mask)
 			break;
 	}
-- 
2.34.1
Re: [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits
Posted by Dave Kleikamp 1 year, 3 months ago
On 7/9/24 7:12PM, Remington Brasga wrote:
> Fix issue with UBSAN throwing shift-out-of-bounds warning.
> 
> Reported-by: syzbot+e38d703eeb410b17b473@syzkaller.appspotmail.com
> Signed-off-by: Remington Brasga <rbrasga@uci.edu>
> ---
> When nb = 32, `mask = mask >> nb` or shorthand `mask >>= nb` throws
> shift-out-of-bounds warning.
> `mask = (mask >> nb)` removes that warning.

Looks good. Applied.

Shaggy

> 
> Link to the syzbot bug report: https://lore.kernel.org/all/0000000000006fc563061cbc7f9c@google.com/T/
> 
>   fs/jfs/jfs_dmap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
> index cb3cda1390ad..636aae946e84 100644
> --- a/fs/jfs/jfs_dmap.c
> +++ b/fs/jfs/jfs_dmap.c
> @@ -3020,7 +3020,7 @@ static int dbFindBits(u32 word, int l2nb)
>   
>   	/* scan the word for nb free bits at nb alignments.
>   	 */
> -	for (bitno = 0; mask != 0; bitno += nb, mask >>= nb) {
> +	for (bitno = 0; mask != 0; bitno += nb, mask = (mask >> nb)) {
>   		if ((mask & word) == mask)
>   			break;
>   	}