cryptsetup: handle more gracefully if "keyslots" LUKS2 JSON header field is invalid

The field is not owned by us (even though is in our JSON objects) but by
the LUKS2 spec. Hence let's handle this a bit more gracefully: let's not
get confused by it, just warn and skip over it.

Fixes: #20847
This commit is contained in:
Lennart Poettering
2021-09-28 16:47:08 +02:00
parent 5918a93355
commit 1641c2b112
4 changed files with 42 additions and 17 deletions
+6 -2
View File
@@ -34,8 +34,12 @@ static int search_policy_hash(
return log_error_errno(r, "Failed to read JSON token data off disk: %m");
keyslot = cryptsetup_get_keyslot_from_token(v);
if (keyslot < 0)
return log_error_errno(keyslot, "Failed to determine keyslot of JSON token: %m");
if (keyslot < 0) {
/* Handle parsing errors of the keyslots field gracefully, since it's not 'owned' by
* us, but by the LUKS2 spec */
log_warning_errno(keyslot, "Failed to determine keyslot of JSON token %i, skipping: %m", token);
continue;
}
w = json_variant_by_key(v, "tpm2-policy-hash");
if (!w || !json_variant_is_string(w))