Skip to contentSkip to conversation

fs/ntfs3: Avoid UBSAN error on true_sectors_per_clst()

PATCH Applied Shigeru Yoshida 2 participants 3 messages Aug 23, 2022 – Sep 30, 2022 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: Avoid UBSAN error on true_sectors_per_clst()

syzbot reported UBSAN error as below:

[   76.901829][ T6677] ================================================================================
[   76.903908][ T6677] UBSAN: shift-out-of-bounds in fs/ntfs3/super.c:675:13
[   76.905363][ T6677] shift exponent -247 is negative

This patch avoid this error.

Fixes a3b774342fa7 (fs/ntfs3: validate BOOT sectors_per_clusters)
Cc Author: Randy Dunlap <[email protected]>
Reported-by [email protected]
---
 fs/ntfs3/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/super.c +1 -1
index 47012c9bf505..adc4f73722b7 100644
@@ -672,7 +672,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
 	if (boot->sectors_per_clusters <= 0x80)
 		return boot->sectors_per_clusters;
 	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
-		return 1U << (0 - boot->sectors_per_clusters);
+		return 1U << -(s8)boot->sectors_per_clusters;
 	return -EINVAL;
 }
 
Signature · 1 line
2.37.2
#1 lore raw

ping?

Quoted 33 lines · Shigeru Yoshida

syzbot reported UBSAN error as below:

[   76.901829][ T6677] ================================================================================
[   76.903908][ T6677] UBSAN: shift-out-of-bounds in fs/ntfs3/super.c:675:13
[   76.905363][ T6677] shift exponent -247 is negative

This patch avoid this error.

Fixes a3b774342fa7 (fs/ntfs3: validate BOOT sectors_per_clusters)
Cc Author: Randy Dunlap <[email protected]>
Reported-by [email protected]
---
 fs/ntfs3/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/super.c +1 -1
index 47012c9bf505..adc4f73722b7 100644
@@ -672,7 +672,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
 	if (boot->sectors_per_clusters <= 0x80)
 		return boot->sectors_per_clusters;
 	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
-		return 1U << (0 - boot->sectors_per_clusters);
+		return 1U << -(s8)boot->sectors_per_clusters;
 	return -EINVAL;
 }
 
Signature · 1 line
2.37.2
maintainer Applied
#2 lore raw
In reply to Shigeru Yoshida
Quoted 22 lines · Shigeru Yoshida

syzbot reported UBSAN error as below:

[   76.901829][ T6677] ================================================================================
[   76.903908][ T6677] UBSAN: shift-out-of-bounds in fs/ntfs3/super.c:675:13
[   76.905363][ T6677] shift exponent -247 is negative

This patch avoid this error.

Fixes a3b774342fa7 (fs/ntfs3: validate BOOT sectors_per_clusters)
Cc Author: Randy Dunlap <[email protected]>
Reported-by [email protected]
---
  fs/ntfs3/super.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/super.c +0 -0
index 47012c9bf505..adc4f73722b7 100644

fs/ntfs3/super.c static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot) · line 678

Quoted 8 lines
fs/ntfs3/super.c +1 -1
@@ -672,7 +672,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
  	if (boot->sectors_per_clusters <= 0x80)
  		return boot->sectors_per_clusters;
  	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
-		return 1U << (0 - boot->sectors_per_clusters);
+		return 1U << -(s8)boot->sectors_per_clusters;
  	return -EINVAL;
  }
 

Applied, thanks again for the patch!