Skip to content

Commit

Permalink
crypto: x86/sha1 - fix stack alignment of AVX2 variant
Browse files Browse the repository at this point in the history
The AVX2 implementation might waste up to a page of stack memory because
of a wrong alignment calculation. This will, in the worst case, increase
the stack usage of sha1_transform_avx2() alone to 5.4 kB -- way to big
for a kernel function. Even worse, it might also allocate *less* bytes
than needed if the stack pointer is already aligned bacause in that case
the 'sub %rbx, %rsp' is effectively moving the stack pointer upwards,
not downwards.

Fix those issues by changing and simplifying the alignment calculation
to use a 32 byte alignment, the alignment really needed.

Cc: Chandramouli Narayanan <mouli@linux.intel.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Reviewed-by: H. Peter Anvin <hpa@linux.intel.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Mathias Krause authored and Herbert Xu committed Mar 25, 2014
1 parent 6ca5afb commit 6c8c17c
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions arch/x86/crypto/sha1_avx2_x86_64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,7 @@ _loop3:

/* Align stack */
mov %rsp, %rbx
and $(0x1000-1), %rbx
sub $(8+32), %rbx
sub %rbx, %rsp
and $~(0x20-1), %rsp
push %rbx
sub $RESERVE_STACK, %rsp

Expand All @@ -665,8 +663,7 @@ _loop3:
avx2_zeroupper

add $RESERVE_STACK, %rsp
pop %rbx
add %rbx, %rsp
pop %rsp

pop %r15
pop %r14
Expand Down

0 comments on commit 6c8c17c

Please sign in to comment.