Skip to content

Commit 46d8c4b

Browse files
committed
crypto: padlock-aes - Fix Nano workaround data corruption
This was detected by the self-test thanks to Ard's chunking patch. I finally got around to testing this out on my ancient Via box. It turns out that the workaround got the assembly wrong and we end up doing count + initial cycles of the loop instead of just count. This obviously causes corruption, either by overwriting the source that is yet to be processed, or writing over the end of the buffer. On CPUs that don't require the workaround only ECB is affected. On Nano CPUs both ECB and CBC are affected. This patch fixes it by doing the subtraction prior to the assembly. Fixes: a76c1c2 ("crypto: padlock-aes - work around Nano CPU...") Cc: <stable@vger.kernel.org> Reported-by: Jamie Heilman <jamie@audible.transient.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2546da9 commit 46d8c4b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/crypto/padlock-aes.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,16 @@ static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
266266
return;
267267
}
268268

269+
count -= initial;
270+
269271
if (initial)
270272
asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
271273
: "+S"(input), "+D"(output)
272274
: "d"(control_word), "b"(key), "c"(initial));
273275

274276
asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
275277
: "+S"(input), "+D"(output)
276-
: "d"(control_word), "b"(key), "c"(count - initial));
278+
: "d"(control_word), "b"(key), "c"(count));
277279
}
278280

279281
static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
@@ -284,14 +286,16 @@ static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
284286
if (count < cbc_fetch_blocks)
285287
return cbc_crypt(input, output, key, iv, control_word, count);
286288

289+
count -= initial;
290+
287291
if (initial)
288292
asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */
289293
: "+S" (input), "+D" (output), "+a" (iv)
290294
: "d" (control_word), "b" (key), "c" (initial));
291295

292296
asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */
293297
: "+S" (input), "+D" (output), "+a" (iv)
294-
: "d" (control_word), "b" (key), "c" (count-initial));
298+
: "d" (control_word), "b" (key), "c" (count));
295299
return iv;
296300
}
297301

0 commit comments

Comments
 (0)