Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: padlock-sha - Fix stack alignment

The PadLock hardware requires the output buffer for SHA to be
128-bit aligned. We currentply place the buffer on the stack,
and ask gcc to align it to 128 bits. That doesn't work on i386
because the kernel stack is only aligned to 32 bits. This patch
changes the code to align the buffer by hand so that the hardware
doesn't fault on unaligned buffers.

Reported-by: Séguier Régis <rguier@e-teleport.net>
Tested-by: Séguier Régis <rguier@e-teleport.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+12 -2
+12 -2
drivers/crypto/padlock-sha.c
··· 24 24 #include <asm/i387.h> 25 25 #include "padlock.h" 26 26 27 + #ifdef CONFIG_64BIT 28 + #define STACK_ALIGN 16 29 + #else 30 + #define STACK_ALIGN 4 31 + #endif 32 + 27 33 struct padlock_sha_desc { 28 34 struct shash_desc fallback; 29 35 }; ··· 70 64 /* We can't store directly to *out as it may be unaligned. */ 71 65 /* BTW Don't reduce the buffer size below 128 Bytes! 72 66 * PadLock microcode needs it that big. */ 73 - char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT))); 67 + char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__ 68 + ((aligned(STACK_ALIGN))); 69 + char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); 74 70 struct padlock_sha_desc *dctx = shash_desc_ctx(desc); 75 71 struct sha1_state state; 76 72 unsigned int space; ··· 136 128 /* We can't store directly to *out as it may be unaligned. */ 137 129 /* BTW Don't reduce the buffer size below 128 Bytes! 138 130 * PadLock microcode needs it that big. */ 139 - char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT))); 131 + char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__ 132 + ((aligned(STACK_ALIGN))); 133 + char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); 140 134 struct padlock_sha_desc *dctx = shash_desc_ctx(desc); 141 135 struct sha256_state state; 142 136 unsigned int space;