public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
From: Nirbhay Sharma <nirbhay.lkd@gmail.com>
To: kent.overstreet@linux.dev
Cc: linux-bcachefs@vger.kernel.org, Nirbhay Sharma <nirbhay.lkd@gmail.com>
Subject: bcachefs: question about fixing use-after-free in bch2_extent_ptr_to_text
Date: Fri,  3 Oct 2025 16:12:14 +0530	[thread overview]
Message-ID: <20251003104213.369614-2-nirbhay.lkd@gmail.com> (raw)

Hi Kent,

I'm investigating syzbot report 564efbe31172fe908429 and have 
successfully reproduced the crash with the C reproducer.

Link: https://syzkaller.appspot.com/bug?extid=564efbe31172fe908429

The issue: bch2_extent_ptr_to_text() crashes when called on a corrupted
extent pointer (bucket 27 < first_bucket 1024). The validation already
detected this:
  "invalid bkey: pointer before first bucket (27 < 1024), deleting"

But bch2_extent_ptr_to_text() is still called afterward (for debug 
output) and crashes in dev_ptr_stale_rcu() when it tries to access 
bucket metadata at an invalid offset.

Looking at the code in fs/bcachefs/extents.c:1247, the function calls
dev_ptr_stale_rcu() without checking if the bucket number is valid.

Should I add bounds checking like this:

  if (b < ca->mi.first_bucket || b >= ca->mi.nbuckets) {
      prt_str(out, " invalid");
  } else {
      int stale = dev_ptr_stale_rcu(ca, ptr);
      ...
  }

Or is there a better approach? I want to make sure I'm fixing this
correctly since you reviewed my previous dirent patch.

Thanks,
Nirbhay Sharma

                 reply	other threads:[~2025-10-03 10:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251003104213.369614-2-nirbhay.lkd@gmail.com \
    --to=nirbhay.lkd@gmail.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    /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