Skip to contentSkip to conversation

bcachefs: Fix UAF in __promote_alloc() error path

PATCH New Kent Overstreet 1 participant 1 message Nov 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: Fix UAF in __promote_alloc() error path

If we error in data_update_init() after adding to the rhashtable of outstanding promotes, kfree_rcu() is required.

---
 fs/bcachefs/io_read.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/bcachefs/io_read.c +2 -1
index ac6a6fcc2bb8..b3b934a87c6d 100644
@@ -262,7 +262,8 @@ static struct promote_op *__promote_alloc(struct btree_trans *trans,
 		bio_free_pages(&(*rbio)->bio);
 	kfree(*rbio);
 	*rbio = NULL;
-	kfree(op);
+	/* We may have added to the rhashtable and thus need rcu freeing: */
+	kfree_rcu(op, rcu);
 	bch2_write_ref_put(c, BCH_WRITE_REF_promote);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.45.2