]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
crypto: x86/twofish-3way - Fix %rbp usage
authorEric Biggers <ebiggers@google.com>
Tue, 19 Dec 2017 00:40:26 +0000 (16:40 -0800)
committerSasha Levin <alexander.levin@microsoft.com>
Sun, 4 Mar 2018 15:28:24 +0000 (10:28 -0500)
commit45cafc0aac3ff6cd32a14b1edc6ad7eb0649407c
tree3bc88a0de16d18068e7a5ad9f26ed20c23ca9c38
parent03915a4958d91a7b1c5668bb1773784fcef4777e
crypto: x86/twofish-3way - Fix %rbp usage

[ Upstream commit d8c7fe9f2a486a6e5f0d5229ca43807af5ab22c6 ]

Using %rbp as a temporary register breaks frame pointer convention and
breaks stack traces when unwinding from an interrupt in the crypto code.

In twofish-3way, we can't simply replace %rbp with another register
because there are none available.  Instead, we use the stack to hold the
values that %rbp, %r11, and %r12 were holding previously.  Each of these
values represents the half of the output from the previous Feistel round
that is being passed on unchanged to the following round.  They are only
used once per round, when they are exchanged with %rax, %rbx, and %rcx.

As a result, we free up 3 registers (one per block) and can reassign
them so that %rbp is not used, and additionally %r14 and %r15 are not
used so they do not need to be saved/restored.

There may be a small overhead caused by replacing 'xchg REG, REG' with
the needed sequence 'mov MEM, REG; mov REG, MEM; mov REG, REG' once per
round.  But, counterintuitively, when I tested "ctr-twofish-3way" on a
Haswell processor, the new version was actually about 2% faster.
(Perhaps 'xchg' is not as well optimized as plain moves.)

Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
arch/x86/crypto/twofish-x86_64-asm_64-3way.S