Skip to contentSkip to conversation

btrfs-progs: Fix null pointer deref in balance_level

PATCH In review Nikolay Borisov 3 participants 3 messages Apr 6, 2021 – Apr 16, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: Fix null pointer deref in balance_level

In case the right buffer is emptied it's first set to null and subsequently it's dereferenced to get its size to pass to root_sub_used. This naturally leads to a null pointer dereference. The correct thing to do is to pass the stashed right->len in "blocksize".

Fixes #296

---
 kernel-shared/ctree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shared/ctree.c +1 -1
index 4cc3aebc1412..3a82286cc914 100644
@@ -927,7 +927,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
 			if (wret)
 				ret = wret;
 
-			root_sub_used(root, right->len);
+			root_sub_used(root, blocksize);
 			wret = btrfs_free_extent(trans, root, bytenr,
 						 blocksize, 0,
 						 root->root_key.objectid,
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Nikolay Borisov

In case the right buffer is emptied it's first set to null and subsequently it's dereferenced to get its size to pass to root_sub_used. This naturally leads to a null pointer dereference. The correct thing to do is to pass the stashed right->len in "blocksize".

Fixes #296

Thanks,

Josef

#2 lore raw
In reply to Nikolay Borisov
Quoted 6 lines · Nikolay Borisov

In case the right buffer is emptied it's first set to null and subsequently it's dereferenced to get its size to pass to root_sub_used. This naturally leads to a null pointer dereference. The correct thing to do is to pass the stashed right->len in "blocksize".

Fixes #296

I'm using the "Issue: #123" format for that.

Quoted 1 line

Added to devel, thanks.