Skip to content

Commit

Permalink
KEYS: Fix skcipher IV clobbering
Browse files Browse the repository at this point in the history
The IV must not be modified by the skcipher operation so we need
to duplicate it.

Fixes: c3917fd ("KEYS: Use skcipher")
Cc: [email protected]
Reported-by: Mimi Zohar <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Sep 22, 2016
1 parent 2db34e7 commit 456bee9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions security/keys/encrypted-keys/encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 456bee9

Please sign in to comment.