public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 0/2] btrfs-progs: mkfs: extent-tree-v2 related fixes
Date: Fri,  7 Oct 2022 20:02:59 +0800	[thread overview]
Message-ID: <cover.1665143843.git.wqu@suse.com> (raw)

Although recently we still have some uncertainty around the on-disk
format for extent-tree-v2, related to how to determine the number
of global roots, most of the on-disk format is fixed.

And even with the uncertain part involved, mkfs.btrfs should not crash
for extent-tree-v2 feature (hidden behind the experimental builds).

There are two bugs involved:

- A crash caused by incorrectly set chunk_objectid for block group item
  As extent-tree-v2 feature reuse that member to indicate which extent
  tree a block group belongs to.

  But the regular fs uses a fixed 256 for that chunk_objectid, and no
  extent-tree-v2 btrfs would have that many global roots.

  This leads to btrfs_extent_root() to return NULL, and cause later
  segfault.

  Fix it by properly setting chunk_objectid.
  This is a regression caused by 1430b41427b5 ("btrfs-progs: separate
  block group tree from extent tree v2").

- A stack-over-flow caused by too long feature string
  With extent-tree-v2 enabled, we have at least 84 bytes long feature
  string (unified features, including compat_ro features likle fst).

  This is beyond the hard-coded 64 bytes limit.

  Fix it by introducing a new macro to indicate a minimal safe buf size,
  and a sanity check to make sure that macro is really large enough.

Qu Wenruo (2):
  btrfs-progs: mkfs: fix a crash when enabling extent-tree-v2
  btrfs-progs: mkfs: fix a stack over-flow when features string are too
    long

 common/fsfeatures.c | 26 ++++++++++++++++++++++++++
 common/fsfeatures.h |  7 +++++++
 convert/main.c      |  3 ++-
 mkfs/common.c       | 14 ++++++++++++--
 mkfs/main.c         |  3 ++-
 5 files changed, 49 insertions(+), 4 deletions(-)

-- 
2.37.3


             reply	other threads:[~2022-10-07 12:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07 12:02 Qu Wenruo [this message]
2022-10-07 12:03 ` [PATCH 1/2] btrfs-progs: mkfs: fix a crash when enabling extent-tree-v2 Qu Wenruo
2022-10-08 11:51   ` Anand Jain
2022-10-07 12:03 ` [PATCH 2/2] btrfs-progs: mkfs: fix a stack over-flow when features string are too long Qu Wenruo
2022-10-08 11:52   ` Anand Jain
2022-10-10 14:34 ` [PATCH 0/2] btrfs-progs: mkfs: extent-tree-v2 related fixes David Sterba

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.1665143843.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