From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: Re: [v4 PATCH 1/2] crypto: scatterwalk - Use nth_page instead of doing it by hand
Date: Sat, 15 Mar 2025 21:42:34 -0700 [thread overview]
Message-ID: <20250316044234.GD117195@sol.localdomain> (raw)
In-Reply-To: <Z9ZTaAjbWefXw6Dz@gondor.apana.org.au>
On Sun, Mar 16, 2025 at 12:28:24PM +0800, Herbert Xu wrote:
> On Sat, Mar 15, 2025 at 08:31:41PM -0700, Eric Biggers wrote:
> >
> > > @@ -189,14 +195,18 @@ static inline void scatterwalk_done_dst(struct scatter_walk *walk,
> > > * reliably optimized out or not.
> > > */
> > > if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE) {
> > > - struct page *base_page, *start_page, *end_page, *page;
> > > + struct page *base_page;
> > > + unsigned int offset;
> > > + int start, end, i;
> > >
> > > base_page = sg_page(walk->sg);
> > > - start_page = base_page + (walk->offset >> PAGE_SHIFT);
> > > - end_page = base_page + ((walk->offset + nbytes +
> > > - PAGE_SIZE - 1) >> PAGE_SHIFT);
> > > - for (page = start_page; page < end_page; page++)
> > > - flush_dcache_page(page);
> > > + offset = walk->offset;
> > > + start = offset >> PAGE_SHIFT;
> > > + end = start + (nbytes >> PAGE_SHIFT);
> > > + end += (offset_in_page(offset) + offset_in_page(nbytes) +
> > > + PAGE_SIZE - 1) >> PAGE_SHIFT;
> >
> > The change to how the end page index is calculated is unrelated to the nth_page
> > fix, and it makes the code slower and harder to understand. My original code
> > just rounded the new offset up to a page boundary to get the end page index.
>
> The original code is open to overflows in the addition. The new
> version is not.
If you think you are fixing a separate issue, you need to say so.
But I also don't think it's worth worrying about lengths so close to UINT_MAX.
No one is using them, they have no testing, and there are likely to be other
overflows like this one too.
- Eric
next prev parent reply other threads:[~2025-03-16 4:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 3:27 [v4 PATCH 0/2] crypto: Use nth_page instead of doing it by hand Herbert Xu
2025-03-14 3:27 ` [v4 PATCH 1/2] crypto: scatterwalk - " Herbert Xu
2025-03-16 3:31 ` Eric Biggers
2025-03-16 4:28 ` Herbert Xu
2025-03-16 4:42 ` Eric Biggers [this message]
2025-03-14 3:27 ` [v4 PATCH 2/2] crypto: hash " Herbert Xu
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=20250316044234.GD117195@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox