Hold read lock in bch2_snapshot_tree_oldest_subvol()
PATCH 1/1 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.
--- fs/bcachefs/snapshot.c | 3 +++ 1 file changed, 3 insertions(+)
fs/bcachefs/snapshot.c +3 -0
@@ -8,6 +8,7 @@#include "errcode.h" #include "error.h" #include "fs.h" +#include "linux/rcupdate.h" #include "recovery_passes.h" #include "snapshot.h"
@@ -469,6 +470,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)u32 id = snapshot_root;u32 subvol =0 , s; +rcu_read_lock ();while (id) { s =snapshot_t (c, id)->subvol;
@@ -477,6 +479,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root) id =bch2_snapshot_tree_next (c, id); } +rcu_read_unlock ();return subvol; }
Signature · 1 line
2.46.0
Quoted 23 lines · Ahmed Ehab
Syzbot reports a problem that a warning is triggered due to suspicious use of
rcu_dereference_check(). That is triggered by a call ofbch2_snapshot_tree_oldest_subvol().The cause of the warning is that inside
bch2_snapshot_tree_oldest_subvol(),snapshot_t()is called which callsrcu_dereference()that requires a read lock to be held. Also, the call ofbch2_snapshot_tree_next()eventually callssnapshot_t().To fix this, call
rcu_read_lock()before callingsnapshot_t(). Then, release the lock after the termination of the while loop.Reported-by <[email protected]>Signed-off-by Ahmed Ehab <[email protected]>--- fs/bcachefs/snapshot.c | 3 +++ 1 file changed, 3 insertions(+)fs/bcachefs/snapshot.c +0
-0
fs/bcachefs/snapshot.c line 11
Quoted 4 lines
fs/bcachefs/snapshot.c +1
-0@@ -8,6 +8,7 @@#include "errcode.h" #include "error.h" #include "fs.h" +#include "linux/rcupdate.h"
unnecessary, this is already pulled in - but I'll fix that nit and apply
Quoted 22 lines
fs/bcachefs/snapshot.c +2
-0#include "recovery_passes.h" #include "snapshot.h" @@ -469,6 +470,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)u32 id = snapshot_root;u32 subvol =0 , s; +rcu_read_lock ();while (id) { s =snapshot_t (c, id)->subvol;@@ -477,6 +479,7 @@ static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root) id =bch2_snapshot_tree_next (c, id); } +rcu_read_unlock ();return subvol; }Signature · 1 line
2.46.0