Skip to contentSkip to conversation

jfs: UBSAN: shift-out-of-bounds in dbFindBits

PATCH In review Remington Brasga 2 participants 2 messages Jul 10, 2024 – Aug 23, 2024 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: UBSAN: shift-out-of-bounds in dbFindBits

Fix issue with UBSAN throwing shift-out-of-bounds warning.

---
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/[email protected]/T/

 fs/jfs/jfs_dmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
index cb3cda1390ad..636aae946e84 100644
@@ -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;
 	}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Remington Brasga

Fix issue with UBSAN throwing shift-out-of-bounds warning.

---
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

Quoted 19 lines

Link to the syzbot bug report: https://lore.kernel.org/all/[email protected]/T/

  fs/jfs/jfs_dmap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
index cb3cda1390ad..636aae946e84 100644
@@ -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;
  	}