]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: fix can_write_extent()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 14 May 2025 14:44:21 +0000 (10:44 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:58 +0000 (20:14 -0400)
Failing to check the return value of bch2_dev_rcu(): we could
(technically) race with device removal.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/data_update.c

index c39ea51e9e484cb3cd62fc62c03a29a6833fce43..de096ca65b4babf7749c8bbe1436bd7c533f9e0e 100644 (file)
@@ -744,7 +744,9 @@ static int can_write_extent(struct bch_fs *c, struct data_update *m)
        rcu_read_lock();
        unsigned nr_replicas = 0, i;
        for_each_set_bit(i, devs.d, BCH_SB_MEMBERS_MAX) {
-               struct bch_dev *ca = bch2_dev_rcu(c, i);
+               struct bch_dev *ca = bch2_dev_rcu_noerror(c, i);
+               if (!ca)
+                       continue;
 
                struct bch_dev_usage usage;
                bch2_dev_usage_read_fast(ca, &usage);