From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
x86@kernel.org, Nikunj A Dadhania <nikunj@amd.com>
Subject: Re: [PATCH] lib/crypto: aesgcm: Don't disable IRQs during AES block encryption
Date: Mon, 30 Mar 2026 22:02:34 -0700 [thread overview]
Message-ID: <20260331050234.GA4451@sol> (raw)
In-Reply-To: <20260331024430.51755-1-ebiggers@kernel.org>
[Added x86@kernel.org and nikunj@amd.com]
On Mon, Mar 30, 2026 at 07:44:30PM -0700, Eric Biggers wrote:
> aes_encrypt() now uses AES instructions when available instead of always
> using table-based code. AES instructions are constant-time and don't
> benefit from disabling IRQs as a constant-time hardening measure.
>
> In fact, on two architectures (arm and riscv) disabling IRQs is
> counterproductive because it prevents the AES instructions from being
> used. (See the may_use_simd() implementation on those architectures.)
>
> Therefore, let's remove the IRQ disabling/enabling and leave the choice
> of constant-time hardening measures to the AES library code.
>
> Note that currently the arm table-based AES code (which runs on arm
> kernels that don't have ARMv8 CE) disables IRQs, while the generic
> table-based AES code does not. So this does technically regress in
> constant-time hardening when that generic code is used. But as
> discussed in commit a22fd0e3c495 ("lib/crypto: aes: Introduce improved
> AES library") I think just leaving IRQs enabled is the right choice.
> Disabling them is slow and can cause problems, and AES instructions
> (which modern CPUs have) solve the problem in a much better way anyway.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
I just noticed the rationale in the patch series that originally added
lib/crypto/aesgcm.c in 2022
(https://lore.kernel.org/all/20221103192259.2229-1-ardb@kernel.org/):
Provide a generic library implementation of AES-GCM which can be
used really early during boot, e.g., to communicate with the
security coprocessor on SEV-SNP virtual machines to bring up
secondary cores. This is needed because the crypto API is not
available yet this early.
We cannot rely on special instructions for AES or polynomial
multiplication, which are arch specific and rely on in-kernel SIMD
infrastructure. Instead, add a generic C implementation that
combines the existing C implementations of AES and multiplication in
GF(2^128).
To reduce the risk of forgery attacks, replace data dependent table
lookups and conditional branches in the used gf128mul routine with
constant-time equivalents. The AES library has already been
robustified to some extent to prevent known-plaintext timing attacks
on the key, but we call it with interrupts disabled to make it a bit
more robust. (Note that in SEV-SNP context, the VMM is untrusted,
and is able to inject interrupts arbitrarily, and potentially
maliciously.)
So, the user of AES-GCM in arch/x86/coco/sev/ is a bit special. It runs
super early, before the crypto library initcalls have run and enabled
the use of AES-NI and PCLMULQDQ optimized routines. And apparently it
really needs protection from timing attacks, as well.
I think this patch is still the way to go, but it does slightly weaken
the protection from timing attacks for super early users like this. So
I think we'll likely want to do something else as well. Either:
- Disable IRQs in the callers in arch/x86/coco/sev/.
- Or, enable the AES-NI and PCLMULQDQ optimized crypto library routines
earlier on x86, so that they will be used in this case. Specifically,
enable them in arch_cpu_finalize_init() between fpu__init_cpu() and
mem_encrypt_init().
I'd prefer the latter. The dedicated instructions are the proper way to
get data and key-independent timing for AES-GCM. It's much less clear
that the generic C code has data and key-independent timing, even if
it's run with IRQs disabled.
Any thoughts?
- Eric
next prev parent reply other threads:[~2026-03-31 5:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 2:44 [PATCH] lib/crypto: aesgcm: Don't disable IRQs during AES block encryption Eric Biggers
2026-03-31 5:02 ` Eric Biggers [this message]
2026-03-31 7:05 ` Ard Biesheuvel
2026-03-31 20:55 ` Eric Biggers
2026-04-01 20:18 ` Eric Biggers
2026-04-02 23:11 ` Eric Biggers
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=20260331050234.GA4451@sol \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nikunj@amd.com \
--cc=x86@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