From: Siddharth Mishra <smish149@asu.edu>
To: dsterba@suse.com
Cc: mason@kernel.org, josef@toxicpanda.com, wqu@suse.com,
fdmanana@kernel.org, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org, Siddharth Mishra <smish149@asu.edu>
Subject: [PATCH 0/2] btrfs: balance item fixes
Date: Thu, 5 Nov 2026 14:47:36 -0700 [thread overview]
Message-ID: <20261105214738.111967-1-smish149@asu.edu> (raw)
Patch 1 fixes a BUG_ON() in btrfs_balance() on a valid filesystem. A
balance can leave its item in the root tree when the commit after the
insert fails without an abort, and the next balance then finds the item
and hits BUG_ON(ret == -EEXIST). syzbot reported it, see patch 1. The
new balance now overwrites the item that no balance owns.
Patch 2 is hardening. Nothing checks the size of the balance item, and
btrfs_recover_balance() reads past a short item at mount. The
tree-checker now rejects a balance item with the wrong size.
Found while looking into a fuzzing report. An AI tool helped with the
analysis and the patches.
Tested on btrfs for-next df5b88a7914e, KASAN and non-debug kernels:
- Patch 1: on a new filesystem, one failed allocation in
btrfs_start_dirty_block_groups() during a first balance, then a
second balance: the BUG_ON() before; with the patch the second
balance runs to the end, no balance item is left and btrfs check is
clean. The same with a failed allocation at each of the first 206
allocation points of the first balance: no BUG, KASAN report or
assertion. Not reproduced without fault injection. The other way to
the BUG_ON(), a transaction aborted with -EEXIST, is not reproduced
on this base: the corrupted image that hit it is now refused by the
tree-checker at mount.
- Patch 2: a crafted image with a 400 byte balance item is refused at
mount; valid filesystems (a paused balance resumed or cancelled after
mount, a balance paused and resumed) are not rejected.
- Both: pause, resume, cancel and skip_balance work as before;
fstests -g balance and btrfs/220: no new failure.
The crafted image is available on request.
Siddharth Mishra (2):
btrfs: overwrite a leftover balance item instead of BUG_ON()
btrfs: tree-checker: add balance item size check
fs/btrfs/tree-checker.c | 17 +++++++++++++++++
fs/btrfs/volumes.c | 10 ++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
base-commit: df5b88a7914e18488908ddf13e14e31ab39f954c
--
2.54.0
next reply other threads:[~2026-11-05 21:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 21:47 Siddharth Mishra [this message]
2026-11-05 21:47 ` [PATCH 1/2] btrfs: overwrite a leftover balance item instead of BUG_ON() Siddharth Mishra
2026-11-05 22:09 ` Qu Wenruo
2026-11-05 22:40 ` Siddharth Mishra
2026-11-05 22:43 ` Qu Wenruo
2026-11-05 21:47 ` [PATCH 2/2] btrfs: tree-checker: add balance item size check Siddharth Mishra
2026-11-05 22:06 ` Qu Wenruo
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=20261105214738.111967-1-smish149@asu.edu \
--to=smish149@asu.edu \
--cc=dsterba@suse.com \
--cc=fdmanana@kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=wqu@suse.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
all inboxes | Powered by JetHome®