bitlk: Fix reading key data size in the decrypted key material

We've assumed that first 4 bytes of the decrypted key data is the
size of the key + metadata. Looks like this isn't true and only
first two bytes contain the size and the other two bytes are
unknown data, possibly related to reencryption and/or passphrase
change.

Fixes: #575
This commit is contained in:
Vojtech Trefny
2020-06-28 17:44:53 +02:00
parent 876ca59234
commit 588c8cf5b3

View File

@@ -908,7 +908,7 @@ static int decrypt_key(struct crypt_device *cd,
{
char *outbuf;
int r;
uint32_t key_size = 0;
uint16_t key_size = 0;
outbuf = crypt_safe_alloc(enc_key->keylength);
if (!outbuf)
@@ -923,10 +923,12 @@ static int decrypt_key(struct crypt_device *cd,
}
/* key_data has it's size as part of the metadata */
memcpy(&key_size, outbuf, 4);
key_size = le32_to_cpu(key_size);
memcpy(&key_size, outbuf, 2);
key_size = le16_to_cpu(key_size);
if (enc_key->keylength != key_size) {
log_err(cd, _("Wrong key size."));
log_err(cd, _("Unexpected key data size."));
log_dbg(cd, "Expected key data size: %zu, got %" PRIu16 "", enc_key->keylength, key_size);
r = -EINVAL;
goto out;
}