mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
	skhan@linuxfoundation.org, me@brighamcampbell.com,
	jkoolstra@xs4all.nl, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: x86/aes-gcm - fix always true check for last AAD segment
Date: Fri, 25 Sep 2026 21:49:05 -0700	[thread overview]
Message-ID: <20260926044905.GA11118@sol> (raw)
In-Reply-To: <20260926040614.8683-1-raizudeen.kerneldev@gmail.com>

On Sat, Sep 26, 2026 at 09:36:14AM +0530, Mohamad Raizudeen wrote:
> In gcm_process_assoc(), a segment that is not the last one must have its
> length rounded down to a multiple of 16 bytes, as required by the
> assembly. The check intended to detect a non-last segment,
> `if (unlikely(assoclen)) /* Not the last segment yet? */` is always
> true, since the loop only runs while assoclen is nonzero.
> 
> As a result the last segment was rounded down as well, leading to some
> avoidable extra work: an additional memcpy into the temporary buffer and
> an additional call into the assembly after the loop. The GCM
> authentication tag is unaffected either way, so the self-tests pass and
> this went unnoticed, its purely an efficiency issue rather than
> correctness one.
> 
> Fix this by comparing the length of the current step against the amount
> of AAD that remains, so that only a step which cannot consume all of the
> remaining bytes is treated as a non-last segment.
> 
> Fixes: b06affb1cb580 ("crypto: x86/aes-gcm - add VAES and AVX512 / AVX10 optimized AES-GCM")
> Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
> ---

Thanks for finding this!  Please use the correct Fixes commit and add Cc
stable:

    Fixes: e9787deff49e ("crypto: x86/aes-gcm - use the new scatterwalk functions")
    Cc: stable@vger.kernel.org

> -		if (unlikely(assoclen)) /* Not the last segment yet? */
> +		if (unlikely(len < assoclen)) /* Not the last segment yet? */
> 			len = round_down(len, 16);

Well, this is not correct either.  Let's just move
'assoclen -= orig_len_this_step;' to near the beginning of the loop
body, restoring the original logic prior to e9787deff49e.

- Eric

      reply	other threads:[~2026-09-26  4:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26  4:06 Mohamad Raizudeen
2026-09-26  4:49 ` Eric Biggers [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=20260926044905.GA11118@sol \
    --to=ebiggers@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=jkoolstra@xs4all.nl \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@brighamcampbell.com \
    --cc=raizudeen.kerneldev@gmail.com \
    --cc=skhan@linuxfoundation.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

all inboxes | Powered by JetHome®