]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: slab-use-after-free Read in bch2_sb_errors_from_cpu
authorPei Li <peili.dev@gmail.com>
Tue, 25 Jun 2024 20:04:59 +0000 (13:04 -0700)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 25 Jun 2024 21:51:26 +0000 (17:51 -0400)
Acquire fsck_error_counts_lock before accessing the critical section
protected by this lock.

syzbot has tested the proposed patch and the reproducer did not trigger
any issue.

Reported-by: syzbot+a2bc0e838efd7663f4d9@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a2bc0e838efd7663f4d9
Signed-off-by: Pei Li <peili.dev@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/sb-errors.c

index bda33e59e2264bc2225d223ce9edc68d48885643..c1270d790e43bfea083267b14b90362dc9ece6a8 100644 (file)
@@ -110,19 +110,25 @@ out:
 void bch2_sb_errors_from_cpu(struct bch_fs *c)
 {
        bch_sb_errors_cpu *src = &c->fsck_error_counts;
-       struct bch_sb_field_errors *dst =
-               bch2_sb_field_resize(&c->disk_sb, errors,
-                                    bch2_sb_field_errors_u64s(src->nr));
+       struct bch_sb_field_errors *dst;
        unsigned i;
 
+       mutex_lock(&c->fsck_error_counts_lock);
+
+       dst = bch2_sb_field_resize(&c->disk_sb, errors,
+                                  bch2_sb_field_errors_u64s(src->nr));
+
        if (!dst)
-               return;
+               goto err;
 
        for (i = 0; i < src->nr; i++) {
                SET_BCH_SB_ERROR_ENTRY_ID(&dst->entries[i], src->data[i].id);
                SET_BCH_SB_ERROR_ENTRY_NR(&dst->entries[i], src->data[i].nr);
                dst->entries[i].last_error_time = cpu_to_le64(src->data[i].last_error_time);
        }
+
+err:
+       mutex_unlock(&c->fsck_error_counts_lock);
 }
 
 static int bch2_sb_errors_to_cpu(struct bch_fs *c)