Skip to content

Commit

Permalink
Fix bad 'bp' value warning
Browse files Browse the repository at this point in the history
We use `rbp` register in `mpi_mul_mont_mod_p256_x86_64`
function to save result of `mulxq` operation. That breaks
frame pointer convention and breaks stack traces. The same
problem described here:
https://lists.openwall.net/linux-kernel/2017/11/22/255
We can't use %rbp with CONFIG_FRAME_POINTER, so check
if CONFIG_FRAME_POINTER is set and use %rdi register
instead of %rbp.
  • Loading branch information
EvgeniiMekhanik committed Nov 24, 2024
1 parent 82064e2 commit 5b76bb3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tls/bignum_x86-64.S
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,9 @@ SYM_FUNC_END(mpi_from_mont_p256_x86_64)
*/
SYM_FUNC_START_32(mpi_mul_mont_mod_p256_x86_64)
pushq %rbx
#if defined(__KERNEL__) && !defined(CONFIG_FRAME_POINTER)
pushq %rbp
#endif
pushq %r12
pushq %r13
pushq %r14
Expand Down Expand Up @@ -1727,8 +1729,15 @@ SYM_FUNC_START_32(mpi_mul_mont_mod_p256_x86_64)
# A[3] * B[0]
movq 24(%rsi), %rdx
adcxq %rax, %r12
#if defined(__KERNEL__) && !defined(CONFIG_FRAME_POINTER)
mulxq (%rcx), %rbp, %rax
adoxq %rbp, %r11
#else
pushq %rdi
mulxq (%rcx), %rdi, %rax
adoxq %rdi, %r11
popq %rdi
#endif
adoxq %rax, %r12
# A[3] * B[2]
mulxq 16(%rcx), %rdx, %rax
Expand All @@ -1748,7 +1757,9 @@ SYM_FUNC_START_32(mpi_mul_mont_mod_p256_x86_64)
popq %r14
popq %r13
popq %r12
#if defined(__KERNEL__) && !defined(CONFIG_FRAME_POINTER)
popq %rbp
#endif
popq %rbx
retq
SYM_FUNC_END(mpi_mul_mont_mod_p256_x86_64)
Expand Down

0 comments on commit 5b76bb3

Please sign in to comment.