All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yongpeng Yang <yangyongpeng.storage@gmail.com>
To: Christoph Hellwig <hch@infradead.org>,
	Eric Biggers <ebiggers@kernel.org>
Cc: 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 23:05:49 +0800	[thread overview]
Message-ID: <b8f06e62-27dc-462e-83ad-33b179daf8a2@gmail.com> (raw)
In-Reply-To: <aQnftXAg93-4FbaO@infradead.org>

On 11/4/2025 7:12 PM, 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.
> 

How about this modification: using "<< PAGE_SHIFT" instead of "* 
PAGE_SIZE" for page_offset and folio_pos?

--- a/fs/crypto/inline_crypt.c
+++ b/fs/crypto/inline_crypt.c
@@ -333,7 +333,7 @@ static bool bh_get_inode_and_lblk_num(const struct 
buffer_head *bh,
         inode = mapping->host;

         *inode_ret = inode;
-       *lblk_num_ret = ((u64)folio->index << (PAGE_SHIFT - 
inode->i_blkbits)) +
+       *lblk_num_ret = ((u64)folio_pos(folio) >> inode->i_blkbits) +
                         (bh_offset(bh) >> inode->i_blkbits);
         return true;
  }
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 09b581c1d878..72eeb1841bc3 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1026,7 +1026,7 @@ static inline pgoff_t page_pgoff(const struct 
folio *folio,
   */
  static inline loff_t folio_pos(const struct folio *folio)
  {
-       return ((loff_t)folio->index) * PAGE_SIZE;
+       return ((loff_t)folio->index) << PAGE_SHIFT;
  }

  /*
@@ -1036,7 +1036,7 @@ static inline loff_t page_offset(struct page *page)
  {
         struct folio *folio = page_folio(page);

-       return folio_pos(folio) + folio_page_idx(folio, page) * PAGE_SIZE;
+       return folio_pos(folio) + (folio_page_idx(folio, page) << 
PAGE_SHIFT);
  }

Yongpeng,

  reply	other threads:[~2025-11-04 15:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30  7:29 [PATCH v2] fscrypt: fix left shift underflow when inode->i_blkbits > PAGE_SHIFT Yongpeng Yang
2025-11-03 16:48 ` Eric Biggers
2025-11-04 11:12   ` Christoph Hellwig
2025-11-04 15:05     ` Yongpeng Yang [this message]
2025-11-05 13:38       ` Christoph Hellwig
2025-11-04 18:10     ` Eric Biggers
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=b8f06e62-27dc-462e-83ad-33b179daf8a2@gmail.com \
    --to=yangyongpeng.storage@gmail.com \
    --cc=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@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 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.