From: Bharadwaj Raju <bharadwaj.raju777@gmail.com>
To: kent.overstreet@linux.dev
Cc: Bharadwaj Raju <bharadwaj.raju777@gmail.com>,
linux-bcachefs@vger.kernel.org, shuah@kernel.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev,
syzbot+cfd994b9cdf00446fd54@syzkaller.appspotmail.com
Subject: [PATCH] bcachefs: don't return early from __btree_err for bad or incompatible node read errors
Date: Sun, 15 Jun 2025 00:27:40 +0530 [thread overview]
Message-ID: <20250614185743.657564-1-bharadwaj.raju777@gmail.com> (raw)
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 errors of type BCH_ERR_btree_node_read_err_bad_node (only if
__bch2_topology_error) or BCH_ERR_btree_node_read_err_incompatible go
through the full __btree_err function instead of returning fsck_fix even
when we are in that recovery phase.
Reported-by: syzbot+cfd994b9cdf00446fd54@syzkaller.appspotmail.com
Fixes: cd3cdb1ef706 ("bcachefs: Single err message for btree node reads")
Signed-off-by: Bharadwaj Raju <bharadwaj.raju777@gmail.com>
---
fs/bcachefs/btree_io.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/bcachefs/btree_io.c b/fs/bcachefs/btree_io.c
index d8f3c4c65e90..e010ae94f1e1 100644
--- a/fs/bcachefs/btree_io.c
+++ b/fs/bcachefs/btree_io.c
@@ -556,7 +556,10 @@ static int __btree_err(int ret,
struct printbuf *err_msg,
const char *fmt, ...)
{
- if (c->recovery.curr_pass == BCH_RECOVERY_PASS_scan_for_btree_nodes)
+ if (c->recovery.curr_pass == BCH_RECOVERY_PASS_scan_for_btree_nodes &&
+ !(ret == -BCH_ERR_btree_node_read_err_bad_node &&
+ __bch2_topology_error(c, err_msg)) &&
+ ret != -BCH_ERR_btree_node_read_err_incompatible)
return bch_err_throw(c, fsck_fix);
bool have_retry = false;
--
2.49.0
next reply other threads:[~2025-06-14 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-14 18:57 Bharadwaj Raju [this message]
2025-06-15 0:19 ` [PATCH] bcachefs: don't return early from __btree_err for bad or incompatible node read errors Kent Overstreet
2025-06-15 8:12 ` Bharadwaj Raju
2025-06-15 16:05 ` Kent Overstreet
2025-06-15 16:46 ` Bharadwaj Raju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250614185743.657564-1-bharadwaj.raju777@gmail.com \
--to=bharadwaj.raju777@gmail.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=syzbot+cfd994b9cdf00446fd54@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).