Re: [PATCH v4 11/13] lib/crypto: sha2: Provide functions for zeroizing SHA2 hmac_sha* structures

From: Nathan Chancellor

Date: Thu Sep 24 2026 - 11:03:40 EST


Hi Thomas,

On Wed, Sep 16, 2026 at 11:50:13AM +0200, Thomas Huth wrote:
> In certain cases crypto code functions need to zeroize their local SHA2
> hmac_sha*_key or hmac_sha*_ctx structures after use to avoid leaking
> sensitive material on the stack.
> Provide hmac_sha*_zeroize_key() and hmac_sha*_zeroize_ctx() helper
> functions that can be used with __cleanup() to automatically zeroize
> the structure when it goes out of scope.
>
> Reviewed-by: Namjae Jeon <linkinjeon@xxxxxxxxxx>
> Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx>
> ---
> include/crypto/sha2.h | 73 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 73 insertions(+)
>
> diff --git a/include/crypto/sha2.h b/include/crypto/sha2.h
> index 7bb8fe169daf2..22fbc37ae8407 100644
> --- a/include/crypto/sha2.h
> +++ b/include/crypto/sha2.h
> @@ -7,6 +7,7 @@
> #define _CRYPTO_SHA2_H
>
> #include <linux/types.h>
> +#include <linux/string.h>

I am seeing a build failure with CONFIG_CFI=y after this patch landed in
-next as commit 09eb210b7deb ("lib/crypto: sha2: Provide functions for
zeroizing SHA2 hmac_sha* structures").

$ printf 'CONFIG_%s=y\n' CFI KEXEC_FILE >kernel/configs/repro.config

$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper defconfig repro.config arch/x86/purgatory/
ld.lld: error: undefined symbol: __memset
>>> referenced by string.c
>>> arch/x86/purgatory/purgatory.ro:(__UNIQUE_ID_addressable___memset_5)

ld.lld: error: undefined symbol: __memmove
>>> referenced by string.c
>>> arch/x86/purgatory/purgatory.ro:(__UNIQUE_ID_addressable___memmove_6)
make[6]: *** [arch/x86/purgatory/Makefile:80: arch/x86/purgatory/purgatory.chk] Error 1
...

This comes from the instances of KCFI_REFERENCE in
arch/x86/include/asm/string_64.h. Maybe __DISABLE_EXPORTS should be set
for the full purgatory to avoid this? I am juggling a lot of stuff at
the moment so just this report instead of a full patch.

diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index cde8463b4d84..aa5b48c47e4f 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -11,8 +11,6 @@ $(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE
$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
$(call if_changed_rule,cc_o_c)

-CFLAGS_sha256.o := -D__DISABLE_EXPORTS
-
# When profile-guided optimization is enabled, llvm emits two different
# overlapping text sections, which is not supported by kexec. Remove profile
# optimization flags.
@@ -38,6 +36,7 @@ PURGATORY_CFLAGS += -fpic -fvisibility=hidden
PURGATORY_CFLAGS += $(DISABLE_KSTACK_ERASE) -DDISABLE_BRANCH_PROFILING
PURGATORY_CFLAGS += -fno-stack-protector
PURGATORY_CFLAGS += -D__NO_FORTIFY
+PURGATORY_CFLAGS += -D__DISABLE_EXPORTS

# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
# in turn leaves some undefined symbols like __fentry__ in purgatory and not
--
Cheers,
Nathan