• John Allen's avatar
    crypto: ccp - Fix use of merged scatterlists · 8a302808
    John Allen authored
    Running the crypto manager self tests with
    CONFIG_CRYPTO_MANAGER_EXTRA_TESTS may result in several types of errors
    when using the ccp-crypto driver:
    
    alg: skcipher: cbc-des3-ccp encryption failed on test vector 0; expected_error=0, actual_error=-5 ...
    
    alg: skcipher: ctr-aes-ccp decryption overran dst buffer on test vector 0 ...
    
    alg: ahash: sha224-ccp test failed (wrong result) on test vector ...
    
    These errors are the result of improper processing of scatterlists mapped
    for DMA.
    
    Given a scatterlist in which entries are merged as part of mapping the
    scatterlist for DMA, the DMA length of a merged entry will reflect the
    combined length of the entries that were merged. The subsequent
    scatterlist entry will contain DMA information for the scatterlist entry
    after the last merged entry, but the non-DMA information will be that of
    the first merged entry.
    
    The ccp driver does not take this scatterlist merging into account. To
    address this, add a second scatterlist pointer to track the current
    position in the DMA mapped representation of the scatterlist. Both the DMA
    representation and the original representation of the scatterlist must be
    tracked as while most of the driver can use just the DMA representation,
    scatterlist_map_and_copy() must use the original representation and
    expects the scatterlist pointer to be accurate to the original
    representation.
    
    In order to properly walk the original scatterlist, the scatterlist must
    be walked until the combined lengths of the entries seen is equal to the
    DMA length of the current entry being processed in the DMA mapped
    representation.
    
    Fixes: 63b94509 ("crypto: ccp - CCP device driver and interface support")
    Signed-off-by: default avatarJohn Allen <john.allen@amd.com>
    Cc: stable@vger.kernel.org
    Acked-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    8a302808
ccp-dev.h 16.1 KB