From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 0/2] btrfs: hardening against radix tree conflicts on 32bit systems
Date: Mon, 2 Nov 2026 19:58:36 +1030 [thread overview]
Message-ID: <cover.1793611601.git.wqu@suse.com> (raw)
Inspired by a recent patch touching btrfs_ioctl_subvol_sync() function,
it turns out that we have a very rare (I'd even call it unpractical) but
still real (one can even craft one image) problem, that on 32-bit
systems, we always truncate the subvolid down to 32bit unsigned long.
This means the following two valid subvolume trees will get the same
index:
Subvolume 257 (0x101) and subvolume 4294967553 (0x100000101)
It should really be very rare, as we have other limits like anon_dev,
which should hit way before subvolumeid limits.
But one can craft an image with only above two subvolumes, and on 32bit
systems only one subvolume can be reached.
Address the situation by:
- Do not insert data reloc tree into fs_roots_radix
As we will reject subvolume ids > ULONG_MAX on 32 bit systems, we
don't want to insert data reloc tree into that radix tree in the first
place.
- Reject subvolume ids > ULONG_MAX
For 64 bits this will become an no-op.
For 32 bits, most subvolumes should still have their ids <= ULONG_MAX.
For crafted images, subvolumes ids larger than ULONG_MAX will be
rejected with a rate-limited error message every time such subvolume
is going to be inserted.
This can lead to some transaction abort, e.g. createing a snapshot
whose id is too large.
But I don't have better solution than rejecting them.
Qu Wenruo (2):
btrfs: do not insert the data reloc tree into fs_roots_radix
btrfs: reject subvolume ids that do not fit into unsigned long
fs/btrfs/disk-io.c | 64 +++++++++++++++++++++++++++++++++++++++-------
fs/btrfs/disk-io.h | 19 ++++++++++++++
fs/btrfs/ioctl.c | 2 +-
3 files changed, 75 insertions(+), 10 deletions(-)
--
2.56.0
next reply other threads:[~2026-11-02 9:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 9:28 Qu Wenruo [this message]
2026-11-02 9:28 ` [PATCH 1/2] btrfs: do not insert the data reloc tree into fs_roots_radix Qu Wenruo
2026-11-02 19:49 ` Filipe Manana
2026-11-02 9:28 ` [PATCH 2/2] btrfs: reject subvolume ids that do not fit into unsigned long Qu Wenruo
2026-11-02 19:54 ` Filipe Manana
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=cover.1793611601.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@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