linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Yongpeng Yang <yangyongpeng.storage@gmail.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Theodore Ts'o <tytso@mit.edu>,
	linux-fscrypt@vger.kernel.org,
	Yongpeng Yang <yangyongpeng@xiaomi.com>,
	linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: Re: [PATCH v2] fscrypt: fix left shift underflow when inode->i_blkbits > PAGE_SHIFT
Date: Tue, 4 Nov 2025 10:10:06 -0800	[thread overview]
Message-ID: <20251104181006.GC1780@sol> (raw)
In-Reply-To: <aQnftXAg93-4FbaO@infradead.org>

On Tue, Nov 04, 2025 at 03:12:53AM -0800, Christoph Hellwig wrote:
> On Mon, Nov 03, 2025 at 08:48:29AM -0800, Eric Biggers wrote:
> > >  	*inode_ret = inode;
> > > -	*lblk_num_ret = ((u64)folio->index << (PAGE_SHIFT - inode->i_blkbits)) +
> > > +	*lblk_num_ret = (((u64)folio->index << PAGE_SHIFT) >> inode->i_blkbits) +
> 
> This should be using folio_pos() instead of open coding the arithmetics.

Well, folio_pos() doesn't work with sizes greater than S64_MAX, and it
uses multiplication rather than a shift.

Probably doesn't matter, but I always feel like I have to actually check
that.

It looks like the size of block device can come from several different
places, including set_capacity(), bdev_resize_partition(), and
add_partition().  The first has a size check.  I don't immediately see a
size check in the other two.  Maybe it's there and I need to look
closer.  Also can the size of a block device be set in other ways?

Then I have to remember whether a multiplication of a signed value gets
reliably optimized to a shift on all architectures or not.  I think so.

Anyway, the trivial version avoids having to consider any of this...

- Eric

  parent reply	other threads:[~2025-11-04 18:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251030072956.454679-1-yangyongpeng.storage@gmail.com>
2025-11-03 16:48 ` [PATCH v2] fscrypt: fix left shift underflow when inode->i_blkbits > PAGE_SHIFT Eric Biggers
2025-11-04 11:12   ` Christoph Hellwig
2025-11-04 15:05     ` Yongpeng Yang
2025-11-05 13:38       ` Christoph Hellwig
2025-11-04 18:10     ` Eric Biggers [this message]
2025-11-05 13:40       ` Christoph Hellwig

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=20251104181006.GC1780@sol \
    --to=ebiggers@kernel.org \
    --cc=hch@infradead.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=tytso@mit.edu \
    --cc=yangyongpeng.storage@gmail.com \
    --cc=yangyongpeng@xiaomi.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;
as well as URLs for NNTP newsgroup(s).