Re: [PATCH] lib/crypto: aes: use memzero_explicit() instead of memset()

From: Eric Biggers

Date: Tue Nov 03 2026 - 18:27:07 EST


On Wed, Oct 28, 2026 at 07:56:36PM +0530, Mohamad Raizudeen wrote:
> aes_gcm_decrypt() and aes_ccm_decrypt() use plain memset() to wipe the
> output buffer when authentication fails. But the compiler can optimize
> that wipe away, so use memzero_explicit() instead of memset().
>
> This matches every other sensitive wipes in this file, which already
> uses memzero_explicit() for keystream blocks, tmp buffers, ctx
> teardowns.
>
> Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@xxxxxxxxx>
> ---
> lib/crypto/aes.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

I added the following note:

[EB: I'm applying this mainly so this doesn't get flagged as an
inconsistency again. The main purpose of the zeroing here is just
so the caller doesn't accidentally use the data, which a plain
memset() is perfectly fine for. ]

- Eric