aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-crypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/dm-crypt.c')
-rw-r--r--drivers/md/dm-crypt.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 2c62c1169f7..c8827ffd85b 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)
1324 1324
1325static int crypt_set_key(struct crypt_config *cc, char *key) 1325static int crypt_set_key(struct crypt_config *cc, char *key)
1326{ 1326{
1327 int r = -EINVAL;
1328 int key_string_len = strlen(key);
1329
1327 /* The key size may not be changed. */ 1330 /* The key size may not be changed. */
1328 if (cc->key_size != (strlen(key) >> 1)) 1331 if (cc->key_size != (key_string_len >> 1))
1329 return -EINVAL; 1332 goto out;
1330 1333
1331 /* Hyphen (which gives a key_size of zero) means there is no key. */ 1334 /* Hyphen (which gives a key_size of zero) means there is no key. */
1332 if (!cc->key_size && strcmp(key, "-")) 1335 if (!cc->key_size && strcmp(key, "-"))
1333 return -EINVAL; 1336 goto out;
1334 1337
1335 if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0) 1338 if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
1336 return -EINVAL; 1339 goto out;
1337 1340
1338 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); 1341 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
1339 1342
1340 return crypt_setkey_allcpus(cc); 1343 r = crypt_setkey_allcpus(cc);
1344
1345out:
1346 /* Hex key string not needed after here, so wipe it. */
1347 memset(key, '0', key_string_len);
1348
1349 return r;
1341} 1350}
1342 1351
1343static int crypt_wipe_key(struct crypt_config *cc) 1352static int crypt_wipe_key(struct crypt_config *cc)