Re: [PATCH v2] bcachefs: don't return fsck_fix for unfixable node errors in __btree_err

From: Kent Overstreet
Date: Sun Jun 15 2025 - 13:17:15 EST


On Sun, Jun 15, 2025 at 10:15:38PM +0530, Bharadwaj Raju wrote:
> After cd3cdb1ef706 ("Single err message for btree node reads"),
> all errors caused __btree_err to return -BCH_ERR_fsck_fix no matter what
> the actual error type was if the recovery pass was scanning for btree
> nodes. This lead to the code continuing despite things like bad node
> formats when they earlier would have caused a jump to fsck_err, because
> btree_err only jumps when the return from __btree_err does not match
> fsck_fix. Ultimately this lead to undefined behavior by attempting to
> unpack a key based on an invalid format.
>
> Make only errors of type -BCH_ERR_btree_node_read_err_fixable cause
> __btree_err to return -BCH_ERR_fsck_fix when scanning for btree nodes.
>
> Reported-by: syzbot+cfd994b9cdf00446fd54@xxxxxxxxxxxxxxxxxxxxxxxxx
> Fixes: cd3cdb1ef706 ("bcachefs: Single err message for btree node reads")
> Signed-off-by: Bharadwaj Raju <bharadwaj.raju777@xxxxxxxxx>

Applied

> ---
> v2: Return the given ret for all errors which are not btree_node_read_err_fixable when in scan_for_btree_nodes
>
> fs/bcachefs/btree_io.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/bcachefs/btree_io.c b/fs/bcachefs/btree_io.c
> index d8f3c4c65e90..940f7ce2e33e 100644
> --- a/fs/bcachefs/btree_io.c
> +++ b/fs/bcachefs/btree_io.c
> @@ -557,7 +557,9 @@ static int __btree_err(int ret,
> const char *fmt, ...)
> {
> if (c->recovery.curr_pass == BCH_RECOVERY_PASS_scan_for_btree_nodes)
> - return bch_err_throw(c, fsck_fix);
> + return ret == -BCH_ERR_btree_node_read_err_fixable
> + ? bch_err_throw(c, fsck_fix)
> + : ret;
>
> bool have_retry = false;
> int ret2;
> --
> 2.49.0
>