Skip to contentSkip to conversation

bcachefs: Fix pool->alloc NULL pointer dereference

PATCH Superseded Alan Huang 2 participants 2 messages Jun 14, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alan Huang

author
#0 lore raw

PATCH 1/1 bcachefs: Fix pool->alloc NULL pointer dereference

btree_interior_update_pool has not been initialized before the filesystem becomes read-write, thus mempool_alloc in bch2_btree_update_start will trigger pool->alloc NULL pointer dereference in mempool_alloc_noprof

---
 fs/bcachefs/chardev.c | 3 +++
 1 file changed, 3 insertions(+)
fs/bcachefs/chardev.c +3 -0
index fde3c2380e28..ec8d0719a543 100644
@@ -378,6 +378,9 @@ static long bch2_ioctl_data(struct bch_fs *c,
 	struct bch_data_ctx *ctx;
 	int ret;
 
+	if (!test_bit(BCH_FS_rw, &c->flags))
+		return -EINVAL;
+
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
Signature · 1 line
2.48.1
#1 lore raw
Quoted 15 lines · Alan Huang

btree_interior_update_pool has not been initialized before the filesystem becomes read-write, thus mempool_alloc in bch2_btree_update_start will trigger pool->alloc NULL pointer dereference in mempool_alloc_noprof

---
 fs/bcachefs/chardev.c | 3 +++
 1 file changed, 3 insertions(+)
fs/bcachefs/chardev.c +0 -0
index fde3c2380e28..ec8d0719a543 100644

fs/bcachefs/chardev.c static long bch2_ioctl_data(struct bch_fs *c, · line 383

Quoted 6 lines
fs/bcachefs/chardev.c +3 -0
@@ -378,6 +378,9 @@ static long bch2_ioctl_data(struct bch_fs *c,
 	struct bch_data_ctx *ctx;
 	int ret;
 
+	if (!test_bit(BCH_FS_rw, &c->flags))
+		return -EINVAL;
+

this isn't the right fix - we need to do a tryget and take a ref on c->writes

Quoted 6 lines
fs/bcachefs/chardev.c +0 -0
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
Signature · 1 line
2.48.1