All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@lst.de>
Cc: cem@kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 03/27] repair: refactor the BLKMAP_NEXTS_MAX check
Date: Thu, 15 Feb 2024 10:11:09 +1100	[thread overview]
Message-ID: <Zc1IjZm8sd2dLSBV@dread.disaster.area> (raw)
In-Reply-To: <20240129073215.108519-4-hch@lst.de>

On Mon, Jan 29, 2024 at 08:31:51AM +0100, Christoph Hellwig wrote:
> Check the 32-bit limits using sizeof instead of cpp ifdefs so that we
> can get rid of BITS_PER_LONG.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  repair/bmap.c | 23 +++++++++++++++--------
>  repair/bmap.h | 13 -------------
>  2 files changed, 15 insertions(+), 21 deletions(-)
> 
> diff --git a/repair/bmap.c b/repair/bmap.c
> index cd1a8b07b..d1b2faaec 100644
> --- a/repair/bmap.c
> +++ b/repair/bmap.c
> @@ -22,6 +22,15 @@
>  pthread_key_t	dblkmap_key;
>  pthread_key_t	ablkmap_key;
>  
> +/*
> + * For 32 bit platforms, we are limited to extent arrays of 2^31 bytes, which
> + * limits the number of extents in an inode we can check. If we don't limit the
> + * valid range, we can overflow the BLKMAP_SIZE() calculation and allocate less
> + * memory than we think we needed, and hence walk off the end of the array and
> + * corrupt memory.
> + */
> +#define BLKMAP_NEXTS32_MAX	((INT_MAX / sizeof(bmap_ext_t)) - 1)
> +
>  blkmap_t *
>  blkmap_alloc(
>  	xfs_extnum_t	nex,
> @@ -35,8 +44,7 @@ blkmap_alloc(
>  	if (nex < 1)
>  		nex = 1;
>  
> -#if (BITS_PER_LONG == 32)	/* on 64-bit platforms this is never true */
> -	if (nex > BLKMAP_NEXTS_MAX) {
> +	if (sizeof(long) == 32 && nex > BLKMAP_NEXTS32_MAX) {

That's a really, really big long. sizeof(long) = 4, perhaps?

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2024-02-14 23:11 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29  7:31 decrufify the configure checks Christoph Hellwig
2024-01-29  7:31 ` [PATCH 01/27] include: remove the filldir_t typedef Christoph Hellwig
2024-01-29  7:31 ` [PATCH 02/27] include: unconditionally define umode_t Christoph Hellwig
2024-01-29  7:31 ` [PATCH 03/27] repair: refactor the BLKMAP_NEXTS_MAX check Christoph Hellwig
2024-02-14 23:11   ` Dave Chinner [this message]
2024-02-15  5:24     ` Christoph Hellwig
2024-01-29  7:31 ` [PATCH 04/27] include: stop using SIZEOF_LONG Christoph Hellwig
2024-01-29  7:31 ` [PATCH 05/27] include: stop generating platform_defs.h Christoph Hellwig
2024-01-29  7:31 ` [PATCH 06/27] io: don't redefine SEEK_DATA and SEEK_HOLE Christoph Hellwig
2024-01-29  7:31 ` [PATCH 07/27] configure: don't check for getmntent Christoph Hellwig
2024-01-29  7:31 ` [PATCH 08/27] configure: require libblkid Christoph Hellwig
2024-01-29  7:31 ` [PATCH 09/27] configure: don't check for fadvise Christoph Hellwig
2024-01-29  7:31 ` [PATCH 10/27] configure: don't check for sendfile Christoph Hellwig
2024-01-29  7:31 ` [PATCH 11/27] configure: don't check for madvise Christoph Hellwig
2024-01-29  7:32 ` [PATCH 12/27] configure: don't check for mincor Christoph Hellwig
2024-01-29  7:32 ` [PATCH 13/27] configure: don't check for fiemap Christoph Hellwig
2024-01-29  7:32 ` [PATCH 14/27] configure: don't check for sync_file_range Christoph Hellwig
2024-01-29  7:32 ` [PATCH 15/27] configure: don't check for readdir Christoph Hellwig
2024-01-29  7:32 ` [PATCH 16/27] configure: don't check for fls Christoph Hellwig
2024-01-29  7:32 ` [PATCH 17/27] configure: don't check for fallocate Christoph Hellwig
2024-01-29  7:32 ` [PATCH 18/27] configure: don't check for syncfs Christoph Hellwig
2024-01-29  7:32 ` [PATCH 19/27] configure: don't check for preadv and pwritev Christoph Hellwig
2024-01-29  7:32 ` [PATCH 20/27] configure: don't check for mremap Christoph Hellwig
2024-01-29  7:32 ` [PATCH 21/27] configure: don't check for fsetxattr Christoph Hellwig
2024-01-29  7:32 ` [PATCH 22/27] configure: don't check for the f_flags field in statfs Christoph Hellwig
2024-01-29  7:32 ` [PATCH 23/27] configure: don't check for mallinfo Christoph Hellwig
2024-02-02  6:44   ` Sam James
2024-02-03  7:44     ` Christoph Hellwig
2024-01-29  7:32 ` [PATCH 24/27] configure: don't check for openat Christoph Hellwig
2024-01-29  7:32 ` [PATCH 25/27] configure: don't check for fstatat Christoph Hellwig
2024-01-29  7:32 ` [PATCH 26/27] configure: don't check for SG_IO Christoph Hellwig
2024-01-29  7:32 ` [PATCH 27/27] configure: don't check for HDIO_GETGEO Christoph Hellwig
2024-01-30  4:52 ` decrufify the configure checks Darrick J. Wong

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=Zc1IjZm8sd2dLSBV@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=cem@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-xfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.