Skip to content

Commit 82e12f1

Browse files
onikogregkh
authored andcommitted
dm crypt: wipe kernel key copy after IV initialization
commit dc94902 upstream. Loading key via kernel keyring service erases the internal key copy immediately after we pass it in crypto layer. This is wrong because IV is initialized later and we use wrong key for the initialization (instead of real key there's just zeroed block). The bug may cause data corruption if key is loaded via kernel keyring service first and later same crypt device is reactivated using exactly same key in hexbyte representation, or vice versa. The bug (and fix) affects only ciphers using following IVs: essiv, lmk and tcw. Fixes: c538f6e ("dm crypt: add ability to use keys from the kernel key retention service") Signed-off-by: Ondrej Kozina <okozina@redhat.com> Reviewed-by: Milan Broz <gmazyland@gmail.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6b8fdea commit 82e12f1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/md/dm-crypt.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,9 +2058,6 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
20582058

20592059
ret = crypt_setkey(cc);
20602060

2061-
/* wipe the kernel key payload copy in each case */
2062-
memset(cc->key, 0, cc->key_size * sizeof(u8));
2063-
20642061
if (!ret) {
20652062
set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
20662063
kzfree(cc->key_string);
@@ -2528,6 +2525,10 @@ static int crypt_ctr_cipher(struct dm_target *ti, char *cipher_in, char *key)
25282525
}
25292526
}
25302527

2528+
/* wipe the kernel key payload copy */
2529+
if (cc->key_string)
2530+
memset(cc->key, 0, cc->key_size * sizeof(u8));
2531+
25312532
return ret;
25322533
}
25332534

@@ -2966,6 +2967,9 @@ static int crypt_message(struct dm_target *ti, unsigned argc, char **argv)
29662967
return ret;
29672968
if (cc->iv_gen_ops && cc->iv_gen_ops->init)
29682969
ret = cc->iv_gen_ops->init(cc);
2970+
/* wipe the kernel key payload copy */
2971+
if (cc->key_string)
2972+
memset(cc->key, 0, cc->key_size * sizeof(u8));
29692973
return ret;
29702974
}
29712975
if (argc == 2 && !strcasecmp(argv[1], "wipe")) {
@@ -3012,7 +3016,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
30123016

30133017
static struct target_type crypt_target = {
30143018
.name = "crypt",
3015-
.version = {1, 18, 0},
3019+
.version = {1, 18, 1},
30163020
.module = THIS_MODULE,
30173021
.ctr = crypt_ctr,
30183022
.dtr = crypt_dtr,

0 commit comments

Comments
 (0)