From 0b173877fbc07f4922f0c6a6fc43fd99088befd2 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 11 Oct 2026 15:48:41 +0200 Subject: [PATCH] lib/crypto: x86/sha1: Follow the normal %rbp convention Some of the SHA-1 assembly functions push callee-save GPRs to the stack *before* they set up the frame pointer (%rbp). (They are leaf functions, but they need to set up a frame pointer anyway because they allocate a 16- or 32-byte-aligned buffer on the stack.) As a result, during these functions, 8(%rbp) doesn't contain a return address like it is supposed to. This differs from the convention used by C code, and it interferes with the frame pointer unwinder (CONFIG_UNWINDER_FRAME_POINTER=y). Specifically, if a call trace is dumped in these functions, then all entries are populated purely from the fallback scan of the entire stack: RIP: 0010:sha1_transform_avx2+0x1921/0x1ea0 [...] Call Trace: ? sha1_transform_avx+0x2a9/0xc90 ? sha1_blocks_avx2+0x78/0x140 ? kernel_fpu_end+0x2d/0x40 ? sha1_blocks_avx2+0x52/0x140 ? sha1_update+0x77/0x220 [...] ? do_syscall_64+0x6f/0x3e0 With this fix to follow the normal %rbp convention, the call trace is generated reliably: RIP: 0010:sha1_transform_avx2+0x66e/0x1ea0 [...] Call Trace: sha1_blocks_avx2+0x78/0x140 sha1_update+0x77/0x220 [...] do_syscall_64+0x6f/0x3e0 Reviewed-by: Ard Biesheuvel Link: https://patch.msgid.link/20261011134843.166585-2-ebiggers@kernel.org Signed-off-by: Eric Biggers --- lib/crypto/x86/sha1-avx2-asm.S | 10 +++++----- lib/crypto/x86/sha1-ssse3-and-avx.S | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/crypto/x86/sha1-avx2-asm.S b/lib/crypto/x86/sha1-avx2-asm.S index 91b2dc6db179..ca64d7104a47 100644 --- a/lib/crypto/x86/sha1-avx2-asm.S +++ b/lib/crypto/x86/sha1-avx2-asm.S @@ -622,6 +622,9 @@ .macro SHA1_VECTOR_ASM name SYM_FUNC_START(\name) + push %rbp + mov %rsp, %rbp + push %rbx push %r12 push %r13 @@ -631,8 +634,6 @@ RESERVE_STACK = (W_SIZE*4 + 8+24) /* Align stack */ - push %rbp - mov %rsp, %rbp and $~(0x20-1), %rsp sub $RESERVE_STACK, %rsp @@ -651,14 +652,13 @@ avx2_zeroupper - mov %rbp, %rsp - pop %rbp - + lea -40(%rbp), %rsp pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx + pop %rbp RET diff --git a/lib/crypto/x86/sha1-ssse3-and-avx.S b/lib/crypto/x86/sha1-ssse3-and-avx.S index 78b48cb09c5b..fe0faaf494c7 100644 --- a/lib/crypto/x86/sha1-ssse3-and-avx.S +++ b/lib/crypto/x86/sha1-ssse3-and-avx.S @@ -69,11 +69,12 @@ .macro SHA1_VECTOR_ASM name SYM_FUNC_START(\name) - push %rbx - push %r12 push %rbp mov %rsp, %rbp + push %rbx + push %r12 + sub $64, %rsp # allocate workspace and $~15, %rsp # align stack @@ -95,10 +96,10 @@ xor %eax, %eax rep stosq - mov %rbp, %rsp # deallocate workspace - pop %rbp + lea -16(%rbp), %rsp # deallocate workspace pop %r12 pop %rbx + pop %rbp RET SYM_FUNC_END(\name)