lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <gire2ul2mlbkrn7jsndwzfxybfijhcse3c2gcq6rmzqaguaz2h@gimiz6gtsgyu>
Date: Sat, 21 Sep 2024 14:53:27 -0400
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: Ahmed Ehab <bottaawesome633@...il.com>
Cc: linux-kernel@...r.kernel.org, linux-bcachefs@...r.kernel.org, 
	syzkaller@...glegroups.com, syzbot+f7c41a878676b72c16a6@...kaller.appspotmail.com
Subject: Re: [PATCH] Hold read lock in bch2_snapshot_tree_oldest_subvol()

On Sun, Sep 22, 2024 at 12:00:36AM GMT, Ahmed Ehab wrote:
> 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: <syzbot+f7c41a878676b72c16a6@...kaller.appspotmail.com>
> Signed-off-by: Ahmed Ehab <bottaawesome633@...il.com>
> ---
>  fs/bcachefs/snapshot.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c
> index 8b18a9b483a4..678e9fdee348 100644
> --- a/fs/bcachefs/snapshot.c
> +++ b/fs/bcachefs/snapshot.c
> @@ -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

>  #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;
>  }
> -- 
> 2.46.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ