mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 13/13] lib/crypto: Add documentation about zeroization of key and context data
Date: Thu, 1 Oct 2026 08:51:22 +0200	[thread overview]
Message-ID: <c6cea3a7-4ca9-43fc-96f3-9b389f3d60da@redhat.com> (raw)
In-Reply-To: <20260930201434.GA61218@google.com>

On 30/09/2026 22.14, Eric Biggers wrote:
> On Wed, Sep 16, 2026 at 11:50:15AM +0200, Thomas Huth wrote:
>> +What to zeroize
>> +---------------
>> +
>> +The following types of structures hold sensitive material and should be
>> +zeroized after use:
>> +
>> +- **Key structures** (e.g. ``struct aes_key``, ``struct hmac_sha256_key``):
>> +  contain expanded round keys or prepared key material.
>> +
>> +- **HMAC/MAC context structures** (e.g. ``struct hmac_sha256_ctx``,
>> +  ``struct aes_cmac_ctx``): contain inner and outer hash states derived from
>> +  the key.
>> +
>> +- **Hash context structures** (e.g. ``struct sha256_ctx``): may contain
>> +  sensitive data being hashed.
>> +
>> +Not all of these require explicit cleanup by callers.  Many ``..._final()``
>> +functions already zeroize their context internally (see `Automatic vs. manual
>> +zeroization`_ below).
> 
> This should mention that the raw key that the key struct was prepared
> from needs to be zeroized as well.  Every in-kernel user of a keyed
> algorithm has to deal with this problem, as to "prepare" a key, you need
> to have the key already in the first place (whether it's passed in from
> userspace, or derived from some other key, or something else).
> 
> Zeroizing a 'struct aes_key' for example is kind of useless if the
> actual raw AES key is still in memory somewhere.
> 
> Any interest in sending a follow-up patch that clarifies this?  It
> really should clarify that users of cryptography in the kernel should
> apply zeroization to the full flow of their keys through the system
> including system calls, key derivation, key preparation, etc.
Agreed, adding some wording about raw keys makes sense. However, I'll be 
very short in time during the next one or two weeks, so if you would like to 
do it, please go ahead and send a patch. Otherwise I'll look into this in a 
week or two when I've got some more spare time again.

  Thanks,
   Thomas


  reply	other threads:[~2026-10-01  6:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  9:50 [PATCH v4 00/13] libcrypto: Provide more __cleanup functions for zeroizing data Thomas Huth
2026-09-16  9:50 ` [PATCH v4 01/13] lib/crypto: aes: Provide functions for zeroizing aes_key and aes_enckey Thomas Huth
2026-09-16  9:50 ` [PATCH v4 02/13] lib/crypto: aes-xts: Provide function for zeroizing aes_xts_key Thomas Huth
2026-09-16  9:50 ` [PATCH v4 03/13] lib/crypto: aes-gcm: Provide functions for zeroizing aes_gcm* structures Thomas Huth
2026-09-16  9:50 ` [PATCH v4 04/13] lib/crypto: aes-ccm: Provide functions for zeroizing aes_ccm* structures Thomas Huth
2026-09-16  9:50 ` [PATCH v4 05/13] lib/crypto: md5: Provide a function for zeroizing hmac_md5 structures Thomas Huth
2026-09-16  9:50 ` [PATCH v4 06/13] lib/crypto: sm3: Provide a function for zeroizing the sm3_ctx structure Thomas Huth
2026-09-16  9:50 ` [PATCH v4 07/13] lib/crypto: blake2: Provide functions for zeroizing blake2*_ctx structures Thomas Huth
2026-09-16  9:50 ` [PATCH v4 08/13] lib/crypto: sha1: Provide functions for zeroizing hmac_sha1 structures Thomas Huth
2026-09-16  9:50 ` [PATCH v4 09/13] security: keys: trusted: always clear the hmac_sha1_ctx before returning Thomas Huth
2026-09-16  9:50 ` [PATCH v4 10/13] x86/purgatory: Compile purgatory with -D__NO_FORTIFY Thomas Huth
2026-09-16  9:50 ` [PATCH v4 11/13] lib/crypto: sha2: Provide functions for zeroizing SHA2 hmac_sha* structures Thomas Huth
2026-09-24 14:58   ` Nathan Chancellor
2026-09-24 17:49     ` Eric Biggers
2026-09-24 18:40       ` Thomas Huth
2026-09-16  9:50 ` [PATCH v4 12/13] smb: client: Use hmac_sha256_zeroize_ctx function to clear hmac_sha256_ctx Thomas Huth
2026-09-16  9:50 ` [PATCH v4 13/13] lib/crypto: Add documentation about zeroization of key and context data Thomas Huth
2026-09-30 20:14   ` Eric Biggers
2026-10-01  6:51     ` Thomas Huth [this message]
2026-09-23  3:20 ` [PATCH v4 00/13] libcrypto: Provide more __cleanup functions for zeroizing data Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c6cea3a7-4ca9-43fc-96f3-9b389f3d60da@redhat.com \
    --to=thuth@redhat.com \
    --cc=Jason@zx2c4.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®