lkml.org 
[lkml]   [2019]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.0 020/238] crypto: cfb - remove bogus memcpy() with src == dest
    Date
    5.0-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Eric Biggers <ebiggers@google.com>

    commit 6c2e322b3621dc8be72e5c86d4fdb587434ba625 upstream.

    The memcpy() in crypto_cfb_decrypt_inplace() uses walk->iv as both the
    source and destination, which has undefined behavior. It is unneeded
    because walk->iv is already used to hold the previous ciphertext block;
    thus, walk->iv is already updated to its final value. So, remove it.

    Also, note that in-place decryption is the only case where the previous
    ciphertext block is not directly available. Therefore, as a related
    cleanup I also updated crypto_cfb_encrypt_segment() to directly use the
    previous ciphertext block rather than save it into walk->iv. This makes
    it consistent with in-place encryption and out-of-place decryption; now
    only in-place decryption is different, because it has to be.

    Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode")
    Cc: <stable@vger.kernel.org> # v4.17+
    Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
    Signed-off-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    crypto/cfb.c | 8 ++++----
    1 file changed, 4 insertions(+), 4 deletions(-)

    --- a/crypto/cfb.c
    +++ b/crypto/cfb.c
    @@ -77,12 +77,14 @@ static int crypto_cfb_encrypt_segment(st
    do {
    crypto_cfb_encrypt_one(tfm, iv, dst);
    crypto_xor(dst, src, bsize);
    - memcpy(iv, dst, bsize);
    + iv = dst;

    src += bsize;
    dst += bsize;
    } while ((nbytes -= bsize) >= bsize);

    + memcpy(walk->iv, iv, bsize);
    +
    return nbytes;
    }

    @@ -162,7 +164,7 @@ static int crypto_cfb_decrypt_inplace(st
    const unsigned int bsize = crypto_cfb_bsize(tfm);
    unsigned int nbytes = walk->nbytes;
    u8 *src = walk->src.virt.addr;
    - u8 *iv = walk->iv;
    + u8 * const iv = walk->iv;
    u8 tmp[MAX_CIPHER_BLOCKSIZE];

    do {
    @@ -172,8 +174,6 @@ static int crypto_cfb_decrypt_inplace(st
    src += bsize;
    } while ((nbytes -= bsize) >= bsize);

    - memcpy(walk->iv, iv, bsize);
    -
    return nbytes;
    }


    \
     
     \ /
      Last update: 2019-03-22 13:39    [W:4.016 / U:0.484 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site