diff options
author | Milan Broz <gmazyland@gmail.com> | 2019-07-09 15:22:12 +0200 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2019-07-09 14:14:21 -0400 |
commit | 4a52ffc7ca6f03005ce10c67412752dd068f79a3 (patch) | |
tree | f2bec54623cbca5900e467c5b159293850ba1c22 /drivers/md | |
parent | 131670c2625307551c23970ebcc0f8bc0fc9b4ef (diff) | |
download | linux-4a52ffc7ca6f03005ce10c67412752dd068f79a3.tar.gz linux-4a52ffc7ca6f03005ce10c67412752dd068f79a3.tar.bz2 linux-4a52ffc7ca6f03005ce10c67412752dd068f79a3.zip |
dm crypt: wipe private IV struct after key invalid flag is set
If a private IV wipe function fails, the code does not set the key
invalid flag. To fix this, move code to after the flag is set to
prevent the device from resuming in an inconsistent state.
Also, this allows using of a randomized key in private wipe function
(to be used in a following commit).
Signed-off-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-crypt.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 2587e94b0511..cd349e925649 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -2158,6 +2158,14 @@ static int crypt_wipe_key(struct crypt_config *cc) clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); get_random_bytes(&cc->key, cc->key_size); + + /* Wipe IV private keys */ + if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) { + r = cc->iv_gen_ops->wipe(cc); + if (r) + return r; + } + kzfree(cc->key_string); cc->key_string = NULL; r = crypt_setkey(cc); @@ -3050,14 +3058,8 @@ static int crypt_message(struct dm_target *ti, unsigned argc, char **argv, memset(cc->key, 0, cc->key_size * sizeof(u8)); return ret; } - if (argc == 2 && !strcasecmp(argv[1], "wipe")) { - if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) { - ret = cc->iv_gen_ops->wipe(cc); - if (ret) - return ret; - } + if (argc == 2 && !strcasecmp(argv[1], "wipe")) return crypt_wipe_key(cc); - } } error: |