Skip to contentSkip to conversation

bcachefs: fix null-ptr-deref in have_stripes()

PATCH In review Jeongjun Park 3 participants 4 messages Oct 25, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bcachefs: fix null-ptr-deref in have_stripes()

c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference occurs, so you need to add code to check the variable.

Reported-by [email protected]
Fixes 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
---
 fs/bcachefs/sb-downgrade.c | 3 +++
 1 file changed, 3 insertions(+)
fs/bcachefs/sb-downgrade.c +3 -0
index ae715ff658e8..8767c33c2b51 100644
@@ -143,6 +143,9 @@ UPGRADE_TABLE()
 
 static int have_stripes(struct bch_fs *c)
 {
+	if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
+		return 0;
+
 	return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
 }
 

--

#1 lore raw
Quoted 6 lines · Jeongjun Park

c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference occurs, so you need to add code to check the variable.

Reported-by [email protected]
Fixes 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")

This looks identical to the v1? It's already in my testing branch

(But it should be in my hotfix branch, doing that now)

Quoted 19 lines
---
 fs/bcachefs/sb-downgrade.c | 3 +++
 1 file changed, 3 insertions(+)
fs/bcachefs/sb-downgrade.c +3 -1
index ae715ff658e8..8767c33c2b51 100644
@@ -143,6 +143,9 @@ UPGRADE_TABLE()
 
 static int have_stripes(struct bch_fs *c)
 {
+	if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
+		return 0;
+
 	return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
 }
 
--
#2 lore raw
Quoted 10 lines · Kent Overstreet
Quoted 6 lines · Jeongjun Park

c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference occurs, so you need to add code to check the variable.

Reported-by [email protected]
Fixes 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")

This looks identical to the v1? It's already in my testing branch

This version fix the “Fixes" tag, the original one is:

"Fixes: ("bcachefs: metadata version bucket_stripe_sectors”)"

Quoted 23 lines

(But it should be in my hotfix branch, doing that now)

Quoted 19 lines

---
fs/bcachefs/sb-downgrade.c | 3 +++

1 file changed, 3 insertions(+)
fs/bcachefs/sb-downgrade.c +3 -1
index ae715ff658e8..8767c33c2b51 100644
@@ -143,6 +143,9 @@ UPGRADE_TABLE()
 
 static int have_stripes(struct bch_fs *c)
 {
+ if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
+ return 0;
+
 return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
 }
 
--
#3 lore raw
Quoted 10 lines · Alan Huang
Quoted 9 lines · Kent Overstreet
Quoted 6 lines · Jeongjun Park

c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference occurs, so you need to add code to check the variable.

Reported-by [email protected]
Fixes 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
Quoted 5 lines
Quoted 1 line

This looks identical to the v1? It's already in my testing branch

This version fix the “Fixes" tag, the original one is:

"Fixes: ("bcachefs: metadata version bucket_stripe_sectors”)"

thanks