From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 030643B059C for ; Mon, 10 Aug 2026 09:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354226; cv=none; b=gd3EnzIRXDqsx5miD2xgc83UwmY03im57b/3SJBM3oFdA0aGaBl3wSLCCaGG3Oy0TmUSegSGF8CAcc6+gwtwSy93WYidiYX+cMxugJngFhUDu4+h+8l1CTACTswZPOYrIyGuPYxN9JZGKIq+GgDaHQcqqx/1KnPvKU6SzYT7FGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354226; c=relaxed/simple; bh=El7IzaMDWkQRBdqCf6D4Vf3bxHbeuZw27aOMI6pHWuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rlr4dGVSeOPlyAxCEEK1XI0KiR2GFMjmgf9ldZo/oBhERUB0atWR/lvBQS21fnfHX68sXSe3zEwe6UvCW+cuLdS/PDlwO3WyrmhYAeHQMCUFF5OG9lfwq81QGn6w9ztTIs96Q13B6xss57uBn476HQ/EXnGlimcQhTG1oCdEH7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=evfKjJ4v; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="evfKjJ4v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FBdlBWEfW4WZn7IIRYi3s7HZuga9kryjgjm+NiKtMPY=; b=evfKjJ4vaiMk9dlCHyooI+Bd10N26+zLpVVwvRQK47KZh2WTwN/neQZC2zrgMetKxeK3zv BaZCaI/Q/d6sTkYW/e9zmTYsQ+nR02dt5PkJxn+cS5twpiKDdZiJtfCHRtU1rSibwpscQK NOFeXP3ZtLbSW/rFTtkUZgjNpkTMa5U= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-dUQHHiaePL6-0D7U3oJ5kw-1; Mon, 10 Aug 2026 05:30:18 -0400 X-MC-Unique: dUQHHiaePL6-0D7U3oJ5kw-1 X-Mimecast-MFC-AGG-ID: dUQHHiaePL6-0D7U3oJ5kw_1786354217 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DA71E1956058; Mon, 10 Aug 2026 09:30:16 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 859953001D38; Mon, 10 Aug 2026 09:30:14 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart Subject: [PATCH v5 01/10] crypto: Provide a wrapper function for zeroizing crypto_aes_ctx Date: Mon, 10 Aug 2026 11:29:56 +0200 Message-ID: <20260810093009.608090-2-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth 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_zeroize_ctx() helper that can be used with __cleanup() to automatically zeroize the context when it goes out of scope. Acked-by: Eric Biggers Signed-off-by: Thomas Huth --- include/crypto/aes.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 3279cfa546085..e70607249ae5c 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); =20 +/** + * aes_zeroize_ctx - Clear 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 (if not using kfree_sensitive()). + */ +static inline void aes_zeroize_ctx(struct crypto_aes_ctx *ctx) +{ + memzero_explicit(ctx, sizeof(*ctx)); +} + /* * The following functions are temporarily exported for use by the AES mode * implementations in arch/$(SRCARCH)/crypto/. These exports will go away= when --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2941A3B05B1 for ; Mon, 10 Aug 2026 09:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354234; cv=none; b=er5Q3uTV04yjTvXxVIHPrMnn7TSbfAs/3YzFyHgI/0yH4ab+lg1dQxe3K1yRrb4JMtCUm8Mtb3Mkc6NLpNDnENdDQZOpfjSZQ44rZJEOlWyhwZnqxjdbQOKhhk1dufaKRvF4wWKkABu08340ikbqcldG5Z1WsbOL+F2NjPBB3HQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354234; c=relaxed/simple; bh=WVt0qQ4+1eH0aK8H3LOcQUCnNbq+Qzdzr1yi2CdD+9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cQnDdgUBUlcT7DyD1IRolv1YATDjXf5jx1MI0KmAY3fgxt5URRJ+kO1NSyJK3GTwF61BcVZmB6rfniJdoTcvANNcnktbrnIQPht2S4A5822VL3+Rtpis/SxJxQQYp/qu9mYY9eWKWeJCBqVnpCpBphbJbG0lCfc7uFoFEepGmiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=C6PxrgYB; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C6PxrgYB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rFuj09l13bDJWP8ROOQNO6DWGBJe5ddETVvR3frCMgU=; b=C6PxrgYBUL3Df0ncq5VyYMm1OvxGkESCn4CTtDm9Xs7PXHWWgLGhCQPLiqKPnLVATkw+Lx Y41Od62aFJIuG2Lh97gemI13Dh7yOibZX7HZYEF2d5LvXNgWaizg+RicORL0eCRBLzpM5A n9FfyGrRBg24FkjV6myJ1l8iylw5Qb4= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-U7rsMKF7Nkq7P_7Ivsxu4g-1; Mon, 10 Aug 2026 05:30:25 -0400 X-MC-Unique: U7rsMKF7Nkq7P_7Ivsxu4g-1 X-Mimecast-MFC-AGG-ID: U7rsMKF7Nkq7P_7Ivsxu4g_1786354224 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 324011800846; Mon, 10 Aug 2026 09:30:23 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0BF853001D38; Mon, 10 Aug 2026 09:30:17 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Neal Liu , Joel Stanley , Andrew Jeffery Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart , linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 02/10] crypto: aspeed - clear the crypto_aes_ctx when done Date: Mon, 10 Aug 2026 11:29:57 +0200 Message-ID: <20260810093009.608090-3-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Declare the gen_aes_key with __cleanup(aes_zeroize_ctx) to avoid that its contents could be leaking via the stack when the function returns. And since it is only required in one branch of the if-statement there, move it to that block, too. Signed-off-by: Thomas Huth --- drivers/crypto/aspeed/aspeed-hace-crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/aspeed/aspeed-hace-crypto.c b/drivers/crypto/as= peed/aspeed-hace-crypto.c index fa201dae1f81b..e7d3f611df05c 100644 --- a/drivers/crypto/aspeed/aspeed-hace-crypto.c +++ b/drivers/crypto/aspeed/aspeed-hace-crypto.c @@ -576,7 +576,6 @@ static int aspeed_aes_setkey(struct crypto_skcipher *ci= pher, const u8 *key, { struct aspeed_cipher_ctx *ctx =3D crypto_skcipher_ctx(cipher); struct aspeed_hace_dev *hace_dev =3D ctx->hace_dev; - struct crypto_aes_ctx gen_aes_key; =20 CIPHER_DBG(hace_dev, "keylen: %d bits\n", (keylen * 8)); =20 @@ -585,9 +584,9 @@ static int aspeed_aes_setkey(struct crypto_skcipher *ci= pher, const u8 *key, return -EINVAL; =20 if (ctx->hace_dev->version =3D=3D AST2500_VERSION) { + struct crypto_aes_ctx gen_aes_key __cleanup(aes_zeroize_ctx); aes_expandkey(&gen_aes_key, key, keylen); memcpy(ctx->key, gen_aes_key.key_enc, AES_MAX_KEYLENGTH); - } else { memcpy(ctx->key, key, keylen); } --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32473AFCE9 for ; Mon, 10 Aug 2026 09:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354233; cv=none; b=ibGl3Ov9NbhxQ7CMdT+PrqBMvzozkK30gWQjHXS68rhAO+0iVXGRVnMpt55oL/HsHTdCbldI7ugOyzgxLHIUPMPZnH0yaoS+G2mKvCu5ubqkdlPLxTfiec3xPeJeg4NpGiR1gy4lCvbMff+nOdgHFcU02zqylO4o705P/pFce2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354233; c=relaxed/simple; bh=rrHOeIvGuTbxvBxf0sD+S1Wa6q8TEDfmgAXE4+BZst4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=egQ5aH15PUfw48nomn514WEQ+OwDnfIY3OKFDwpMErEkDojTacaK97oFcjN0+roPCQoVOqxTQ37+n+Io+SwSb3rvZ31tqB1l/SyIRY8x/3ye/GCL49exSwNYMiKPN25iC5HtHx/GPVOHBhNSE0uN4C9XbxwkqMKP9YEbqZEatDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fVMgwa6C; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fVMgwa6C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dFIxmKcUsq1WalhKwXv0wsQgLSJrF7IelNY2pEdEa3U=; b=fVMgwa6CF6PbcugPPqeVLnfzqHZQ1OzZIhgB9qt08XTP/eRyb6V8MfzJSwRz3K9cMWUeZ3 yuT4Y3WIffJVhpY1sbHfqH42PJ1u5luH9QcjZoh4C/Q76JNtinYYX50u+5JReh810bTOel xm+FRpJMkJjietmHlzus+SE2pz+CdTg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-fO72Sv4ONtWyLKSWRw1G6w-1; Mon, 10 Aug 2026 05:30:27 -0400 X-MC-Unique: fO72Sv4ONtWyLKSWRw1G6w-1 X-Mimecast-MFC-AGG-ID: fO72Sv4ONtWyLKSWRw1G6w_1786354226 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CF51195608F; Mon, 10 Aug 2026 09:30:26 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E84EC3001D3A; Mon, 10 Aug 2026 09:30:23 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart Subject: [PATCH v5 03/10] crypto: padlock-aes - clear the crypto_aes_ctx when done Date: Mon, 10 Aug 2026 11:29:58 +0200 Message-ID: <20260810093009.608090-4-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_zeroize_ctx) when we're done with it to avoid that key data could leak on the stack. And since __cleanup() (and __free()) should not be mixed with "gotos" in the same function, turn the goto statement here into a proper block of the related if-statement. Signed-off-by: Thomas Huth --- drivers/crypto/padlock-aes.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c index 1be549a07a219..400a889e924d7 100644 --- a/drivers/crypto/padlock-aes.c +++ b/drivers/crypto/padlock-aes.c @@ -109,7 +109,7 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8= *in_key, { struct aes_ctx *ctx =3D aes_ctx(tfm); const __le32 *key =3D (const __le32 *)in_key; - struct crypto_aes_ctx gen_aes; + struct crypto_aes_ctx gen_aes __cleanup(aes_zeroize_ctx); int cpu; =20 if (key_len % 8) @@ -137,20 +137,18 @@ static int aes_set_key(struct crypto_tfm *tfm, const = u8 *in_key, ctx->cword.decrypt.ksize =3D ctx->cword.encrypt.ksize; =20 /* Don't generate extended keys if the hardware can do it. */ - if (aes_hw_extkey_available(key_len)) - goto ok; + if (!aes_hw_extkey_available(key_len)) { + ctx->D =3D ctx->d_data; + ctx->cword.encrypt.keygen =3D 1; + ctx->cword.decrypt.keygen =3D 1; =20 - ctx->D =3D ctx->d_data; - ctx->cword.encrypt.keygen =3D 1; - ctx->cword.decrypt.keygen =3D 1; + if (aes_expandkey(&gen_aes, in_key, key_len)) + return -EINVAL; =20 - if (aes_expandkey(&gen_aes, in_key, key_len)) - return -EINVAL; - - memcpy(ctx->E, gen_aes.key_enc, AES_MAX_KEYLENGTH); - memcpy(ctx->D, gen_aes.key_dec, AES_MAX_KEYLENGTH); + memcpy(ctx->E, gen_aes.key_enc, AES_MAX_KEYLENGTH); + memcpy(ctx->D, gen_aes.key_dec, AES_MAX_KEYLENGTH); + } =20 -ok: for_each_online_cpu(cpu) if (&ctx->cword.encrypt =3D=3D per_cpu(paes_last_cword, cpu) || &ctx->cword.decrypt =3D=3D per_cpu(paes_last_cword, cpu)) --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45B063B05BA for ; Mon, 10 Aug 2026 09:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354239; cv=none; b=DkCPl8rIKwPpjt0JcJ1pFDL69DOec3fCF4Lk3J8vcgsa3uAn9hRXWKOzXPxsgLn57o9cyZK6PINs2sb4ZTgS9PJbLVPqcT4keUpYAl1zS6uNVAZRq0QCizJsy6YxNiE4vdhfF0y5l00CvlVA2M8EbZpp8f6+yWy33VPFiGo39/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354239; c=relaxed/simple; bh=H51eEndb83vlMBdSKdQPCJs4a0NhTn4ra/iT1GUYwIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C/KWE7Vt+m8Cs/aRV/1xk7Ui6oivgHclIDf4smHcF2FHqxgeAOywSfQwsnJXQvqM+XSkp6xajQd2rj9YlBdALfZgUX0y0XW8v5p8gYMnoEOJIrce6kQqpiU6uDPygTGfh/E39YA+b/2HVsfiGYx2jh/ADRjJUL/L4ul1woiQAGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DtdL/DIi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DtdL/DIi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UgOea8COfMWPGkNwdk17UcXroZGUrewDpcR0b9Y5VNk=; b=DtdL/DIiyk+9DXpRPS9qvpjVL8CRGVc/HjQQPv3fVLVrUoxhxbmr+SeeTByUamNyYt1i9c UfibudMsCAL3B2RNSEuGIK4rkYMlCcI6GQH31aFuT8eikt83QotTQd93swVFThvnnAQu8b Db+R2xvY/9ULIN6bRQr2dnD3qhDmoQo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-WhMXaSr1MJ-7amixPsaTGA-1; Mon, 10 Aug 2026 05:30:30 -0400 X-MC-Unique: WhMXaSr1MJ-7amixPsaTGA-1 X-Mimecast-MFC-AGG-ID: WhMXaSr1MJ-7amixPsaTGA_1786354229 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5035D180075E; Mon, 10 Aug 2026 09:30:29 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 306B93001D38; Mon, 10 Aug 2026 09:30:26 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart Subject: [PATCH v5 04/10] crypto: sa2ul - clear the crypto_aes_ctx when done Date: Mon, 10 Aug 2026 11:29:59 +0200 Message-ID: <20260810093009.608090-5-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_zeroize_ctx) when we're done with it to avoid that key data could leak on the stack. Signed-off-by: Thomas Huth --- drivers/crypto/sa2ul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c index d865fd4a098cb..f1a7c2cc7a1af 100644 --- a/drivers/crypto/sa2ul.c +++ b/drivers/crypto/sa2ul.c @@ -465,7 +465,7 @@ static void sa_prepare_iopads(struct algo_data *data, c= onst u8 *key, /* Derive the inverse key used in AES-CBC decryption operation */ static inline int sa_aes_inv_key(u8 *inv_key, const u8 *key, u16 key_sz) { - struct crypto_aes_ctx ctx; + struct crypto_aes_ctx ctx __cleanup(aes_zeroize_ctx); int key_pos; =20 if (aes_expandkey(&ctx, key, key_sz)) { --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A840F3B05AB for ; Mon, 10 Aug 2026 09:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354241; cv=none; b=uwi8okKnbeVvxlAra2BRwd0/uASlriDLEvWRLPCB/VdUgeTpuGXibciWoCmtdqj6NXPj/LdWY0twZJ0bU5qLuIbnTm1BZQhQh598lmGkhgrk9K5LAnbPfj4CaLOJJVGxDrUXTyptBMwKs5gCYNPVYtgqzp3D8+r9h0q5gzW/Kac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354241; c=relaxed/simple; bh=b5aZNIDCHkvfoWtjbjEcQ7aD9yQG5oyRD+0JfQ4XMl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kJmYqw+erLJhtsJWRAWVGNwYUgtBn//M20qDeR8uLZujqtu4AZXRMMvqZCkavEMAnBDL8vN1f1VMjyHERQpGPwX3DJbFLM7u5cwo4sfFcoFWxQN6v1csypkGpzYdpNE5AObGdUET1AWhEBZ0F+UPJR7r4WJ6nLjM3BK6DgGUdHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LIpAiikA; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LIpAiikA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vqj916x7IWEPwY8/O5oc6WAr80znZJ+nk/7CTdbfDAQ=; b=LIpAiikA2XD825oaeTxdpqbL0La1HmUU+fQoCB8QTL13MrHyy8k68omyk/OZzVlWjCYqQ4 zs25x1kYtJhHqVP0Taq/Vt/QezhavdxlBlc9OEjj4nWErZEca3SZRQ3auwTqtP8zDPPbZg S+un0xEkp6L9pbidgOUvEDGWRGPJIJk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-1bpIgU8CMXGcJ8ZkQtFrtw-1; Mon, 10 Aug 2026 05:30:35 -0400 X-MC-Unique: 1bpIgU8CMXGcJ8ZkQtFrtw-1 X-Mimecast-MFC-AGG-ID: 1bpIgU8CMXGcJ8ZkQtFrtw_1786354233 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 715B71800115; Mon, 10 Aug 2026 09:30:33 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 13DE33001D38; Mon, 10 Aug 2026 09:30:29 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Russell King Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 05/10] crypto: arm/aes-neonbs - clear the crypto_aes_ctx when done Date: Mon, 10 Aug 2026 11:30:00 +0200 Message-ID: <20260810093009.608090-6-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_zeroize_ctx) when we're done with it to avoid that key data could leak on the stack. Signed-off-by: Thomas Huth --- arch/arm/crypto/aes-neonbs-glue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/crypto/aes-neonbs-glue.c b/arch/arm/crypto/aes-neonbs= -glue.c index c49ddafc54f34..f0c8bfd2ac8fc 100644 --- a/arch/arm/crypto/aes-neonbs-glue.c +++ b/arch/arm/crypto/aes-neonbs-glue.c @@ -60,7 +60,7 @@ static int aesbs_setkey(struct crypto_skcipher *tfm, cons= t u8 *in_key, unsigned int key_len) { struct aesbs_ctx *ctx =3D crypto_skcipher_ctx(tfm); - struct crypto_aes_ctx rk; + struct crypto_aes_ctx rk __cleanup(aes_zeroize_ctx); int err; =20 err =3D aes_expandkey(&rk, in_key, key_len); --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A6CD3B05B9 for ; Mon, 10 Aug 2026 09:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354245; cv=none; b=kNqifPHUosm6RxQe5qf2oQri5lRMuS5EzdudM8botFrPE7+YnhUGHggE4P7MpqUcVcYb8mIhtdSLgmqgF6zBHSguhnw2LOn5DOBEeE83h3DYxaqaOOknQCVl9cD/cTXv/p3mwmirVlKS9Q2hedz9Kw/45F0FzxqrddqNZ6KYF9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354245; c=relaxed/simple; bh=TXi1E78cjlAEwfYKo16gnIGsjCugY7q4hnj/efQOZ4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q4Oy3LbhZC1sfcejKU/UYL6pgSIN6vNOzBtNu91WLscs8Xhgiqgjj9ClMJSfh9XaM4nSpWmM4j31o1pzzVhfixZA/7pF/Z1oMyEd7iogLXYGF6UjMuP6LIzSw5AdAyk4p24H34oEVJrXMa5cerAat0BrRnjIWs2AUpPzo9mZ4xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Z56M4ucp; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z56M4ucp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D6NyyqK7KlyD8z4FwO/BXzdfa/BL5mjoIdYzF1ekpFM=; b=Z56M4ucpcMXhRKO8ulDKTS5j6hKhcKe0EiRGmXcBJs/jkMgpjuIMFh+PhJfNK1X1ciEoGV 15axGU2+MkhFYL2DmNQ6+a7hrTClKjL70UuOc93ta3bIKIEKy4J4P1YdbctPuGXT/Jhw8J Isk/ZDLa71cd5/GqzwtPTcDkRs+M/Tw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-_HJPmvf_OV6lUCEBUl9rBQ-1; Mon, 10 Aug 2026 05:30:39 -0400 X-MC-Unique: _HJPmvf_OV6lUCEBUl9rBQ-1 X-Mimecast-MFC-AGG-ID: _HJPmvf_OV6lUCEBUl9rBQ_1786354238 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B91A01955DB0; Mon, 10 Aug 2026 09:30:37 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D8973001D38; Mon, 10 Aug 2026 09:30:34 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 06/10] crypto: arm64/aes-neonbs - clear the crypto_aes_ctx when done Date: Mon, 10 Aug 2026 11:30:01 +0200 Message-ID: <20260810093009.608090-7-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_zeroize_ctx) when we're done with it to avoid that key data could leak on the stack. Signed-off-by: Thomas Huth --- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-ne= onbs-glue.c index 5bcbac9798931..c2f3eac0ca661 100644 --- a/arch/arm64/crypto/aes-neonbs-glue.c +++ b/arch/arm64/crypto/aes-neonbs-glue.c @@ -247,7 +247,7 @@ static int aesbs_xts_setkey(struct crypto_skcipher *tfm= , const u8 *in_key, unsigned int key_len) { struct aesbs_xts_ctx *ctx =3D crypto_skcipher_ctx(tfm); - struct crypto_aes_ctx rk; + struct crypto_aes_ctx rk __cleanup(aes_zeroize_ctx); int err; =20 err =3D xts_verify_key(tfm, in_key, key_len); --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EE2B3B0AEF for ; Mon, 10 Aug 2026 09:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354251; cv=none; b=QZHL8UNzBMEFjZz4386+ITyZCHjsbRginFfXt57tp8oku+xaCyINQ/PVFTLYHh0duJLFocUA75hWOCNtCHH/+ZpZZx/4FPsrBPsK4hC1gtlVQ+taEArRBKzGuBOvmQihtaHMpHyX3bcZSgs5x44UPvBwOHBzIWrzAv6W/dca000= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354251; c=relaxed/simple; bh=ll7c2R5VX3v6+Fl2r+qzo4RuiBEEIU3wp8x51vbCOds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oyhFVWiu7y29Lg7XAPW1VBlHUuRtlBXCNH1bNxOL/HTD7CulprkCsfEPkyUQ59g59wr1UUMRBlhiB9osOt5/9gX+lLUpqKmOD2X22JBLmc3kQ375dP7A766PyzcGqip/6t3x4e/6BW9p19Fo6haGhswXuOPQvIR+znZdi64bOfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JwszL6pq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JwszL6pq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+uzNBxCm8TygHEsuvoTt/jMmagg8F1gKPzJZMx41fv8=; b=JwszL6pqTtJif6M3QKJnF+nwgFpT8cbCqPES4i/9Mwnmp/OWd0iq4WwL1jPUjd5QydRCDx FJlRWomhY6HPV8XCAaRDJL3Mg4BIYWy5de/fcJiRaz7KJ2tCmzIIfNdhYg6y/Dwh4yHlv9 clfIqjF87cexpntMB8/peguFIKBtnvs= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-aLkbJ_1bMdePKXMMNg6SYw-1; Mon, 10 Aug 2026 05:30:42 -0400 X-MC-Unique: aLkbJ_1bMdePKXMMNg6SYw-1 X-Mimecast-MFC-AGG-ID: aLkbJ_1bMdePKXMMNg6SYw_1786354241 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 68E1B19560B3; Mon, 10 Aug 2026 09:30:41 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7779A3001DAF; Mon, 10 Aug 2026 09:30:38 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Giovanni Cabiddu Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org, Antoine Tenart , qat-linux@intel.com Subject: [PATCH v5 07/10] crypto: qat - zeroize crypto_aes_ctx with __cleanup(aes_zeroize_ctx) Date: Mon, 10 Aug 2026 11:30:02 +0200 Message-ID: <20260810093009.608090-8-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth A recent patch by Giovanni Cabiddu already added a memzero_explicit() for the crypto_aes_ctx in the qat_alg_xts_reverse_key() function, but since we introduced __cleanup(aes_zeroize_ctx) markers in previous commits in many spots of the code already, let's use it here now, too, to have the same code pattern everywhere. Signed-off-by: Thomas Huth --- drivers/crypto/intel/qat/qat_common/qat_algs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_algs.c b/drivers/crypt= o/intel/qat/qat_common/qat_algs.c index 91663805d9e60..cb669fb661625 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_algs.c +++ b/drivers/crypto/intel/qat/qat_common/qat_algs.c @@ -388,7 +388,7 @@ static void qat_alg_skcipher_init_enc(struct qat_alg_sk= cipher_ctx *ctx, static void qat_alg_xts_reverse_key(const u8 *key_forward, unsigned int ke= ylen, u8 *key_reverse) { - struct crypto_aes_ctx aes_expanded; + struct crypto_aes_ctx aes_expanded __cleanup(aes_zeroize_ctx); int nrounds; u8 *key; =20 @@ -405,7 +405,6 @@ static void qat_alg_xts_reverse_key(const u8 *key_forwa= rd, unsigned int keylen, memcpy(key_reverse + AES_BLOCK_SIZE, key - AES_BLOCK_SIZE, AES_BLOCK_SIZE); } - memzero_explicit(&aes_expanded, sizeof(aes_expanded)); } =20 static void qat_alg_skcipher_init_dec(struct qat_alg_skcipher_ctx *ctx, --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DC113B3BF5 for ; Mon, 10 Aug 2026 09:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354254; cv=none; b=qkcM2m2kYkTvWsFyl5xYI2mRBWlvX0k5h9TOOaGApdQ9VUZv3q0QvdU5Kxskk4yADovLkkDn1V2havLwaVwryUgL9uPh2m6W8pyMTIMf9AqtBB6JqKWiRieufA4saL/x+yANisHBF1QxG9phxL5hNkGmgTkbxkYUyr0N+/H5Iks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354254; c=relaxed/simple; bh=0OpdUhVbbXBoRIbpB5mfrAmwF4IesghjJtKgHGPvd5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KwY9OrKmlTwn8nL+8ndQLZnXrj4JcwLih/3Lf+p6NOAzKfK3x1A8kng6MlVf8q6Oi4E7nidHQJxaStclNF/dF9FT3boC2VL9rhKuu3L4Ae1KI91LRQbb+M3JpV6jCZOQX7hu4zyAiO8POZPD0u7fAArAlozn35WqPfFURga+cWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ul4YX+3o; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ul4YX+3o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O7XDseE2m1TmA6tZncYGgA9JdA6mmPokf7dLTiKrG+Y=; b=Ul4YX+3oa7yxZYcPR0APrGTytfXXa4tXjMC+9620I9Au29U+bC/YPFb0mpcnq3xcDpEjoj 8DeGywMDL8X0W3xcfijPNzLrG5Et8gRshm5CkuHRMGNFhNVt1q637acEDYV5NaBgjLpjpw Fl15YYio1e9wztzUa1i0cabxJaxiQXc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-htGM6jHWMiObNZ3vmr3_Ww-1; Mon, 10 Aug 2026 05:30:45 -0400 X-MC-Unique: htGM6jHWMiObNZ3vmr3_Ww-1 X-Mimecast-MFC-AGG-ID: htGM6jHWMiObNZ3vmr3_Ww_1786354244 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9E76519560B2; Mon, 10 Aug 2026 09:30:44 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 835573001DAF; Mon, 10 Aug 2026 09:30:42 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Antoine Tenart Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org Subject: [PATCH v5 08/10] crypto: safexcel - Simplify the check for a valid AES key Date: Mon, 10 Aug 2026 11:30:03 +0200 Message-ID: <20260810093009.608090-9-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth safexcel_aead_setkey() currently uses aes_expandkey() to check for a valid AES key, but then does not use the crypto_aes_ctx afterwards anymore, i.e. this is just a wasteful way of checking the key length, and thus aes_check_keylen() should be used instead. This also fixes a potential leak of sensitive data via the stack, since this function forgot to zeroize crypto_aes_ctx before returning to the caller. Suggested-by: Antoine Tenart Signed-off-by: Thomas Huth Acked-by: Antoine Tenart --- drivers/crypto/inside-secure/safexcel_cipher.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypt= o/inside-secure/safexcel_cipher.c index a8349b684693e..f07d043c67d45 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -407,7 +407,6 @@ static int safexcel_aead_setkey(struct crypto_aead *ctf= m, const u8 *key, struct safexcel_cipher_ctx *ctx =3D crypto_tfm_ctx(tfm); struct safexcel_crypto_priv *priv =3D ctx->base.priv; struct crypto_authenc_keys keys; - struct crypto_aes_ctx aes; int err =3D -EINVAL, i; const char *alg; =20 @@ -438,7 +437,7 @@ static int safexcel_aead_setkey(struct crypto_aead *ctf= m, const u8 *key, goto badkey; break; case SAFEXCEL_AES: - err =3D aes_expandkey(&aes, keys.enckey, keys.enckeylen); + err =3D aes_check_keylen(keys.enckeylen); if (unlikely(err)) goto badkey; break; --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63EE73B42D3 for ; Mon, 10 Aug 2026 09:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354255; cv=none; b=oz+9WgycxmjtoJ+WE8aT+AqRW6s74RVAEtHL0mEKCL3DyVgr3nDS5SXSlvCNsXQQyVEdfLKytbBySvOeyDxvXE7B2zA7DQp3u0VQ3hEkQZJf+Uixx+kHmIdUuqrteYk5rshg/B40TIZxHWWkKb/uvE9UpdviUpy/+VmWuZYgXj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354255; c=relaxed/simple; bh=mRIq6aOo8Xre5dmapUQRuqQO2Rgcce3ztC5/CcVoVP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nnk3VQ5I9AGM1j+wWo1yjyZIeGqGB/fZpVfHn0uJNDUQ5Qxc2fE+9ZaO0nDY8knaAKWaAaIQAr9VSsWBqSkQzQ65Z00adWv0fk34D2WuLsoC0zDGKUPceKDgd+UFKSJVCI1AmXDKJ70u95+TQ2fMhnx1pTHHJpD7I5EK2o/GDH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eS+Wbfq9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eS+Wbfq9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hCtTLF0JiWbnDet+pboh6iIiYU7Zl/uxYrEoLKTK9go=; b=eS+Wbfq971JOe1FEA6OvU+9G6srIE0fw54ZIitjR5vcKFtHQYWfci/rC3fU9avSYGXwUb5 RR++n61pzwX1LNz+i8KcGSRIY+I5YZruWpksYhj+gi1G/1X7i8Ezx0GW6mofIsdifOW4bj H9NIMWYFdGZUUfJ0hCFbp0jWwG4l8UI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-bF_nFi62OGCUcFDDhaZobw-1; Mon, 10 Aug 2026 05:30:49 -0400 X-MC-Unique: bF_nFi62OGCUcFDDhaZobw-1 X-Mimecast-MFC-AGG-ID: bF_nFi62OGCUcFDDhaZobw_1786354248 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9023195608E; Mon, 10 Aug 2026 09:30:47 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB4BB3001D38; Mon, 10 Aug 2026 09:30:45 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Antoine Tenart Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org Subject: [PATCH v5 09/10] crypto: safexcel - zeroize crypto_aes_ctx with __cleanup(aes_zeroize_ctx) Date: Mon, 10 Aug 2026 11:30:04 +0200 Message-ID: <20260810093009.608090-10-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth The code clears the crypto_aes_ctx in most cases already with memzero_explicit(), but safexcel_skcipher_aesxts_setkey() runs aes_expandkey() twice, and in case the second call fails, the context from the first call is leaked. To fix this issue and to avoid future similar problems, let's use the new __cleanup(aes_zeroize_ctx) mechanism to make sure that we always clear the crypto_aes_ctx in all cases. Acked-by: Antoine Tenart Signed-off-by: Thomas Huth --- drivers/crypto/inside-secure/safexcel_cipher.c | 13 ++++--------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypt= o/inside-secure/safexcel_cipher.c index f07d043c67d45..b031cb9652ec3 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -375,7 +375,7 @@ static int safexcel_skcipher_aes_setkey(struct crypto_s= kcipher *ctfm, struct crypto_tfm *tfm =3D crypto_skcipher_tfm(ctfm); struct safexcel_cipher_ctx *ctx =3D crypto_tfm_ctx(tfm); struct safexcel_crypto_priv *priv =3D ctx->base.priv; - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_zeroize_ctx); int ret, i; =20 ret =3D aes_expandkey(&aes, key, len); @@ -396,7 +396,6 @@ static int safexcel_skcipher_aes_setkey(struct crypto_s= kcipher *ctfm, =20 ctx->key_len =3D len; =20 - memzero_explicit(&aes, sizeof(aes)); return 0; } =20 @@ -1361,7 +1360,7 @@ static int safexcel_skcipher_aesctr_setkey(struct cry= pto_skcipher *ctfm, struct crypto_tfm *tfm =3D crypto_skcipher_tfm(ctfm); struct safexcel_cipher_ctx *ctx =3D crypto_tfm_ctx(tfm); struct safexcel_crypto_priv *priv =3D ctx->base.priv; - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_zeroize_ctx); int ret, i; unsigned int keylen; =20 @@ -1387,7 +1386,6 @@ static int safexcel_skcipher_aesctr_setkey(struct cry= pto_skcipher *ctfm, =20 ctx->key_len =3D keylen; =20 - memzero_explicit(&aes, sizeof(aes)); return 0; } =20 @@ -2541,7 +2539,7 @@ static int safexcel_skcipher_aesxts_setkey(struct cry= pto_skcipher *ctfm, struct crypto_tfm *tfm =3D crypto_skcipher_tfm(ctfm); struct safexcel_cipher_ctx *ctx =3D crypto_tfm_ctx(tfm); struct safexcel_crypto_priv *priv =3D ctx->base.priv; - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_zeroize_ctx); int ret, i; unsigned int keylen; =20 @@ -2589,7 +2587,6 @@ static int safexcel_skcipher_aesxts_setkey(struct cry= pto_skcipher *ctfm, =20 ctx->key_len =3D keylen << 1; =20 - memzero_explicit(&aes, sizeof(aes)); return 0; } =20 @@ -2755,12 +2752,11 @@ static int safexcel_aead_ccm_setkey(struct crypto_a= ead *ctfm, const u8 *key, struct crypto_tfm *tfm =3D crypto_aead_tfm(ctfm); struct safexcel_cipher_ctx *ctx =3D crypto_tfm_ctx(tfm); struct safexcel_crypto_priv *priv =3D ctx->base.priv; - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_zeroize_ctx); int ret, i; =20 ret =3D aes_expandkey(&aes, key, len); if (ret) { - memzero_explicit(&aes, sizeof(aes)); return ret; } =20 @@ -2789,7 +2785,6 @@ static int safexcel_aead_ccm_setkey(struct crypto_aea= d *ctfm, const u8 *key, else ctx->hash_alg =3D CONTEXT_CONTROL_CRYPTO_ALG_XCBC128; =20 - memzero_explicit(&aes, sizeof(aes)); return 0; } =20 diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/= inside-secure/safexcel_hash.c index 3402e570d045c..20c17eb09495e 100644 --- a/drivers/crypto/inside-secure/safexcel_hash.c +++ b/drivers/crypto/inside-secure/safexcel_hash.c @@ -1905,7 +1905,7 @@ static int safexcel_cbcmac_setkey(struct crypto_ahash= *tfm, const u8 *key, unsigned int len) { struct safexcel_ahash_ctx *ctx =3D crypto_tfm_ctx(crypto_ahash_tfm(tfm)); - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_zeroize_ctx); int ret, i; =20 ret =3D aes_expandkey(&aes, key, len); @@ -1928,7 +1928,6 @@ static int safexcel_cbcmac_setkey(struct crypto_ahash= *tfm, const u8 *key, } ctx->cbcmac =3D true; =20 - memzero_explicit(&aes, sizeof(aes)); return 0; } =20 --=20 2.55.0 From nobody Tue Sep 29 09:08:14 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF18E3B6341 for ; Mon, 10 Aug 2026 09:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354259; cv=none; b=M1XgoRrAyXTNGqnkbWPF/NgvlYkeHI37Yx7GxrxMr6zu7kYOVvyX3m9C4cdpTF3nDN/fwp+PunwPOJoONS6ZqPVnKwHNrR98p9p/tKLC0cyrfiUpkN7Z66O/Q+J64wEVXB0c9uQ+dARh9TYlrQxmdDSJx2NvQ076MZ0LwsIFd/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354259; c=relaxed/simple; bh=AvdIm6Ui0tKhNtJ8JmYLXzg5tYfY6zHY3E/mVVY4STI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qn27eHQalCGegmSf+0qp2fO9n4ZasV/FR56aIj7snoHzDfEaYZjfgCtaVFOxirqJjFQn2rjf5Z/rvVHQRH35fMUVPEDzGDah/C+sHTLK/cqQaqFnyE/kfeHnGbDcn2cNlmYzzAHw2oWhGa+mWUeCyjWRrvIXwvenE95NhxIlQVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NPQnHbnz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NPQnHbnz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786354256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fllTULH2rQv7zAqX+LQLL7uPEeBIqqKHUflABxHkaxI=; b=NPQnHbnzxCRSHZYLsdXKU7KzmmZZFEgRmr8/CgLSJ1TbR1XKYHNO+6GW/S11/7fOOcrOrV 1s0ltqPuJ4Fx6MNBb1xaYykXXzWe45XOwfRhEjKEOZqRty0NJiOunSx4YXITBI341AA3zG OWY6PnnTqRbKimygukdC9zOReAnYXgc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-264-Xp_sMOMDPSeBETgCHF5euA-1; Mon, 10 Aug 2026 05:30:52 -0400 X-MC-Unique: Xp_sMOMDPSeBETgCHF5euA-1 X-Mimecast-MFC-AGG-ID: Xp_sMOMDPSeBETgCHF5euA_1786354251 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0095D19560BB; Mon, 10 Aug 2026 09:30:51 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 987073001D38; Mon, 10 Aug 2026 09:30:48 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , Christian Marangi , Antoine Tenart Cc: linux-crypto@vger.kernel.org, Eric Biggers , linux-kernel@vger.kernel.org Subject: [PATCH v5 10/10] crypto: eip93 - Simplify the check for a valid AES key Date: Mon, 10 Aug 2026 11:30:05 +0200 Message-ID: <20260810093009.608090-11-thuth@redhat.com> In-Reply-To: <20260810093009.608090-1-thuth@redhat.com> References: <20260810093009.608090-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" From: Thomas Huth eip93_aead_setkey() currently uses aes_expandkey() to check for a valid AES key, but then does not use the crypto_aes_ctx afterwards anymore, i.e. this is just a wasteful way of checking the key length, and thus aes_check_keylen() should be used instead. This also fixes a potential leak of sensitive data via the stack, since this function forgot to zeroize crypto_aes_ctx before returning to the caller. Suggested-by: Antoine Tenart Signed-off-by: Thomas Huth Reviewed-by: Antoine Tenart --- drivers/crypto/inside-secure/eip93/eip93-aead.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/inside-secure/eip93/eip93-aead.c b/drivers/cryp= to/inside-secure/eip93/eip93-aead.c index 2bbd0af7b0e0e..0b7a899b14d76 100644 --- a/drivers/crypto/inside-secure/eip93/eip93-aead.c +++ b/drivers/crypto/inside-secure/eip93/eip93-aead.c @@ -92,7 +92,6 @@ static int eip93_aead_setkey(struct crypto_aead *ctfm, co= nst u8 *key, struct crypto_tfm *tfm =3D crypto_aead_tfm(ctfm); struct eip93_crypto_ctx *ctx =3D crypto_tfm_ctx(tfm); struct crypto_authenc_keys keys; - struct crypto_aes_ctx aes; struct sa_record *sa_record =3D ctx->sa_record; u32 nonce =3D 0; int ret; @@ -126,7 +125,7 @@ static int eip93_aead_setkey(struct crypto_aead *ctfm, = const u8 *key, =20 break; case EIP93_ALG_AES: - ret =3D aes_expandkey(&aes, keys.enckey, keys.enckeylen); + ret =3D aes_check_keylen(keys.enckeylen); if (ret) return ret; =20 --=20 2.55.0