• Herbert Xu's avatar
    crypto: arm64/aes-ccm - Rewrite skcipher walker loop · 57ead1bf
    Herbert Xu authored
    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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    Tested-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    57ead1bf
aes-ce-ccm-glue.c 7.2 KB