From nobody Fri Oct 2 09:17:16 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 EBED6368D59 for ; Mon, 3 Aug 2026 09:44:57 +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=1785750300; cv=none; b=kr45sn3QwZG5fvvkPzenyygt1P/mIHSc9W/uYrjxE9GS+e7hHeIlJYKnIXPzlcxjpTwB8SJSI+kAOd19bQ7VaIhVcEc4aR0+RHR+LfMsMyn/A95hSCXM9htxZlbvrTpf5NNuwAfABExPykslek69qK5Qsh6i3hh5QVuqtA1C2WM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750300; c=relaxed/simple; bh=tZ9DFU3CImOxJ23hySRfTaj9nKHCdZcc7HQT89o1FyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h7EEGjEYidVKMmg25xCDM3YAuxldDg/xvB6JYryLDvLs/nO+eMomXJpkvGADL87taswrviRiZ9sFB6ggh50c0wbnRIhvtZNZjzcKQYn/R+2fCABlDnI2A4IVZvRKzkvm6pQ0JWC2zWG9hOdJTMWZoEYDAkv91SuU1HXTQPw0Gms= 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=TRNyNYE+; 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="TRNyNYE+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750296; 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=kq1yNBsy1kHNFFiJapNMSiZHiMzaL2oUNaY6DUDtqzs=; b=TRNyNYE+OIeLgSUF1eiWkyJJrZtRzyHoshH6DKIRsY0PkvRlbrLUyhaXaLHLuUDf/WjZL4 iTICuOzR/E3OEWcjlyk/aVUlH2aEsvZPzImjH4bGU/n0wi7oOiebtq16s7ZLcmaDAHfGjJ /kDcCPX7i3HwiLF2AOh7fcioc7xum94= 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-551-Pz97ijfvNm26Z97FiCNjWQ-1; Mon, 03 Aug 2026 05:44:43 -0400 X-MC-Unique: Pz97ijfvNm26Z97FiCNjWQ-1 X-Mimecast-MFC-AGG-ID: Pz97ijfvNm26Z97FiCNjWQ_1785750282 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 64BC1180034A; Mon, 3 Aug 2026 09:44:42 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C76C31956087; Mon, 3 Aug 2026 09:44:39 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Simo Sorce Subject: [PATCH v2 1/9] crypto: Provide a wrapper for zeroizing crypto_aes_ctx Date: Mon, 3 Aug 2026 11:44:20 +0200 Message-ID: <20260803094432.70505-2-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 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_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 Acked-by: Eric Biggers --- 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); =20 +/** + * 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)); +} + /* * 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 Fri Oct 2 09:17:16 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 AAD262F7F1B for ; Mon, 3 Aug 2026 09:45:02 +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=1785750304; cv=none; b=dnaO2DMjoFtkk1i9pSi4tkGvv8E7/ck5kVcX9MdxZZ4KVj3BTZ2l3GdxhzZwEAMRXDJo286yHkoXuxJ+H8SLwI9iiRfKil5YvHg2mJsoswDEOjgk1b4rghbphgRAhO5tX+lmSuaYfjDM3zLgCaSGccaUBb/Z7iEAlh5iylrAPRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750304; c=relaxed/simple; bh=osdCp1YaPDSUXbk8x8A3ktndGqvtQPaLAPwMLJg1XGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i0jwB21L/QHDDBsfRhcIaWuKoPG6H2Dor1CmwrMkHlA7rG6vr62so32RhdcJfENU0x04S1OO1uS7Pt1owR06IiqH8EJYtmlZ7Up1X1BBrYueMIsscDju/OcVxYlwmQwKAC5CCIgW8D7D34O1YqpkLJVDqfl6WL5ofR5ZmuAv1S8= 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=PjtTCCff; 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="PjtTCCff" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750301; 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=z/s71yf/xbMLaACx3//RVPK21sA9eWV1kaPskwgCZQM=; b=PjtTCCffvYLRVRxswtJyXMGeW+oIsK7apcPBWbztyXfj+1hjbFbJ2uIidc74dU6nska3bE yQFW38JGChS+1Ent7R3PiUOqhCWbJQvip2nfN2UH0XcluVCm5JMBeo1XGK0q54Ruf8uRbu HsLWpZvHtDFsirW+DqV8Ystn3QbRkyU= 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-15-7KxwcOU9NS2jR-v4kKKdKg-1; Mon, 03 Aug 2026 05:44:53 -0400 X-MC-Unique: 7KxwcOU9NS2jR-v4kKKdKg-1 X-Mimecast-MFC-AGG-ID: 7KxwcOU9NS2jR-v4kKKdKg_1785750291 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 56001195605E; Mon, 3 Aug 2026 09:44:50 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 810F51956088; Mon, 3 Aug 2026 09:44:42 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Neal Liu , Joel Stanley , Andrew Jeffery , linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Cc: Simo Sorce Subject: [PATCH v2 2/9] crypto: aspeed - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:21 +0200 Message-ID: <20260803094432.70505-3-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Declare the gen_aes_key with __cleanup(aes_clear_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..74a4ce62fcd93 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_clear_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 Fri Oct 2 09:17:16 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 CA15B367285 for ; Mon, 3 Aug 2026 09:44:59 +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=1785750301; cv=none; b=dZH/Eycqo46zKWNwfuqJgblDvbn5RYRu/s3hH68FYBHDCePOfNn+4kLpNdAvFAxsU6hvoqIfuNgyyoNKtpXV8MCHjdhC6WdgJi8vR8eWToNn/3AY6wu25xZ+10fQKnNIl1Ga8qJJLnkjiN+9tbpCz779uyWFiHbsw7G65ozlckU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750301; c=relaxed/simple; bh=Ly3gsOBB0d0dZwCOQG/BAo9MKOMd4r6cuiwq5qrqiOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hh3WTyAjHYvOwATPxhdYuzmIFSFfUkobxrSc9xmvmw/aAAWtXHNsQHq29OSOGxW2JVe9daWOBpsuJSn4xB3KBipMjLJtNKBJcPWS84krxUMPs1Eexv0CIca2yZ+jJOX9tmPSbtb84OWzrYuQ9izA9nT9cgfM+bIMeL059F8w3S0= 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=Dt3gY7XW; 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="Dt3gY7XW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750298; 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=1BITfAIER9fk3/uef/hKbnVdlnd+g+3AUzVw4gdmtNA=; b=Dt3gY7XWAy4lY/k50HuB2pIrl3WmA38DaQSyZe2MRFQW6xosSHwoljamBu+xPLK4Jnhxmw AIwphj2WHVFkH+EZpAll6cToQfWgp37RqwC6BqXIF7el2JBT7hHu4nx+LalnL9+35hbPRT XvHKq/QjB8PyOGO7WxrV50W17bx6NYo= 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-679-Xa3eL1rVMOmdTOmAHmgX1w-1; Mon, 03 Aug 2026 05:44:56 -0400 X-MC-Unique: Xa3eL1rVMOmdTOmAHmgX1w-1 X-Mimecast-MFC-AGG-ID: Xa3eL1rVMOmdTOmAHmgX1w_1785750295 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 75057180029F; Mon, 3 Aug 2026 09:44:55 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 170D2195608E; Mon, 3 Aug 2026 09:44:50 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Christian Marangi , Antoine Tenart Cc: Simo Sorce Subject: [PATCH v2 3/9] crypto: inside-secure/eip93 - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:22 +0200 Message-ID: <20260803094432.70505-4-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_clear_ctx) when we're done with it to avoid that key data could leak on the stack. Cc: Christian Marangi Cc: Antoine Tenart Signed-off-by: Thomas Huth --- drivers/crypto/inside-secure/eip93/eip93-aead.c | 2 +- drivers/crypto/inside-secure/eip93/eip93-cipher.c | 2 +- 2 files changed, 2 insertions(+), 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..8bbbf8c0b8c98 100644 --- a/drivers/crypto/inside-secure/eip93/eip93-aead.c +++ b/drivers/crypto/inside-secure/eip93/eip93-aead.c @@ -92,7 +92,7 @@ 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 crypto_aes_ctx aes __cleanup(aes_clear_ctx); struct sa_record *sa_record =3D ctx->sa_record; u32 nonce =3D 0; int ret; diff --git a/drivers/crypto/inside-secure/eip93/eip93-cipher.c b/drivers/cr= ypto/inside-secure/eip93/eip93-cipher.c index 4dd7ab7503e85..3f9a15aa93541 100644 --- a/drivers/crypto/inside-secure/eip93/eip93-cipher.c +++ b/drivers/crypto/inside-secure/eip93/eip93-cipher.c @@ -116,7 +116,7 @@ static int eip93_skcipher_setkey(struct crypto_skcipher= *ctfm, const u8 *key, } =20 if (flags & EIP93_ALG_AES) { - struct crypto_aes_ctx aes; + struct crypto_aes_ctx aes __cleanup(aes_clear_ctx); =20 ctx->blksize =3D AES_BLOCK_SIZE; ret =3D aes_expandkey(&aes, key, keylen); --=20 2.55.0 From nobody Fri Oct 2 09:17:16 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 1C6E8368D59 for ; Mon, 3 Aug 2026 09:45:04 +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=1785750306; cv=none; b=f4ALtp+OZRkwUUwZx8wzQnHHIi7IaK15SfqaQrvYeVoOPiZ6CsaXV0S7ccQKYtw+dj/f8rXB2vc+wgNx9Omb+ykKb7uYUlZ9vnw9DTYV3b9JuabPQTH+tq+J5hAGE8MS8R8jRnQ52jgWeVr3ARMcwS9/z3jHZKQkzErJSMrFkwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750306; c=relaxed/simple; bh=tET0bmPovu6LMHmhPlWZdTJH8biWVE0DzpomZulNAYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=APw2l3Mv1yUOjAtpvAyTckXjskxjineAOdgNASPXIrIs/R1fBJ8yjBlHBgio5yV1BIlDnyWzln8w8mn8ytDPZx4zORVq9HckZGjRNjVaZKLv6HV9DvmCt7ryVFcSStwQWhxGteZj/V+ljCNxUuXV4LSY++yy9zlT9aNpCTdxyIs= 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=DUfuosqx; 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="DUfuosqx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750304; 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=r7jhgAlap1RRZguFS9J+8193uRModx2Kfk65XzDNpnY=; b=DUfuosqxi0GxUcTH44M8QiRWQjA/KSA2t/qw94RbZKXvsa3FTKv0Im9bfiJ6/LxrqCfpHI j2hIwNmDKtAxiptUhCvLvSuk5y/zPqhXcdVKv/dnR0PA3JnyUcCKGbiftgHR2vTUZFcNdQ CptyAW1/EUcg1y/qHckiAzZf4GOOalo= Received: from mx-prod-mc-08.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-658-aHCCS2MAPjOvDzSdGnbn7g-1; Mon, 03 Aug 2026 05:45:00 -0400 X-MC-Unique: aHCCS2MAPjOvDzSdGnbn7g-1 X-Mimecast-MFC-AGG-ID: aHCCS2MAPjOvDzSdGnbn7g_1785750300 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C9F1B1800370; Mon, 3 Aug 2026 09:44:59 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 760E41956087; Mon, 3 Aug 2026 09:44:56 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Simo Sorce Subject: [PATCH v2 4/9] crypto: padlock-aes - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:23 +0200 Message-ID: <20260803094432.70505-5-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_clear_ctx) when we're done with it to avoid that key data could leak on the stack. Signed-off-by: Thomas Huth --- drivers/crypto/padlock-aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c index 1be549a07a219..ac0aace62b299 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_clear_ctx); int cpu; =20 if (key_len % 8) --=20 2.55.0 From nobody Fri Oct 2 09:17:16 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 9C382372EFA for ; Mon, 3 Aug 2026 09:45:08 +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=1785750310; cv=none; b=pk3eEr+OvI3M7s4ygbKVHZjTEOd4z0iYwLb97CnoXZzuQdV96DB8jAUi+wx6v3f9PmdkCYHRGuDxJ1Q72mE5hkIDwaanSCe+tFQX9mfqYLEZOwL4+cJd7ep/Ytx83OhXwnERe/Z6eFmwm5GZDnmZyApeSCZAUtt8jQwvVwGgJNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750310; c=relaxed/simple; bh=hlFkWPJbwxqmu6n2UBUC9mnTUyBcPL2Dz2V9kgQ8ZAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mWxzZryYC0zY2EZBR9PkaErQvUMmuQs32MHpu6a4V8CCUletdZ9fVIqrCmIepfoeaImSfDPNfKrdjpUEXRlnWWIc9+rYsmRfA90T41ei3MOpIsJre3zYea3ZpYpxTXApdPPN9Euuh5HVZcfj6AFzOxroZBcAxKrot50R6Dz3zzw= 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=Eg4LJ59n; 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="Eg4LJ59n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750307; 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=rNfaUJSGZkllVVmqoWpRblGjymrMkwDfUYzNGF3wB5o=; b=Eg4LJ59n3vtpQPjVYZhJF3tKJFc/7q+imP2pkanCZ33CT0QUnC0iqJGLDFvNix39iLyqEt ounXBvmTUWyHxmedDhJxj23IEgUGUzThq0WF974F2r0TDpnt+boAECNQnZifmJHtvNgKFE CmlALToZVQg76ULl7RgxJxDH7ekwDOQ= Received: from mx-prod-mc-08.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-79-6nUzNavaMcGu9F092Tibjg-1; Mon, 03 Aug 2026 05:45:04 -0400 X-MC-Unique: 6nUzNavaMcGu9F092Tibjg-1 X-Mimecast-MFC-AGG-ID: 6nUzNavaMcGu9F092Tibjg_1785750303 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6898A1800350; Mon, 3 Aug 2026 09:45:03 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 89AD01956087; Mon, 3 Aug 2026 09:45:00 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Simo Sorce Subject: [PATCH v2 5/9] crypto: sa2ul - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:24 +0200 Message-ID: <20260803094432.70505-6-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_clear_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..b921993d86a7b 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_clear_ctx); int key_pos; =20 if (aes_expandkey(&ctx, key, key_sz)) { --=20 2.55.0 From nobody Fri Oct 2 09:17:16 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 80B00377559 for ; Mon, 3 Aug 2026 09:45:14 +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=1785750316; cv=none; b=IAXI1f+QzJG/evHzGY5xrcXjbWsI6mg6TXpWV7Wpm0P3v5FEa/1I+z5+Mvh8Z9/We5lDGpVHO+MGYpqAraHp8kk/kq5zvz3cFONsbcpPiV/fLeHIl3UW4xDjbu5SDoa8u5LmVKkfNS+fiiKTCsHFr/w0IAengWjDywy2Yk6ePTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750316; c=relaxed/simple; bh=Y1ZQ2Z65qWpaCYiK8JIwqN04PJl0FQWPEWmvnfjs9xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XwE3VbMEt63i/3HMNj07llxnvY7PDJL5v/9Kj3drsHTbotQNNCuS7/E6dW3z+MnNLSK/dnHAroFRdG4t66Lk7AB28fYJ1JuRrGQ9NhW1kBUuHC8UTipIhpl3NJwXdr9hp6zUcgOGF4eraFtqgAu0vUoSn09LizrugR8HYxS6Bcc= 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=U3YCOo/C; 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="U3YCOo/C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750313; 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=tgRIZfjAKRcjwzlyDkDI9fWoNOZ3iNTbySLuYW1QpTA=; b=U3YCOo/CD3gtrs2yLJmwIKQEF1ZLsZRlJJFKzI4zg+4moq390YX33l20p5vJcTCK9wQzMT eP01owVnvyRv9rCSzdsEHJ5EnlVDnRtUfjp6Jcv60l6u3UfEqO3k2+InG6/VyyHu9JSW6L 92gNuDusfvJrZNicOrib2IG12icjEZg= Received: from mx-prod-mc-08.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-221-mikQaVWmOWil4AOAeWIsyg-1; Mon, 03 Aug 2026 05:45:10 -0400 X-MC-Unique: mikQaVWmOWil4AOAeWIsyg-1 X-Mimecast-MFC-AGG-ID: mikQaVWmOWil4AOAeWIsyg_1785750309 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C09511800348; Mon, 3 Aug 2026 09:45:08 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2AB891956087; Mon, 3 Aug 2026 09:45:03 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org Cc: Simo Sorce Subject: [PATCH v2 6/9] crypto: arm/aes-neonbs - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:25 +0200 Message-ID: <20260803094432.70505-7-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_clear_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..2bb21f7b06a8e 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_clear_ctx); int err; =20 err =3D aes_expandkey(&rk, in_key, key_len); --=20 2.55.0 From nobody Fri Oct 2 09:17:16 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 25B5E377561 for ; Mon, 3 Aug 2026 09:45:21 +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=1785750323; cv=none; b=hwsWsGWA94K2+xBOs2QZd6cwMJvjFo71SseOhVsyXrPFu3InFUAibFuNbgbcObWu+vsMOLlLGA6xaarMEi8qYO9Fg4tEdHQBiEttqQGzD69EMs9TgCbAFmwK5CCCkZfBKcaca1svd0iwJaQ5RnZJ+CDYd9w3c4eBeVGK4cr/wsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750323; c=relaxed/simple; bh=dHiWsuZcN9yBemaC9Mcs84SKEAwk+m6rbldjlEmvX8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ba44Qzu7Bkp+Oa13FFuTadt4ppcjnktRwQgGgYno4l7e5a6ffZ8mrl4qMwxh+ccZTWIfi2p0yVG2/WapCEloVjAPHruEyEIoL190L4Gnc89rTomRJH1/2VvPlA7i/KZ5en4hicc8vAHjDUemasBpy78AR0AFIlen9RsG91JVqIA= 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=QFdjQEEz; 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="QFdjQEEz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750321; 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=kqzqzXsKLyD/JykJa41z6gjBOK5AcAPVYWltBpH9JdQ=; b=QFdjQEEzoLo5ap13mY2vpL4T2PZDdetF5mj0G98UmCriUB/bmL+yah5rATbbDWRAVky6c1 JHOCJ432wWZRrx0L8kJhXiUfUytvaLn+dge1DZqY6HFfAr1fLqEpSZma7SEteg4UEnpiPe slKxnu2ahGlL3amOMkPxEPMzlD5/5Dk= Received: from mx-prod-mc-08.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-451-GnM8WsrJNJayiuqXF46ESw-1; Mon, 03 Aug 2026 05:45:15 -0400 X-MC-Unique: GnM8WsrJNJayiuqXF46ESw-1 X-Mimecast-MFC-AGG-ID: GnM8WsrJNJayiuqXF46ESw_1785750314 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E9A741800473; Mon, 3 Aug 2026 09:45:13 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C07931956087; Mon, 3 Aug 2026 09:45:09 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Simo Sorce Subject: [PATCH v2 7/9] crypto: arm64/aes-neonbs - clear the crypto_aes_ctx when done Date: Mon, 3 Aug 2026 11:44:26 +0200 Message-ID: <20260803094432.70505-8-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: Thomas Huth Clear the crypto_aes_ctx structure via __cleanup(aes_clear_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..4c0f1bbd03fee 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_clear_ctx); int err; =20 err =3D xts_verify_key(tfm, in_key, key_len); --=20 2.55.0 From nobody Fri Oct 2 09:17:16 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 65DF136A369 for ; Mon, 3 Aug 2026 09:45:23 +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=1785750325; cv=none; b=lMvQ0KE7KY6rFry8ez1R0eOL8LaFPppKt7XZ2slcwK44v/GODOHmnqECGQ6So7oQeTW4WpcqS02UpteyqgJBuprqGXa7+WoaCfNM5zeWOgbEr2UrmOWEE90e219lAut90TjU1wfZxB5EL7Y0jvHqK1494PbXI2G0u5ETHTW/VRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750325; c=relaxed/simple; bh=KxsvhumK4s3tw3Er5p0b5F38MiorgxJ4jQR1poItIjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mHe1cpzoM3zt4Okur8SqL3DOqybnok0yg1GeELZIYpNKe80EwVbdFrkBwhShb1kYX1q7Okz1cSyqBZxUwCO7akSFTDHKpxD6qLQMvNEanuP9XPGO+obJ3oORkcUfW9qV4AX7nNqSOS17vgwILUMdCE9FAvXxUfZNWR95n8fDdOg= 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=NRrsd1hF; 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="NRrsd1hF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750322; 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=0KQ0+OJ5RmnRaSRsooNlQiduy9YrkCjgJuqwW/tXaUM=; b=NRrsd1hFb+NLgDgdPTsE2Ggr/Wgctc9IH2EQdxVpVsDGDO80JYX48YrtjXPAuWcAxllEc/ v85aeHkTDpt46RRYcMyYSAbQRiNXml0zLK9sDkBiw8va1A0GmwnxYhVUds5D67Ho6MJe7g fRzOJhHL9MLkS72oj/jdNmq9SQVSsEs= 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-6-w65f0Gx6O7S8iK9U9Q_7nQ-1; Mon, 03 Aug 2026 05:45:19 -0400 X-MC-Unique: w65f0Gx6O7S8iK9U9Q_7nQ-1 X-Mimecast-MFC-AGG-ID: w65f0Gx6O7S8iK9U9Q_7nQ_1785750318 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 0171819560B7; Mon, 3 Aug 2026 09:45:18 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1F2461956087; Mon, 3 Aug 2026 09:45:14 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Antoine Tenart Cc: Simo Sorce Subject: [PATCH v2 8/9] crypto: safexcel - zeroize crypto_aes_ctx with __cleanup(aes_clear_ctx) Date: Mon, 3 Aug 2026 11:44:27 +0200 Message-ID: <20260803094432.70505-9-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 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 two cases are missed: 1) safexcel_aead_setkey() never cleared it 2) 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 these and to avoid future similar problems, let's use the new __cleanup(aes_clear_ctx) mechanism to make sure that we clear the crypto_aes_ctx everywhere. Cc: Antoine Tenart Signed-off-by: Thomas Huth --- drivers/crypto/inside-secure/safexcel_cipher.c | 15 +++++---------- drivers/crypto/inside-secure/safexcel_hash.c | 3 +-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypt= o/inside-secure/safexcel_cipher.c index a8349b684693e..2d21ef388beaf 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_clear_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 @@ -407,7 +406,7 @@ 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; + struct crypto_aes_ctx aes __cleanup(aes_clear_ctx); int err =3D -EINVAL, i; const char *alg; =20 @@ -1362,7 +1361,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_clear_ctx); int ret, i; unsigned int keylen; =20 @@ -1388,7 +1387,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 @@ -2542,7 +2540,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_clear_ctx); int ret, i; unsigned int keylen; =20 @@ -2590,7 +2588,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 @@ -2756,12 +2753,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_clear_ctx); int ret, i; =20 ret =3D aes_expandkey(&aes, key, len); if (ret) { - memzero_explicit(&aes, sizeof(aes)); return ret; } =20 @@ -2790,7 +2786,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..d3b701c96d871 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_clear_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 Fri Oct 2 09:17:16 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 EE9CD37E5EE for ; Mon, 3 Aug 2026 09:45:30 +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=1785750332; cv=none; b=DPwb5dhVOZUtH0sux9/mtClKtY2AzcIqq1RG77dv/xNw1ZjADC/29yS+VWivt24hounR/+Q+Jd1KZnCH8MzVNzOYGsMrAGhPhy4hyGmW2Y+pVqs/7sZrlR74d+/9YU9SOY+tMLC8ljtd1L4KIXNc0n/wrQ5Zsv7Dbu7aAoKJqG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785750332; c=relaxed/simple; bh=0LDHq7QdkqDReNPHALZn7cIcfQsp6FI/EqyFL/S+3O4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQooBSlS7iqoUC14td0icZal35GQv+pKv2lRWxSmafvGajLWyW9UuhS3rO5J1tOJCrtkOqRxNYS23/UCLo7wip7c8UvKT74DPeTA+6ZcP90+WKJoz0sYGtH3cg7i+00/0EsFLU8OnhtywPK4ZawJq0PcY0YeHhEmorp3srntgn8= 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=OKeV5VoU; 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="OKeV5VoU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785750329; 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=dYwdk10fZS/RlXj0yQtqtdCG4riS9n+O4AarGWgwDs0=; b=OKeV5VoU+NdJ7Yj4sJYZHUZJ2au1uARtteo+F5pTikQZEJwRfqpHjekI3CzMA0pySFuZZe ng+EA/t/ZCE3h6S5VfX84IyMNjoQiWvvvoFCUMsw5AZZU+DT8htiyPxNz9CBjGVlAzfXND tqIZCuVmr0yi+fz0jDbseqUmKwFl+2A= 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-213-KTRdosnKOcmRdBGh9i5rJA-1; Mon, 03 Aug 2026 05:45:24 -0400 X-MC-Unique: KTRdosnKOcmRdBGh9i5rJA-1 X-Mimecast-MFC-AGG-ID: KTRdosnKOcmRdBGh9i5rJA_1785750323 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 1E45819560BC; Mon, 3 Aug 2026 09:45:23 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.48.213]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 016C01956087; Mon, 3 Aug 2026 09:45:18 +0000 (UTC) From: Thomas Huth To: Herbert Xu , "David S. Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Giovanni Cabiddu , qat-linux@intel.com Cc: Simo Sorce Subject: [PATCH v2 9/9] crypto: qat - zeroize crypto_aes_ctx with __cleanup(aes_clear_ctx) Date: Mon, 3 Aug 2026 11:44:28 +0200 Message-ID: <20260803094432.70505-10-thuth@redhat.com> In-Reply-To: <20260803094432.70505-1-thuth@redhat.com> References: <20260803094432.70505-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.0 on 10.30.177.12 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_clear_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. Cc: Giovanni Cabiddu 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..9a56fcdedd579 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_clear_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