Skip to contentSkip to conversation

btrfs: tree-checker: Fix bounds check in check_inode_extref()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: tree-checker: Fix bounds check in check_inode_extref()

The parentheses for the unlikely() annotation were put in the wrong place so it means that the condition is basically never true and the bounds checking is skipped.

Fixes aab9458b9f00 ("btrfs: tree-checker: add inode extref checks")
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index ca30b15ea452..c10b4c242acf 100644
@@ -1797,7 +1797,7 @@ static int check_inode_extref(struct extent_buffer *leaf,
 		struct btrfs_inode_extref *extref = (struct btrfs_inode_extref *)ptr;
 		u16 namelen;
 
-		if (unlikely(ptr + sizeof(*extref)) > end) {
+		if (unlikely(ptr + sizeof(*extref) > end)) {
 			inode_ref_err(leaf, slot,
 			"inode extref overflow, ptr %lu end %lu inode_extref size %zu",
 				      ptr, end, sizeof(*extref));
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

The parentheses for the unlikely() annotation were put in the wrong place so it means that the condition is basically never true and the bounds checking is skipped.

Fixes aab9458b9f00 ("btrfs: tree-checker: add inode extref checks")

Nice catch.

Thanks,
Qu

Quoted 17 lines
---
  fs/btrfs/tree-checker.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index ca30b15ea452..c10b4c242acf 100644
@@ -1797,7 +1797,7 @@ static int check_inode_extref(struct extent_buffer *leaf,
  		struct btrfs_inode_extref *extref = (struct btrfs_inode_extref *)ptr;
  		u16 namelen;
 
-		if (unlikely(ptr + sizeof(*extref)) > end) {
+		if (unlikely(ptr + sizeof(*extref) > end)) {
  			inode_ref_err(leaf, slot,
  			"inode extref overflow, ptr %lu end %lu inode_extref size %zu",
  				      ptr, end, sizeof(*extref));