From: Eric Biggers <ebiggers@kernel.org>
To: Thomas Huth <thuth@redhat.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
Simo Sorce <simo@redhat.com>
Subject: Re: [PATCH v2 1/9] crypto: Provide a wrapper for zeroizing crypto_aes_ctx
Date: Mon, 3 Aug 2026 12:05:40 -0700 [thread overview]
Message-ID: <20260803190540.GD2062@quark> (raw)
In-Reply-To: <20260803094432.70505-2-thuth@redhat.com>
On Mon, Aug 03, 2026 at 11:44:20AM +0200, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
>
> Several crypto drivers need to zeroize their local crypto_aes_ctx
> structures after use to avoid leaking key material on the stack.
> Currently some call sites do this with their own memzero_explicit()
> call, which is error-prone since it is easy to miss a return path
> (what already happened in some drivers). Some other call sites miss
> to clear crypto_aes_ctx completely.
>
> Provide an aes_clear_ctx() helper that can be used with __cleanup()
> to automatically zeroize the context when it goes out of scope.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> include/crypto/aes.h | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/include/crypto/aes.h b/include/crypto/aes.h
> index 3279cfa546085..5ca7b1ab50e8c 100644
> --- a/include/crypto/aes.h
> +++ b/include/crypto/aes.h
> @@ -159,6 +159,19 @@ static inline int aes_check_keylen(size_t keylen)
> int aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,
> unsigned int key_len);
>
> +/**
> + * aes_clear_ctx - Zeroize a crypto_aes_ctx structure
> + * @ctx: The location of the context that should be zeroized
> + *
> + * Explicitly fills the crypto_aes_ctx with zeroes. This should be done
> + * once the context is not required anymore to avoid that its contents
> + * are leaked on the stack or heap.
> + */
> +static inline void aes_clear_ctx(struct crypto_aes_ctx *ctx)
> +{
> + memzero_explicit(ctx, sizeof(*ctx));
> +}
Acked-by: Eric Biggers <ebiggers@kernel.org>
I guess we should start using __cleanup with type-specific zeroization
functions like this more often. One gotcha is that __cleanup and 'goto'
should not be mixed in the same function; see the comment at
include/linux/cleanup.h line 148. Patch 8 of this series doesn't follow
that in safexcel_aead_setkey().
- Eric
next prev parent reply other threads:[~2026-08-03 19:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 9:44 [PATCH v2 0/9] crypto: Provide a function for zeroizing crypto_aes_ctx Thomas Huth
2026-08-03 9:44 ` [PATCH v2 1/9] crypto: Provide a wrapper " Thomas Huth
2026-08-03 19:05 ` Eric Biggers [this message]
2026-08-04 2:21 ` Simon Richter
2026-08-04 2:37 ` Eric Biggers
2026-08-04 7:42 ` Thomas Huth
2026-08-04 18:54 ` Eric Biggers
2026-08-03 9:44 ` [PATCH v2 2/9] crypto: aspeed - clear the crypto_aes_ctx when done Thomas Huth
2026-08-03 9:44 ` [PATCH v2 3/9] crypto: inside-secure/eip93 " Thomas Huth
2026-08-03 9:44 ` [PATCH v2 4/9] crypto: padlock-aes " Thomas Huth
2026-08-03 9:44 ` [PATCH v2 5/9] crypto: sa2ul " Thomas Huth
2026-08-03 9:44 ` [PATCH v2 6/9] crypto: arm/aes-neonbs " Thomas Huth
2026-08-03 9:44 ` [PATCH v2 7/9] crypto: arm64/aes-neonbs " Thomas Huth
2026-08-03 9:44 ` [PATCH v2 8/9] crypto: safexcel - zeroize crypto_aes_ctx with __cleanup(aes_clear_ctx) Thomas Huth
2026-08-03 9:44 ` [PATCH v2 9/9] crypto: qat " Thomas Huth
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=20260803190540.GD2062@quark \
--to=ebiggers@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simo@redhat.com \
--cc=thuth@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).