aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2011-03-24 09:54:27 -0400
committerAlasdair G Kergon <agk@redhat.com>2011-03-24 09:54:27 -0400
commitde8be5ac70f50a2340f24fd769a1aafa5a51ae34 (patch)
tree1f4b7a5cddd6c6a78412a2dbd9ec071f00a41d1d /drivers/md
parent3407ef5262b55ca5d7139d2b555ef792fe531eec (diff)
dm crypt: wipe keys string immediately after key is set
Always wipe the original copy of the key after processing it in crypt_set_key(). Signed-off-by: Milan Broz <mbroz@redhat.com> Acked-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-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 4e054bd91664..7dcae0d74db7 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1331,20 +1331,29 @@ static int crypt_setkey_allcpus(struct crypt_config *cc)
1331 1331
1332static int crypt_set_key(struct crypt_config *cc, char *key) 1332static int crypt_set_key(struct crypt_config *cc, char *key)
1333{ 1333{
1334 int r = -EINVAL;
1335 int key_string_len = strlen(key);
1336
1334 /* The key size may not be changed. */ 1337 /* The key size may not be changed. */
1335 if (cc->key_size != (strlen(key) >> 1)) 1338 if (cc->key_size != (key_string_len >> 1))
1336 return -EINVAL; 1339 goto out;
1337 1340
1338 /* Hyphen (which gives a key_size of zero) means there is no key. */ 1341 /* Hyphen (which gives a key_size of zero) means there is no key. */
1339 if (!cc->key_size && strcmp(key, "-")) 1342 if (!cc->key_size && strcmp(key, "-"))
1340 return -EINVAL; 1343 goto out;
1341 1344
1342 if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0) 1345 if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
1343 return -EINVAL; 1346 goto out;
1344 1347
1345 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); 1348 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
1346 1349
1347 return crypt_setkey_allcpus(cc); 1350 r = crypt_setkey_allcpus(cc);
1351
1352out:
1353 /* Hex key string not needed after here, so wipe it. */
1354 memset(key, '0', key_string_len);
1355
1356 return r;
1348} 1357}
1349 1358
1350static int crypt_wipe_key(struct crypt_config *cc) 1359static int crypt_wipe_key(struct crypt_config *cc)