Skip to content

Commit 211c581

Browse files
peiliiKent Overstreet
authored andcommitted
bcachefs: slab-use-after-free Read in bch2_sb_errors_from_cpu
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: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=a2bc0e838efd7663f4d9 Signed-off-by: Pei Li <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 89d21b6 commit 211c581

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fs/bcachefs/sb-errors.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,25 @@ void bch2_sb_error_count(struct bch_fs *c, enum bch_sb_error_id err)
110110
void bch2_sb_errors_from_cpu(struct bch_fs *c)
111111
{
112112
bch_sb_errors_cpu *src = &c->fsck_error_counts;
113-
struct bch_sb_field_errors *dst =
114-
bch2_sb_field_resize(&c->disk_sb, errors,
115-
bch2_sb_field_errors_u64s(src->nr));
113+
struct bch_sb_field_errors *dst;
116114
unsigned i;
117115

116+
mutex_lock(&c->fsck_error_counts_lock);
117+
118+
dst = bch2_sb_field_resize(&c->disk_sb, errors,
119+
bch2_sb_field_errors_u64s(src->nr));
120+
118121
if (!dst)
119-
return;
122+
goto err;
120123

121124
for (i = 0; i < src->nr; i++) {
122125
SET_BCH_SB_ERROR_ENTRY_ID(&dst->entries[i], src->data[i].id);
123126
SET_BCH_SB_ERROR_ENTRY_NR(&dst->entries[i], src->data[i].nr);
124127
dst->entries[i].last_error_time = cpu_to_le64(src->data[i].last_error_time);
125128
}
129+
130+
err:
131+
mutex_unlock(&c->fsck_error_counts_lock);
126132
}
127133

128134
static int bch2_sb_errors_to_cpu(struct bch_fs *c)

0 commit comments

Comments
 (0)