24 Mar, 2019

2 commits

  • 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: # v4.17+
    Cc: James Bottomley
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     
  • commit 394a9e044702e6a8958a5e89d2a291605a587a2a upstream.

    Like some other block cipher mode implementations, the CFB
    implementation assumes that while walking through the scatterlist, a
    partial block does not occur until the end. But the walk is incorrectly
    being done with a blocksize of 1, as 'cra_blocksize' is set to 1 (since
    CFB is a stream cipher) but no 'chunksize' is set. This bug causes
    incorrect encryption/decryption for some scatterlist layouts.

    Fix it by setting the 'chunksize'. Also extend the CFB test vectors to
    cover this bug as well as cases where the message length is not a
    multiple of the block size.

    Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode")
    Cc: # v4.17+
    Cc: James Bottomley
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

10 Jan, 2019

1 commit

  • commit fa4600734b74f74d9169c3015946d4722f8bcf79 upstream.

    crypto_cfb_decrypt_segment() incorrectly XOR'ed generated keystream with
    IV, rather than with data stream, resulting in incorrect decryption.
    Test vectors will be added in the next patch.

    Signed-off-by: Dmitry Eremin-Solenikov
    Cc: stable@vger.kernel.org
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Dmitry Eremin-Solenikov
     

13 Dec, 2018

1 commit

  • commit e5bde04ccce64d808f8b00a489a1fe5825d285cb upstream.

    In multiple functions, the algorithm fields are read after its reference
    is dropped through crypto_mod_put. In this case, the algorithm memory
    may be freed, resulting in use-after-free bugs. This patch delays the
    put operation until the algorithm is never used.

    Fixes: 79c65d179a40 ("crypto: cbc - Convert to skcipher")
    Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode")
    Fixes: 043a44001b9e ("crypto: pcbc - Convert to skcipher")
    Cc:
    Signed-off-by: Pan Bian
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Pan Bian
     

21 Apr, 2018

1 commit

  • We avoid various VLAs[1] by using constant expressions for block size
    and alignment mask.

    [1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

    Signed-off-by: Salvatore Mesoraca
    Signed-off-by: Herbert Xu

    Salvatore Mesoraca
     

09 Mar, 2018

1 commit

  • TPM security routines require encryption and decryption with AES in
    CFB mode, so add it to the Linux Crypto schemes. CFB is basically a
    one time pad where the pad is generated initially from the encrypted
    IV and then subsequently from the encrypted previous block of
    ciphertext. The pad is XOR'd into the plain text to get the final
    ciphertext.

    https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#CFB

    Signed-off-by: James Bottomley
    Signed-off-by: Herbert Xu

    James Bottomley