public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/3] xfs: fix realtime geometry integer overflows
@ 2023-12-03 19:00 Darrick J. Wong
  2023-12-03 19:05 ` [PATCH 1/3] xfs: make rextslog computation consistent with mkfs Darrick J. Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Darrick J. Wong @ 2023-12-03 19:00 UTC (permalink / raw)
  To: djwong, chandanbabu, hch; +Cc: linux-xfs

Hi all,

While reading through the realtime geometry support code in xfsprogs, I
noticed a discrepancy between the sb_rextslog computation used when
writing out the superblock during mkfs and the validation code used in
xfs_repair.  This discrepancy would lead to system failure for a runt rt
volume having more than 1 rt block but zero rt extents in length.  Most
people aren't going to configure a 1M extent size for their 360k rt
floppy disk volume, but I did!

In the process of studying that code, it occurred to me that there is a
second bug in the computation -- the use of highbit32 for a 64-bit
value means that the upper 32 bits are not considered in the search for
a high bit.  This causes the creation of a realtime summary file that is
the wrong length.  If rextents is a multiple of U32_MAX then this will
appear to work fine because highbit32 returns -1 for an input of 0; but
for all other cases the rt summary is undersized, leading to failures.

Fix the first problem by standardizing the computation with a helper in
libxfs; and the second problem by correcting the computation.  This will
cause any existing rt volumes larger than 2^32 blocks to fail validation
but they probably were already crashing anyway.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been lightly tested with fstests.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fix-rtmount-overflows-6.7
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   12 ++++++++++++
 fs/xfs/libxfs/xfs_rtbitmap.h |   14 ++++++++++++++
 fs/xfs/libxfs/xfs_sb.c       |    6 ++++--
 fs/xfs/xfs_rtalloc.c         |    6 ++++--
 4 files changed, 34 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [PATCHSET v2 0/3] xfs: fix realtime geometry integer overflows
@ 2023-12-07  2:23 Darrick J. Wong
  2023-12-07  2:28 ` [PATCH 3/3] xfs: don't allow overly small or large realtime volumes Darrick J. Wong
  0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2023-12-07  2:23 UTC (permalink / raw)
  To: chandanbabu, hch, djwong; +Cc: linux-xfs

Hi all,

While reading through the realtime geometry support code in xfsprogs, I
noticed a discrepancy between the sb_rextslog computation used when
writing out the superblock during mkfs and the validation code used in
xfs_repair.  This discrepancy would lead to system failure for a runt rt
volume having more than 1 rt block but zero rt extents in length.  Most
people aren't going to configure a 1M extent size for their 360k rt
floppy disk volume, but I did!

In the process of studying that code, it occurred to me that there is a
second bug in the computation -- the use of highbit32 for a 64-bit
value means that the upper 32 bits are not considered in the search for
a high bit.  This causes the creation of a realtime summary file that is
the wrong length.  If rextents is a multiple of U32_MAX then this will
appear to work fine because highbit32 returns -1 for an input of 0; but
for all other cases the rt summary is undersized, leading to failures.

Fix the first problem by standardizing the computation with a helper in
libxfs; and the second problem by correcting the computation.  This will
cause any existing rt volumes larger than 2^32 blocks to fail validation
but they probably were already crashing anyway.

v2: pick up review tags

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been lightly tested with fstests.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=fix-rtmount-overflows-6.8
---
 fs/xfs/libxfs/xfs_rtbitmap.c |   14 ++++++++++++++
 fs/xfs/libxfs/xfs_rtbitmap.h |   16 ++++++++++++++++
 fs/xfs/libxfs/xfs_sb.c       |    6 ++++--
 fs/xfs/xfs_rtalloc.c         |    6 ++++--
 4 files changed, 38 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-07  2:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-03 19:00 [PATCHSET 0/3] xfs: fix realtime geometry integer overflows Darrick J. Wong
2023-12-03 19:05 ` [PATCH 1/3] xfs: make rextslog computation consistent with mkfs Darrick J. Wong
2023-12-04  4:55   ` Christoph Hellwig
2023-12-04 18:52     ` Darrick J. Wong
2023-12-03 19:05 ` [PATCH 2/3] xfs: fix 32-bit truncation in xfs_compute_rextslog Darrick J. Wong
2023-12-04  4:55   ` Christoph Hellwig
2023-12-03 19:05 ` [PATCH 3/3] xfs: don't allow overly small or large realtime volumes Darrick J. Wong
2023-12-03 19:09   ` Darrick J. Wong
2023-12-04  4:56   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2023-12-07  2:23 [PATCHSET v2 0/3] xfs: fix realtime geometry integer overflows Darrick J. Wong
2023-12-07  2:28 ` [PATCH 3/3] xfs: don't allow overly small or large realtime volumes Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox