* [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits
@ 2024-07-10 0:12 Remington Brasga
2024-08-23 18:16 ` Dave Kleikamp
0 siblings, 1 reply; 3+ messages in thread
From: Remington Brasga @ 2024-07-10 0:12 UTC (permalink / raw)
To: Dave Kleikamp, Manas Ghandat, Juntong Deng, Andrew Kanner,
Osama Muhammad, Shuah Khan
Cc: jfs-discussion, linux-kernel, linux-kernel-mentees,
syzbot+e38d703eeb410b17b473, Remington Brasga
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits
2024-07-10 0:12 [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits Remington Brasga
@ 2024-08-23 18:16 ` Dave Kleikamp
0 siblings, 0 replies; 3+ messages in thread
From: Dave Kleikamp @ 2024-08-23 18:16 UTC (permalink / raw)
To: Remington Brasga, Manas Ghandat, Juntong Deng, Andrew Kanner,
Osama Muhammad, Shuah Khan
Cc: jfs-discussion, linux-kernel, linux-kernel-mentees,
syzbot+e38d703eeb410b17b473
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;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits
@ 2024-10-25 14:58 Matt Jan
0 siblings, 0 replies; 3+ messages in thread
From: Matt Jan @ 2024-10-25 14:58 UTC (permalink / raw)
To: Dave Kleikamp, jfs-discussion, linux-kernel, Shuah Khan; +Cc: Matt Jan
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.
Signed-off-by: Matt Jan <zoo868e@gmail.com>
---
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 974ecf5e0d95..b9eccf8900eb 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -3015,7 +3015,7 @@ static int dbFindBits(u32 word, int l2nb)
/* get the number of bits.
*/
nb = 1 << l2nb;
- assert(nb <= DBWORD);
+ assert(nb < DBWORD || (nb == DBWORD && !word));
/* complement the word so we can use a mask (i.e. 0s represent
* free bits) and compute the mask.
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-25 14:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-10 0:12 [PATCH] jfs: UBSAN: shift-out-of-bounds in dbFindBits Remington Brasga
2024-08-23 18:16 ` Dave Kleikamp
2024-10-25 14:58 Matt Jan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®