From nobody Tue Sep 29 13:18:54 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 853FB4756C5 for ; Fri, 7 Aug 2026 12:58: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=1786107546; cv=none; b=HBZmC8Ad/ah6DeeSBacRGs0nep+tqvCX2lgmj82Dd3oUAAm5C4k0P8kfVJITLq8H9R7WhjQHM1xEYAOkS8+CJQH31ywIHymxCOQzesniL35eiBfVI4dcBY4JsImmr6HJiQWwk/NSyVw2Pq5j+gOW7ZwVLflRfOWGfkBhslL8dA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107546; c=relaxed/simple; bh=GOicAiiPdCosnYt+UyxDcvfW0DeSZyz5yYTdbWqyCUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bYEN8sr+2BNjSez1S8ISZRrcxpU3sVh+FGqdltbo3FgoMnSNZNfMHax/OuN16Sq4Xl7lyhML9G2NFLVZ+elZs492mKALQdZpdm6ykvcdcF4QoQYODyfU1cPUmslAPc3UvzgLkyCg6xsFzKXPwuXMANhhDtp4ovPKydZTMukL4fU= 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=IKp+Rc4j; 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="IKp+Rc4j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107537; 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=SAuxcU+LljEfsSN8otHgMJR5aOh9hA9sihtkJB/tiGQ=; b=IKp+Rc4jLJhkOUnzQxs7ptLzM7p6eeTNLt4kpqmQw8XqxytDFeGI+NVdVuCT4egfYkF6GB JcxksxyuBJdpPBSJbPYZZvDGKsryTqVuzaUD/MJAFOMHxtoH6uDc4gZHUhmdPsE8TQSeh4 FwDCMArFEvPkLP4Ht3fycENuyVhMYHQ= 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-631-Y9pqZvjBOSyoo-bdcoWNiw-1; Fri, 07 Aug 2026 08:58:54 -0400 X-MC-Unique: Y9pqZvjBOSyoo-bdcoWNiw-1 X-Mimecast-MFC-AGG-ID: Y9pqZvjBOSyoo-bdcoWNiw_1786107533 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 D3C50195609D; Fri, 7 Aug 2026 12:58:52 +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 8CF2C30001A2; Fri, 7 Aug 2026 12:58:50 +0000 (UTC) From: Thomas Huth To: Eric Biggers , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Namjae Jeon Subject: [PATCH v2 1/6] crypto: Provide wrapper functions for zeroizing aes_cmac_key and aes_cmac_ctx Date: Fri, 7 Aug 2026 14:58:38 +0200 Message-ID: <20260807125845.1477067-2-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 Code that uses AES-CMAC might need to zeroize their local aes_cmac_key and/or aes_cmac_ctx structures after use to avoid leaking sensitive material on the stack. Provide an aes_cmac_zeroize_key() and an aes_cmac_zeroize_ctx() helper function that can be used with __cleanup() to automatically clear the key and context when they go out of scope. Signed-off-by: Thomas Huth --- include/crypto/aes-cbc-macs.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/crypto/aes-cbc-macs.h b/include/crypto/aes-cbc-macs.h index e61df108b926d..06e8a22f8a0ac 100644 --- a/include/crypto/aes-cbc-macs.h +++ b/include/crypto/aes-cbc-macs.h @@ -8,6 +8,7 @@ #define _CRYPTO_AES_CBC_MACS_H =20 #include +#include =20 /** * struct aes_cmac_key - Prepared key for AES-CMAC or AES-XCBC-MAC @@ -24,6 +25,19 @@ struct aes_cmac_key { } k_final[2]; }; =20 +/** + * aes_cmac_zeroize_key() - Zeroize an aes_cmac_key structure + * @key: The location of the key structure that should be zeroized + * + * Explicitly fills the aes_cmac_key with zeroes. This should be done once + * the key 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_cmac_zeroize_key(struct aes_cmac_key *key) +{ + memzero_explicit(key, sizeof(*key)); +} + /** * struct aes_cmac_ctx - Context for computing an AES-CMAC or AES-XCBC-MAC= value * @key: Pointer to the key struct. A pointer is used rather than a copy = of the @@ -40,6 +54,19 @@ struct aes_cmac_ctx { u8 h[AES_BLOCK_SIZE]; }; =20 +/** + * aes_cmac_zeroize_ctx() - Zeroize an aes_cmac_ctx structure + * @ctx: The location of the context that should be zeroized + * + * Explicitly fills the aes_cmac_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. Only required if not using aes_cmac_final(= ). + */ +static inline void aes_cmac_zeroize_ctx(struct aes_cmac_ctx *ctx) +{ + memzero_explicit(ctx, sizeof(*ctx)); +} + /** * aes_cmac_preparekey() - Prepare a key for AES-CMAC * @key: (output) The key struct to initialize @@ -47,6 +74,10 @@ struct aes_cmac_ctx { * @key_len: Length of the raw key in bytes. The supported values are * AES_KEYSIZE_128, AES_KEYSIZE_192, and AES_KEYSIZE_256. * + * On success, the caller should ensure that the prepared key is zeroized + * at the end of its lifetime, e.g. by calling aes_cmac_zeroize_key() or + * kfree_sensitive(). + * * Context: Any context. * Return: 0 on success or -EINVAL if the given key length is invalid. No= other * errors are possible, so callers that always pass a valid key length @@ -79,6 +110,9 @@ void aes_xcbcmac_preparekey(struct aes_cmac_key *key, * * This supports both AES-CMAC and AES-XCBC-MAC. Which one is done depend= s on * whether aes_cmac_preparekey() or aes_xcbcmac_preparekey() was called. + * + * The caller should ensure that the context is zeroized at the end of its + * lifetime, e.g. by calling aes_cmac_final() or aes_cmac_zeroize_ctx(). */ static inline void aes_cmac_init(struct aes_cmac_ctx *ctx, const struct aes_cmac_key *key) --=20 2.55.0 From nobody Tue Sep 29 13:18:54 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 E13D61A681E for ; Fri, 7 Aug 2026 12:59: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=1786107561; cv=none; b=GSQxtbiChFrvBGvUCIqBUyBamxulovNde0z15bRToZ8c4BHGFI9pRJjfFKTBERvAtpL6TuvzKu3F9ubzOwiRJLDNsu6Iqo0ZcA9GchhUGwU4zlNNW3/w1XMTXZqJ69e1XVAZRqR2mk6xD3vujTZCIDNe73Hb9RCQ5n8YtnvySoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107561; c=relaxed/simple; bh=HY1fXOCc++pdACbCDsnbvo4DN0eMrHtPCYGnQ2C1K8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CPWgCJjhgzpeGL51XkGSKMHudWhNVkPTrIg5XPix+e5MwiAdrXEq1aIc2Wa/g3jptFwNKwuoPORdL227jJs1hzoK/QjJNkj83CYcycUCQ7MAmShXU1Ew1i4on1AIWbXC40oYRlEmM0WhM1ijwCApUIwW5kibdUJfWrEEoYR0V6U= 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=f8Eh3o/t; 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="f8Eh3o/t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107544; 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=EnK55USt5eYX4DKAb2D0n3Ly2M5DO0VV1eu2CGhl9ns=; b=f8Eh3o/tJi+0EoUSjNh2U4y3CixbjZdCwR7I8fF2O8oeWguOegHCaYs1ZsUUwNGe0OV3yB xReu4qsT6j4fiRPW9m+ro5BKSsGh3lk3iwujZXfiaclZABNFqT1H5Nz7KylKtYJZsJWJHs OhNsQy4QoUAYGD5I6aMVty2h+UufZVk= 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-357-sZsFBmd1O1Kh-2j3jyt2wg-1; Fri, 07 Aug 2026 08:59:02 -0400 X-MC-Unique: sZsFBmd1O1Kh-2j3jyt2wg-1 X-Mimecast-MFC-AGG-ID: sZsFBmd1O1Kh-2j3jyt2wg_1786107539 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 936481954B1B; Fri, 7 Aug 2026 12:58:58 +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 A88BB3000239; Fri, 7 Aug 2026 12:58:53 +0000 (UTC) From: Thomas Huth To: Eric Biggers , Steve French , Namjae Jeon Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Sergey Senozhatsky , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Subject: [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done Date: Fri, 7 Aug 2026 14:58:39 +0200 Message-ID: <20260807125845.1477067-3-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 local crypto-related structures via __cleanup() functions when we're done with them to avoid that sensitive data could leak on the stack. Note: cmac_ctx in ksmbd_sign_smb3_pdu() gets cleared in aes_cmac_final() already, so this does not need a __cleanup() marker. Signed-off-by: Thomas Huth Acked-by: Namjae Jeon --- fs/smb/client/smb2transport.c | 4 ++-- fs/smb/server/auth.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c index 1143ee52470a7..d23566da2ac81 100644 --- a/fs/smb/client/smb2transport.c +++ b/fs/smb/client/smb2transport.c @@ -464,8 +464,8 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_S= erver_Info *server) unsigned char smb3_signature[SMB2_CMACAES_SIZE]; struct kvec *iov =3D rqst->rq_iov; struct smb2_hdr *shdr =3D (struct smb2_hdr *)iov[0].iov_base; - struct aes_cmac_key cmac_key; - struct aes_cmac_ctx cmac_ctx; + struct aes_cmac_key cmac_key __cleanup(aes_cmac_zeroize_key); + struct aes_cmac_ctx cmac_ctx __cleanup(aes_cmac_zeroize_ctx); struct smb_rqst drqst; u8 key[SMB3_SIGN_KEY_SIZE]; =20 diff --git a/fs/smb/server/auth.c b/fs/smb/server/auth.c index 4e7b6f0e6b8cd..e8d1c068a43e8 100644 --- a/fs/smb/server/auth.c +++ b/fs/smb/server/auth.c @@ -509,7 +509,7 @@ void ksmbd_sign_smb2_pdu(struct ksmbd_conn *conn, char = *key, struct kvec *iov, void ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *= iov, int n_vec, char *sig) { - struct aes_cmac_key cmac_key; + struct aes_cmac_key cmac_key __cleanup(aes_cmac_zeroize_key); struct aes_cmac_ctx cmac_ctx; int i; =20 --=20 2.55.0 From nobody Tue Sep 29 13:18:54 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 4B48C43302C for ; Fri, 7 Aug 2026 12:59:12 +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=1786107561; cv=none; b=dyleX5iZQzYTA3xrFLEdT5Ikj79u2ZwKo3qHmc0CCADxRKp4BYTI98Tf26QjkuTf5hMHcMvjyzj/FhJKIcmXU+76nLmV3WYEtOftV/69yvvoefFQyjfogwKHZ3kxHngRzbO0U7EgO/1K5YhzfpTtfjO/pymXUjVZJT6CblLB2tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107561; c=relaxed/simple; bh=nB9PeiYqtYxB59Cpiw4+izGx1h8kYfW2R3OcHeWgats=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JvRKL1np/Qbniqhq78shH1dqsRI7mVbZYWHqJpM4B9KPb/Y79WyR6l/XhrrdZw0zOd2eDHTi+o5eY7J3St7ujfuRg3mxAFyds4zrnjoblPwGnx1k66DsAK3ybDa5wkv3V/ANqxtG0sugSlI4IrREdiSEsdDuh0pZ7ZbzBF4yy44= 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=c6x5af7z; 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="c6x5af7z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107550; 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=8M7wXURrhkNZfyuEwKvTXxWNDng8ek7UYAiVlFhlORo=; b=c6x5af7z2Rpnb0fT+8/xOP6PQosLPf6Qk7CzveX2S6Ja6Y3IkUlJyF2G74723nevEcvAMJ ELRoRbKlm3vl53J3t/kBr6FvskmQLqrYzd2DJ6Nl5AUnxyJBaNxmDT1OHRRGASesripr0F iHf0f2tBbeqBkrq02Onk14ac/vMxfl0= 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-312-pasijFAYP1-GQ_F9r9GQxw-1; Fri, 07 Aug 2026 08:59:05 -0400 X-MC-Unique: pasijFAYP1-GQ_F9r9GQxw-1 X-Mimecast-MFC-AGG-ID: pasijFAYP1-GQ_F9r9GQxw_1786107543 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 598A019560B2; Fri, 7 Aug 2026 12:59:03 +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 4E93A30001A2; Fri, 7 Aug 2026 12:58:59 +0000 (UTC) From: Thomas Huth To: Eric Biggers , Eric Dumazet , Neal Cardwell , "David S. Miller" , Jakub Kicinski , Paolo Abeni Cc: Herbert Xu , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Namjae Jeon , Kuniyuki Iwashima , Simon Horman , netdev@vger.kernel.org Subject: [PATCH v2 3/6] net/tcp-ao: clear the aes_cmac_key when done Date: Fri, 7 Aug 2026 14:58:40 +0200 Message-ID: <20260807125845.1477067-4-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 local aes_cmac_key structure via __cleanup() function when we're done with it to avoid that sensitive data could leak on the stack. Signed-off-by: Thomas Huth --- net/ipv4/tcp_ao.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c index e4ec60a334963..0626cbf60620c 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -141,7 +141,7 @@ void tcp_ao_calc_traffic_key(const struct tcp_ao_key *m= kt, u8 *traffic_key, traffic_key); return; case TCP_AO_ALGO_AES_128_CMAC: { - struct aes_cmac_key k; + struct aes_cmac_key k __cleanup(aes_cmac_zeroize_key); =20 aes_cmac_preparekey(&k, mkt->key, AES_KEYSIZE_128); aes_cmac(&k, input, input_len, traffic_key); --=20 2.55.0 From nobody Tue Sep 29 13:18:54 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 94195477994 for ; Fri, 7 Aug 2026 12:59:17 +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=1786107569; cv=none; b=O4HGCEQLJqa3FL3MJ6od38hPPeR6vg7QnhfrnsSwp1Q17tXfkpH6qp2WFkelJ3/bSIFtTlJEDDrfKWUEHezcGa0UBpVdpTtKz9+/9zF+c4NVWvP4zuWUrC17+5M33/YU/WF+oecuDOGhUGkvxDNnWSCEcW5NhBhyZTAWaFjbWuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107569; c=relaxed/simple; bh=xll+zQBRt7rsfHb8Jkq21yOblpXfl3YCI/v6M+vzAvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e5OUltF6hFl2jVlrHMH2vY6W8z3qrep+Tych+R5bCT32msn+Db5Ukrocclbe4gGQGiv7B+WpoXv/Am2YonAXfybWneBPm5UxxpEsyzOqrv/1qHylCBMifok7ssAitAaEawEIaoiuM3txSWysreGOHpxZqe5GrQroQO9HFd5k7F8= 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=IJpbbr0E; 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="IJpbbr0E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107552; 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=G6hdW7g3Ya8i9Nu/IIIEE9pizj4AfF82eIRYCUasgO8=; b=IJpbbr0EVO220ZzGTlG8EZTYnuejwH50sV1anGnt9xVulv8j183xF2QgiMZYopiYRHjCPH +g8M/zXQMXC9G+pIOsieFP8ZEg/ew8fSELJ3cL+SqRkpQXvae6KuHP087xQvvUUzJXriER GlmYVdMSjl+z7UTFt0fjoT48OAwruT8= 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-507-OfXcrwZXOEemRMILt9Qq4A-1; Fri, 07 Aug 2026 08:59:09 -0400 X-MC-Unique: OfXcrwZXOEemRMILt9Qq4A-1 X-Mimecast-MFC-AGG-ID: OfXcrwZXOEemRMILt9Qq4A_1786107547 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 AE9F21955DB0; Fri, 7 Aug 2026 12:59:07 +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 11E9430001A2; Fri, 7 Aug 2026 12:59:03 +0000 (UTC) From: Thomas Huth To: Eric Biggers , Marcel Holtmann , Luiz Augusto von Dentz Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Namjae Jeon , linux-bluetooth@vger.kernel.org Subject: [PATCH v2 4/6] Bluetooth: SMP: clear the aes_cmac_key when done Date: Fri, 7 Aug 2026 14:58:41 +0200 Message-ID: <20260807125845.1477067-5-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 local aes_cmac_key structure via __cleanup() function when we're done with it to avoid that sensitive data could leak on the stack. While we're at it, also clear the tmp[] array here that is populated with a raw version of the original key and thus would leak the same information via the stack otherwise. Signed-off-by: Thomas Huth --- net/bluetooth/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index c4470958b0d57..4a32e4f80b48a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -164,7 +164,7 @@ static inline void swap_buf(const u8 *src, u8 *dst, siz= e_t len) static int smp_aes_cmac(const u8 k[16], const u8 *m, size_t len, u8 mac[16= ]) { uint8_t tmp[16], mac_msb[16], msg_msb[CMAC_MSG_MAX]; - struct aes_cmac_key key; + struct aes_cmac_key key __cleanup(aes_cmac_zeroize_key); int err; =20 if (len > CMAC_MSG_MAX) @@ -178,6 +178,7 @@ static int smp_aes_cmac(const u8 k[16], const u8 *m, si= ze_t len, u8 mac[16]) SMP_DBG("key %16phN", k); =20 err =3D aes_cmac_preparekey(&key, tmp, 16); + memzero_explicit(tmp, sizeof(tmp)); if (WARN_ON_ONCE(err)) /* Should never happen, as 16 is valid keylen */ return err; aes_cmac(&key, msg_msb, len, mac_msb); --=20 2.55.0 From nobody Tue Sep 29 13:18:54 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 3A548476048 for ; Fri, 7 Aug 2026 12:59:25 +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=1786107575; cv=none; b=UDg/cAfX6gT/gLwCb5Sd0gQelIR5d93B6mfSdg21wAqICGfiLzwuY6R2Usjr31ey7ShSwoan5ATtPqY24F8qFYCo+ZrQAUJyflX1Eq1m9pjzglL7etVQECZuJXcLecjOdRgVcl8IJquOKecOOPGFRrQMmO0wkmu1s+VX1sMrA48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107575; c=relaxed/simple; bh=qPEZRKhEi06HCbNvqfEU6K4V3GJdTOqXA3pBAX/Oy84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZD0qhD8ilXNZcZFSR8kubk7+cpnMt3Ijnb5A8J98J8urAnG7BtsVQezaRBzf24dFEZDSY2+OTMUbITp12ozA8Qz050eUrrICDClzbT3kS8Uhuffm6kIapKvYPC7SuWMkH0cUYYSrW/J0SmNMDMLtdVPvvc8bcn2zrpTBOttnDQ4= 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=bXMGtIs7; 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="bXMGtIs7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107559; 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=KZ8+O2dzwSXOTlm2+htw33WMtif8W7imIy+AZH7HO/Q=; b=bXMGtIs71b+nzLzmbfQC9bTSwGECVheqbZMgausdDahumZK2idmn085A7nJGxMCv3HsXJi rdHDo89GCq/SDt7V4KgX1wn3aLafSnvhbNrH9IsZG4rOlgDD/LMB/FIwUO09TzRKd4Z6um 3NmdAsGI0bnJXGxeDbtrE6e2noYL5iM= 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-52-0YgWB7iWPD6zLHbetqDpSQ-1; Fri, 07 Aug 2026 08:59:12 -0400 X-MC-Unique: 0YgWB7iWPD6zLHbetqDpSQ-1 X-Mimecast-MFC-AGG-ID: 0YgWB7iWPD6zLHbetqDpSQ_1786107551 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 41FA0195608B; Fri, 7 Aug 2026 12:59:11 +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 68A5630001A2; Fri, 7 Aug 2026 12:59:08 +0000 (UTC) From: Thomas Huth To: Eric Biggers , "Jason A. Donenfeld" , Ard Biesheuvel Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Namjae Jeon Subject: [PATCH v2 5/6] lib/crypto: aes: Use __cleanup() for aes_cmac_key instead of memzero_explicit() Date: Fri, 7 Aug 2026 14:58:42 +0200 Message-ID: <20260807125845.1477067-6-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 By using __cleanup(aes_cmac_zeroize_key) for clearing the key data, we can save one line of code here. Signed-off-by: Thomas Huth --- lib/crypto/aes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c index 41aaa82cb1a1c..f1549839b3de0 100644 --- a/lib/crypto/aes.c +++ b/lib/crypto/aes.c @@ -740,7 +740,7 @@ EXPORT_SYMBOL_NS_GPL(aes_cbcmac_final, "CRYPTO_INTERNAL= "); /* FIPS cryptographic algorithm self-test for AES-CMAC */ static void __init aes_cmac_fips_test(void) { - struct aes_cmac_key key; + struct aes_cmac_key key __cleanup(aes_cmac_zeroize_key); u8 mac[AES_BLOCK_SIZE]; =20 if (aes_cmac_preparekey(&key, fips_test_key, sizeof(fips_test_key)) !=3D @@ -749,7 +749,6 @@ static void __init aes_cmac_fips_test(void) aes_cmac(&key, fips_test_data, sizeof(fips_test_data), mac); if (memcmp(fips_test_aes_cmac_value, mac, sizeof(mac)) !=3D 0) panic("aes: CMAC FIPS self-test failed (wrong MAC)\n"); - memzero_explicit(&key, sizeof(key)); } #else /* CONFIG_CRYPTO_LIB_AES_CBC_MACS */ static inline void aes_cmac_fips_test(void) --=20 2.55.0 From nobody Tue Sep 29 13:18:54 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 3E250479897 for ; Fri, 7 Aug 2026 12:59:25 +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=1786107576; cv=none; b=pccMA66YHV1lI+k5+jn2ETvTamvzn/ZLXbQaeIb4G39FSsrPB4zOcyuHoaIXkp6YgsQI89D5yrNZWdWg9RCDCOuALgPh6VGP+8zeq3P7SDlfXgXF728vqqsR4ByT/ZmzMqrdNEdRAOGKnTPF5o0ntbi2Iu66Ul5PDwFWFFSMI48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786107576; c=relaxed/simple; bh=c+Obj3KxZAXJqJFX2X9E/Kyv+qj00penHJsYWag3Dkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QUZ3Q8bdqVHqjurk+lu1EEVz1P1DfeHKYiLRTDDS95S3ruigi5o/FuWK5ycF0pReqZx3m8hGXVT0yZfhIejqgYx1cw3ZGXxZ5IXgZt7X9Rd4vxHmEOb5rDUbhfTOIkQLD5b1bHqn4weI9AFDDIz+cEelu+BdeEzUCkfDhd/GFbM= 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=RIzd/P5V; 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="RIzd/P5V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786107562; 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=4Ce3mbn9VnBLWH5P+vwgYp9VLPRTWUW0aQvMbeGeCrI=; b=RIzd/P5VKgncp1trAkAaDgAN2eMUExpfQPuRYAjCKpOREEabtNkH0L0qB6U8t3/M93SkEd zYBapY4bLBQ0ZZpAQVNU4mSnLqUuh9xMIfKrfpHK9VBoaHc6DJrjkVEiv+1L7IF2J7pJOE 0V8AA3D6xoLpygKM/QPpdSuxOMgLP/c= 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-328-WQL0Ke1hPIiluU26xBzukQ-1; Fri, 07 Aug 2026 08:59:16 -0400 X-MC-Unique: WQL0Ke1hPIiluU26xBzukQ-1 X-Mimecast-MFC-AGG-ID: WQL0Ke1hPIiluU26xBzukQ_1786107555 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 CE5F81956096; Fri, 7 Aug 2026 12:59:14 +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 F069D30001A2; Fri, 7 Aug 2026 12:59:11 +0000 (UTC) From: Thomas Huth To: Eric Biggers , Johannes Berg Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Namjae Jeon , linux-wireless@vger.kernel.org Subject: [PATCH v2 6/6] mac80211: fils_aead: Use __cleanup() for aes_cmac_key instead of memzero_explicit() Date: Fri, 7 Aug 2026 14:58:43 +0200 Message-ID: <20260807125845.1477067-7-thuth@redhat.com> In-Reply-To: <20260807125845.1477067-1-thuth@redhat.com> References: <20260807125845.1477067-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 By using __cleanup(aes_cmac_zeroize_key) for clearing the key data, we can save one line of code here. Signed-off-by: Thomas Huth Acked-by: Johannes Berg --- net/mac80211/fils_aead.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/mac80211/fils_aead.c b/net/mac80211/fils_aead.c index d2f4a17eab990..293590976489a 100644 --- a/net/mac80211/fils_aead.c +++ b/net/mac80211/fils_aead.c @@ -24,7 +24,7 @@ static int aes_s2v(const u8 *in_key, size_t key_len, size_t num_elem, const u8 *addr[], size_t len[], u8 *v) { u8 d[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE] =3D {}; - struct aes_cmac_key key; + struct aes_cmac_key key __cleanup(aes_cmac_zeroize_key); struct aes_cmac_ctx ctx; size_t i; int res; @@ -62,7 +62,6 @@ static int aes_s2v(const u8 *in_key, size_t key_len, aes_cmac_update(&ctx, d, AES_BLOCK_SIZE); aes_cmac_final(&ctx, v); =20 - memzero_explicit(&key, sizeof(key)); return 0; } =20 --=20 2.55.0