Skip to content

Commit 49fd90b

Browse files
author
Kent Overstreet
committed
bcachefs: Fix unlocked access to c->disk_sb.sb in bch2_replicas_entry_validate()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 9104fc1 commit 49fd90b

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

fs/bcachefs/journal_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static int journal_entry_data_usage_validate(struct bch_fs *c,
605605
goto out;
606606
}
607607

608-
if (journal_entry_err_on(bch2_replicas_entry_validate(&u->r, c->disk_sb.sb, &err),
608+
if (journal_entry_err_on(bch2_replicas_entry_validate(&u->r, c, &err),
609609
c, version, jset, entry,
610610
journal_entry_data_usage_bad_size,
611611
"invalid journal entry usage: %s", err.buf)) {

fs/bcachefs/replicas.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ void bch2_replicas_entry_to_text(struct printbuf *out,
6666
prt_printf(out, "]");
6767
}
6868

69-
int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *r,
70-
struct bch_sb *sb,
71-
struct printbuf *err)
69+
static int bch2_replicas_entry_validate_locked(struct bch_replicas_entry_v1 *r,
70+
struct bch_sb *sb,
71+
struct printbuf *err)
7272
{
7373
if (!r->nr_devs) {
7474
prt_printf(err, "no devices in entry ");
@@ -94,6 +94,16 @@ int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *r,
9494
return -BCH_ERR_invalid_replicas_entry;
9595
}
9696

97+
int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *r,
98+
struct bch_fs *c,
99+
struct printbuf *err)
100+
{
101+
mutex_lock(&c->sb_lock);
102+
int ret = bch2_replicas_entry_validate_locked(r, c->disk_sb.sb, err);
103+
mutex_unlock(&c->sb_lock);
104+
return ret;
105+
}
106+
97107
void bch2_cpu_replicas_to_text(struct printbuf *out,
98108
struct bch_replicas_cpu *r)
99109
{
@@ -676,7 +686,7 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
676686
struct bch_replicas_entry_v1 *e =
677687
cpu_replicas_entry(cpu_r, i);
678688

679-
int ret = bch2_replicas_entry_validate(e, sb, err);
689+
int ret = bch2_replicas_entry_validate_locked(e, sb, err);
680690
if (ret)
681691
return ret;
682692

fs/bcachefs/replicas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void bch2_replicas_entry_sort(struct bch_replicas_entry_v1 *);
1010
void bch2_replicas_entry_to_text(struct printbuf *,
1111
struct bch_replicas_entry_v1 *);
1212
int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *,
13-
struct bch_sb *, struct printbuf *);
13+
struct bch_fs *, struct printbuf *);
1414
void bch2_cpu_replicas_to_text(struct printbuf *, struct bch_replicas_cpu *);
1515

1616
static inline struct bch_replicas_entry_v1 *

0 commit comments

Comments
 (0)