linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: David Howells <dhowells@redhat.com>,
	linux-crypto <linux-crypto@vger.kernel.org>,
	keyrings@vger.kernel.org
Subject: Re: [PATCH] trusted-keys: skcipher bug info
Date: Tue, 20 Sep 2016 08:59:06 -0400	[thread overview]
Message-ID: <1474376346.14532.33.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <20160920123555.GA22272@gondor.apana.org.au>

On Tue, 2016-09-20 at 20:35 +0800, Herbert Xu wrote:
> On Tue, Sep 20, 2016 at 08:11:51AM -0400, Mimi Zohar wrote:
> > Hi Herbert,
> > 
> > The initial random iv value, initialized in encrypted_init(), should
> > not be modified.  Commit c3917fd "KEYS: Use skcipher", which replaced
> > the blkcipher with skcipher, modifies the iv in
> > crypto_skcipher_encrypt()/decrypt().
> > 
> > The following example creates an encrypted key, writes the key to a
> > file, and then loads the key from the file.  To illustrate the problem,
> > this patch provides crypto_skcipher_encrypt()/decrypt() with a copy of
> > the iv.  With this change, the resulting test-key and test-key1 keys
> > are the same.
> 
> Sorry, I missed the subtlety.  This patch should fix the problem.

Thanks!

Mimi
> 
> ---8<---
> Subject: KEYS: Fix skcipher IV clobbering
> 
> The IV must not be modified by the skcipher operation so we need
> to duplicate it.
> 
> Fixes: c3917fd9dfbc ("KEYS: Use skcipher")
> Cc: stable@vger.kernel.org
> Reported-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
> index 5adbfc3..17a0610 100644
> --- a/security/keys/encrypted-keys/encrypted.c
> +++ b/security/keys/encrypted-keys/encrypted.c
> @@ -29,6 +29,7 @@
>  #include <linux/rcupdate.h>
>  #include <linux/scatterlist.h>
>  #include <linux/ctype.h>
> +#include <crypto/aes.h>
>  #include <crypto/hash.h>
>  #include <crypto/sha.h>
>  #include <crypto/skcipher.h>
> @@ -478,6 +479,7 @@ static int derived_key_encrypt(struct encrypted_key_payload *epayload,
>  	struct crypto_skcipher *tfm;
>  	struct skcipher_request *req;
>  	unsigned int encrypted_datalen;
> +	u8 iv[AES_BLOCK_SIZE];
>  	unsigned int padlen;
>  	char pad[16];
>  	int ret;
> @@ -500,8 +502,8 @@ static int derived_key_encrypt(struct encrypted_key_payload *epayload,
>  	sg_init_table(sg_out, 1);
>  	sg_set_buf(sg_out, epayload->encrypted_data, encrypted_datalen);
> 
> -	skcipher_request_set_crypt(req, sg_in, sg_out, encrypted_datalen,
> -				   epayload->iv);
> +	memcpy(iv, epayload->iv, sizeof(iv));
> +	skcipher_request_set_crypt(req, sg_in, sg_out, encrypted_datalen, iv);
>  	ret = crypto_skcipher_encrypt(req);
>  	tfm = crypto_skcipher_reqtfm(req);
>  	skcipher_request_free(req);
> @@ -581,6 +583,7 @@ static int derived_key_decrypt(struct encrypted_key_payload *epayload,
>  	struct crypto_skcipher *tfm;
>  	struct skcipher_request *req;
>  	unsigned int encrypted_datalen;
> +	u8 iv[AES_BLOCK_SIZE];
>  	char pad[16];
>  	int ret;
> 
> @@ -599,8 +602,8 @@ static int derived_key_decrypt(struct encrypted_key_payload *epayload,
>  		   epayload->decrypted_datalen);
>  	sg_set_buf(&sg_out[1], pad, sizeof pad);
> 
> -	skcipher_request_set_crypt(req, sg_in, sg_out, encrypted_datalen,
> -				   epayload->iv);
> +	memcpy(iv, epayload->iv, sizeof(iv));
> +	skcipher_request_set_crypt(req, sg_in, sg_out, encrypted_datalen, iv);
>  	ret = crypto_skcipher_decrypt(req);
>  	tfm = crypto_skcipher_reqtfm(req);
>  	skcipher_request_free(req);
> 

      reply	other threads:[~2016-09-20 12:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20 12:11 [PATCH] trusted-keys: skcipher bug info Mimi Zohar
2016-09-20 12:35 ` Herbert Xu
2016-09-20 12:59   ` Mimi Zohar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474376346.14532.33.camel@linux.vnet.ibm.com \
    --to=zohar@linux.vnet.ibm.com \
    --cc=dhowells@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).