Skip to content

Commit 39c3aad

Browse files
botta633Kent Overstreet
authored andcommitted
bcachefs: Hold read lock in bch2_snapshot_tree_oldest_subvol()
Syzbot reports a problem that a warning is triggered due to suspicious use of rcu_dereference_check(). That is triggered by a call of bch2_snapshot_tree_oldest_subvol(). The cause of the warning is that inside bch2_snapshot_tree_oldest_subvol(), snapshot_t() is called which calls rcu_dereference() that requires a read lock to be held. Also, the call of bch2_snapshot_tree_next() eventually calls snapshot_t(). To fix this, call rcu_read_lock() before calling snapshot_t(). Then, release the lock after the termination of the while loop. Reported-by: <[email protected]> Signed-off-by: Ahmed Ehab <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 025c55a commit 39c3aad

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/bcachefs/snapshot.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)
469469
u32 id = snapshot_root;
470470
u32 subvol = 0, s;
471471

472+
rcu_read_lock();
472473
while (id) {
473474
s = snapshot_t(c, id)->subvol;
474475

@@ -477,6 +478,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)
477478

478479
id = bch2_snapshot_tree_next(c, id);
479480
}
481+
rcu_read_unlock();
480482

481483
return subvol;
482484
}

0 commit comments

Comments
 (0)