Skip to content

Commit

Permalink
crypto: sanity check that LUKS header strings are NUL-terminated
Browse files Browse the repository at this point in the history
The LUKS spec requires that header strings are NUL-terminated, and our
code relies on that. Protect against maliciously crafted headers by
adding validation.

Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
  • Loading branch information
berrange committed Oct 27, 2022
1 parent f1018ea commit c1d8634
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crypto/block-luks.c
Expand Up @@ -554,6 +554,24 @@ qcrypto_block_luks_check_header(const QCryptoBlockLUKS *luks, Error **errp)
return -1;
}

if (!memchr(luks->header.cipher_name, '\0',
sizeof(luks->header.cipher_name))) {
error_setg(errp, "LUKS header cipher name is not NUL terminated");
return -1;
}

if (!memchr(luks->header.cipher_mode, '\0',
sizeof(luks->header.cipher_mode))) {
error_setg(errp, "LUKS header cipher mode is not NUL terminated");
return -1;
}

if (!memchr(luks->header.hash_spec, '\0',
sizeof(luks->header.hash_spec))) {
error_setg(errp, "LUKS header hash spec is not NUL terminated");
return -1;
}

/* Check all keyslots for corruption */
for (i = 0 ; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS ; i++) {

Expand Down

0 comments on commit c1d8634

Please sign in to comment.