linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Marco Nelissen <marco.nelissen@gmail.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] filemap: avoid truncating 64-bit offset to 32 bits
Date: Thu, 2 Jan 2025 15:25:36 -0800	[thread overview]
Message-ID: <20250102232536.GW6174@frogsfrogsfrogs> (raw)
In-Reply-To: <20250102141015.bc8ef069a91cfd9664538494@linux-foundation.org>

On Thu, Jan 02, 2025 at 02:10:15PM -0800, Andrew Morton wrote:
> On Thu,  2 Jan 2025 11:04:11 -0800 Marco Nelissen <marco.nelissen@gmail.com> wrote:
> 
> > on 32-bit kernels, folio_seek_hole_data() was inadvertently truncating a
> > 64-bit value to 32 bits, leading to a possible infinite loop when writing
> > to an xfs filesystem.
> > 
> > ...
> >
> > +++ b/mm/filemap.c
> > @@ -3005,7 +3005,7 @@ static inline loff_t folio_seek_hole_data(struct xa_state *xas,
> >  		if (ops->is_partially_uptodate(folio, offset, bsz) ==
> >  							seek_data)
> >  			break;
> > -		start = (start + bsz) & ~(bsz - 1);
> > +		start = (start + bsz) & ~((u64)bsz - 1);
> >  		offset += bsz;
> >  	} while (offset < folio_size(folio));
> >  unlock:
> 
> Thanks.  I'll add
> 
> Fixes: 54fa39ac2e00b ("iomap: use mapping_seek_hole_data")
> Cc: <stable@vger.kernel.org>
> 
> The
> 
> 	offset = offset_in_folio(folio, start) & ~(bsz - 1);
> 
> a few lines earlier is worrisome.  I wonder if we should simply make
> `bsz' and `offset' have type u64 and sleep well at night.

I think that callsite is ok because offset_in_folio() should never
return a value larger than 2^31 ... right?  IOWs, only the second case
needs casting because @start is loff_t.

--D


      reply	other threads:[~2025-01-02 23:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02 19:04 Marco Nelissen
2025-01-02 22:10 ` Andrew Morton
2025-01-02 23:25   ` Darrick J. Wong [this message]

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=20250102232536.GW6174@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=marco.nelissen@gmail.com \
    --cc=willy@infradead.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