aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-crypt.c
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2009-12-10 18:51:55 -0500
committerAlasdair G Kergon <agk@redhat.com>2009-12-10 18:51:55 -0500
commit0b4309581b5be8749afdd5a9087fd82a2a5c9932 (patch)
tree4e29641aa1da9e8dc7ab8394f12162976ebef986 /drivers/md/dm-crypt.c
parent8e87b9b81b3c370f7e53c1ab6e1c3519ef37a644 (diff)
dm crypt: make wipe message also wipe tfm key
The "wipe key" message is used to wipe a volume key from memory temporarily, for example when suspending to RAM. There are two instances of the key in memory (inside crypto tfm) but only one got wiped. This patch wipes them both. Cc: stable@kernel.org Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-crypt.c')
-rw-r--r--drivers/md/dm-crypt.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index e412980763bd..f2c139305e13 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -934,14 +934,14 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
934 934
935 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); 935 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
936 936
937 return 0; 937 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
938} 938}
939 939
940static int crypt_wipe_key(struct crypt_config *cc) 940static int crypt_wipe_key(struct crypt_config *cc)
941{ 941{
942 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); 942 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
943 memset(&cc->key, 0, cc->key_size * sizeof(u8)); 943 memset(&cc->key, 0, cc->key_size * sizeof(u8));
944 return 0; 944 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
945} 945}
946 946
947/* 947/*
@@ -983,11 +983,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
983 return -ENOMEM; 983 return -ENOMEM;
984 } 984 }
985 985
986 if (crypt_set_key(cc, argv[1])) {
987 ti->error = "Error decoding key";
988 goto bad_cipher;
989 }
990
991 /* Compatibility mode for old dm-crypt cipher strings */ 986 /* Compatibility mode for old dm-crypt cipher strings */
992 if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) { 987 if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) {
993 chainmode = "cbc"; 988 chainmode = "cbc";
@@ -1015,6 +1010,11 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1015 strcpy(cc->chainmode, chainmode); 1010 strcpy(cc->chainmode, chainmode);
1016 cc->tfm = tfm; 1011 cc->tfm = tfm;
1017 1012
1013 if (crypt_set_key(cc, argv[1]) < 0) {
1014 ti->error = "Error decoding and setting key";
1015 goto bad_ivmode;
1016 }
1017
1018 /* 1018 /*
1019 * Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi". 1019 * Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi".
1020 * See comments at iv code 1020 * See comments at iv code
@@ -1085,11 +1085,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1085 goto bad_bs; 1085 goto bad_bs;
1086 } 1086 }
1087 1087
1088 if (crypto_ablkcipher_setkey(tfm, cc->key, key_size) < 0) {
1089 ti->error = "Error setting key";
1090 goto bad_device;
1091 }
1092
1093 if (sscanf(argv[2], "%llu", &tmpll) != 1) { 1088 if (sscanf(argv[2], "%llu", &tmpll) != 1) {
1094 ti->error = "Invalid iv_offset sector"; 1089 ti->error = "Invalid iv_offset sector";
1095 goto bad_device; 1090 goto bad_device;