crypto: arm64/aes-ccm - Rewrite skcipher walker loop
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 30 Jan 2023 08:58:51 +0000 (16:58 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 10 Feb 2023 09:20:19 +0000 (17:20 +0800)
commit57ead1bf1c5430c5f663dfd3399040d90db9c7ab
tree3c35d2db028dc0744afd3752884a6cf8e5473e09
parent808d065ad7367e9552b054aa3e092b78027bdf3e
crypto: arm64/aes-ccm - Rewrite skcipher walker loop

An often overlooked aspect of the skcipher walker API is that an
error is not just indicated by a non-zero return value, but by the
fact that walk->nbytes is zero.

Thus it is an error to call skcipher_walk_done after getting back
walk->nbytes == 0 from the previous interaction with the walker.

This is because when walk->nbytes is zero the walker is left in
an undefined state and any further calls to it may try to free
uninitialised stack memory.

The arm64 ccm code has to deal with zero-length messages, and
it needs to process data even when walk->nbytes == 0 is returned.
It doesn't have this bug because there is an explicit check for
walk->nbytes != 0 prior to the skcipher_walk_done call.

However, the loop is still sufficiently different from the usual
layout and it appears to have been copied into other code which
then ended up with this bug.  This patch rewrites it to follow the
usual convention of checking walk->nbytes.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/arm64/crypto/aes-ce-ccm-glue.c