mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 19:00:02 +01:00
Fix issues reported by valgrind.
keyslot_cipher member leaked after existing LUKS2 context reload. crypt_keyslot_set_encryption may access freed memory if crypt_keyslot_get_encryption was previously called with CRYPT_ANY_SLOT parameter.
This commit is contained in:
10
lib/setup.c
10
lib/setup.c
@@ -705,9 +705,10 @@ static int _crypt_load_luks2(struct crypt_device *cd, int reload, int repair)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reload)
|
if (reload) {
|
||||||
LUKS2_hdr_free(cd, &cd->u.luks2.hdr);
|
LUKS2_hdr_free(cd, &cd->u.luks2.hdr);
|
||||||
else
|
free(cd->u.luks2.keyslot_cipher);
|
||||||
|
} else
|
||||||
cd->type = type;
|
cd->type = type;
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
@@ -4815,14 +4816,17 @@ int crypt_keyslot_set_encryption(struct crypt_device *cd,
|
|||||||
const char *cipher,
|
const char *cipher,
|
||||||
size_t key_size)
|
size_t key_size)
|
||||||
{
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
if (!cd || !cipher || ! key_size || !isLUKS2(cd->type))
|
if (!cd || !cipher || ! key_size || !isLUKS2(cd->type))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (LUKS2_keyslot_cipher_incompatible(cd, cipher))
|
if (LUKS2_keyslot_cipher_incompatible(cd, cipher))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
tmp = strdup(cipher);
|
||||||
free(cd->u.luks2.keyslot_cipher);
|
free(cd->u.luks2.keyslot_cipher);
|
||||||
cd->u.luks2.keyslot_cipher = strdup(cipher);
|
cd->u.luks2.keyslot_cipher = tmp;
|
||||||
if (!cd->u.luks2.keyslot_cipher)
|
if (!cd->u.luks2.keyslot_cipher)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
cd->u.luks2.keyslot_key_size = key_size;
|
cd->u.luks2.keyslot_key_size = key_size;
|
||||||
|
|||||||
Reference in New Issue
Block a user