X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=drivers%2Fmd%2Fdm-crypt.c;h=c8827ffd85bb961b7e9cad4d54647ea0251fd716;hb=8ce26169555cf5634263d39d3665e45300218a5e;hp=2c62c1169f78afa27109532d1970ec201d082cae;hpb=53f358a81e10e798f44af896ffacaedd7ac0269b;p=karo-tx-linux.git diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 2c62c1169f78..c8827ffd85bb 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -1324,20 +1324,29 @@ static int crypt_setkey_allcpus(struct crypt_config *cc) static int crypt_set_key(struct crypt_config *cc, char *key) { + int r = -EINVAL; + int key_string_len = strlen(key); + /* The key size may not be changed. */ - if (cc->key_size != (strlen(key) >> 1)) - return -EINVAL; + if (cc->key_size != (key_string_len >> 1)) + goto out; /* Hyphen (which gives a key_size of zero) means there is no key. */ if (!cc->key_size && strcmp(key, "-")) - return -EINVAL; + goto out; if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0) - return -EINVAL; + goto out; set_bit(DM_CRYPT_KEY_VALID, &cc->flags); - return crypt_setkey_allcpus(cc); + r = crypt_setkey_allcpus(cc); + +out: + /* Hex key string not needed after here, so wipe it. */ + memset(key, '0', key_string_len); + + return r; } static int crypt_wipe_key(struct crypt_config *cc)