(void) crypt_log_debug_errno(cd, r, "Token %d: no matching TPM2 token data found.", token);
return -EPERM;
}
- if (IN_SET(r, -EREMCHG, -EREMOTE)) {
+ if (IN_SET(r, -EREMCHG, -EREMOTE, -EADDRNOTAVAIL)) {
/* Remap as above. Note: For now without -EUCLEAN because currently the only error it
* reports won't be solved by moving to another token. */
(void) crypt_log_debug_errno(cd, r, "Token %d: TPM policy does not match current system state, skipping.", token);
srk,
ret_decrypted_key);
if (r == -EREMOTE)
- return log_warning_errno(r, "TPM key integrity check failed or NV index unusable. Key enrolled in superblock most likely does not belong to this TPM.");
+ return log_warning_errno(r, "TPM key integrity check failed. Key enrolled in superblock most likely does not belong to this TPM.");
+ if (r == -EADDRNOTAVAIL)
+ return log_warning_errno(r, "NV index referenced by token is missing, unwritten, or unusable, it could be for another system.");
if (r == -EILSEQ)
return log_error_errno(SYNTHETIC_ERRNO(ENOANO), "Bad PIN."); /* cryptsetup docs say we should return ENOANO on bad PIN */
if (r == -ENOLCK)
&tpm2_key);
if (r == -EREMOTE)
return log_error_errno(r, "TPM key integrity check failed. Key most likely does not belong to this TPM.");
+ if (r == -EADDRNOTAVAIL)
+ return log_error_errno(r, "NV index referenced by key is missing, unwritten, or unusable, it could be for another system.");
if (ERRNO_IS_NEG_TPM2_UNSEAL_BAD_PCR(r))
return log_error_errno(r, "TPM policy does not match current system state. Either system has been tempered with or policy out-of-date: %m");
if (r < 0)
{ "io.systemd.Credentials.KeyBelongsToOtherTPM", EREMOTE, "The TPM integrity check for this key failed, key probably belongs to another TPM, or was corrupted." },
{ "io.systemd.Credentials.TPMInDictionaryLockout", ENOLCK, "The TPM is in dictionary lockout mode, cannot operate." },
{ "io.systemd.Credentials.UnexpectedPCRState" , EUCLEAN, "Unexpected TPM PCR state of the system." },
+ { "io.systemd.Credentials.NVIndexUnusable", EADDRNOTAVAIL, "The NV index referenced by the key is missing, unwritten, or unusable, it could be for another system." },
};
const CredentialsVarlinkError* credentials_varlink_error_by_id(const char *id) {
srk,
ret_decrypted_key);
if (r == -EREMOTE)
- return log_warning_errno(r, "TPM key integrity check failed or NV index unusable. Key enrolled in superblock most likely does not belong to this TPM.");
+ return log_warning_errno(r, "TPM key integrity check failed. Key enrolled in superblock most likely does not belong to this TPM.");
+ if (r == -EADDRNOTAVAIL)
+ return log_warning_errno(r, "NV index referenced by token is missing, unwritten, or unusable, it could be for another system.");
if (ERRNO_IS_NEG_TPM2_UNSEAL_BAD_PCR(r)) {
log_warning_errno(r, "TPM policy does not match current system state. Either system has been tempered with or policy out-of-date: %m");
/* Normalize to -EPERM so callers don't confuse it with -ENOANO's "needs PIN" meaning. */
srk,
ret_decrypted_key);
if (r == -EREMOTE)
- return log_warning_errno(r, "TPM key integrity check failed or NV index unusable. Key enrolled in superblock most likely does not belong to this TPM.");
+ return log_warning_errno(r, "TPM key integrity check failed. Key enrolled in superblock most likely does not belong to this TPM.");
+ if (r == -EADDRNOTAVAIL)
+ return log_warning_errno(r, "NV index referenced by token is missing, unwritten, or unusable, it could be for another system.");
if (ERRNO_IS_NEG_TPM2_UNSEAL_BAD_PCR(r)) {
log_warning_errno(r, "TPM policy does not match current system state. Either system has been tempered with or policy out-of-date: %m");
/* Normalize to -EPERM so callers don't confuse it with -ENOANO's "needs PIN" meaning. */
"Submitted policy does not match policy stored in PolicyAuthorizeNV.");
if ((rc & ~(TPM2_RC_N_MASK|TPM2_RC_P)) == TPM2_RC_HANDLE ||
rc == TPM2_RC_NV_UNINITIALIZED) /* NV index is missing, unwritten, or otherwise unusable for this policy (or: wrong authHandle/policySession). */
- return log_debug_errno(SYNTHETIC_ERRNO(EREMOTE),
- "NV index referenced by token is missing, unwritten, or unusable.");
+ return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
+ "NV index referenced by token is missing, unwritten, or unusable, it could be for another system.");
if (rc != TSS2_RC_SUCCESS)
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"Failed to add AuthorizeNV policy to TPM: %s",
/* Returns the following errors:
*
- * -EREMOTE → blob is from a different TPM, or NV index referenced by policy is unusable
+ * -EREMOTE → blob is from a different TPM
+ * -EADDRNOTAVAIL → NV index referenced by policy is missing, unwritten, or unusable
* -ENOSTR → signature JSON has no matching entry for the current PCR policy
* -EDEADLK → couldn't create primary key because authorization failure
* -ENOLCK → TPM is in dictionary lockout mode
#define ERRNO_IS_NEG_TPM2_UNSEAL_BAD_PCR(r) IN_SET(r, -EREMCHG, -ENOANO, -EUCLEAN, -EPERM)
/* Errors that mean the tried TPM2 token does not match the boot state, be it due to wrong PCR state, a
- * different PCR signing key/policy, or even a different TPM. The caller should keep trying other tokens. */
-#define ERRNO_IS_NEG_TPM2_TOKEN_MISMATCH(r) IN_SET(r, -EREMCHG, -ENOANO, -EPERM, -ENOSTR, -EREMOTE)
+ * different PCR signing key/policy, a different TPM, or an unusable NV index. The caller should keep trying
+ * other tokens. */
+#define ERRNO_IS_NEG_TPM2_TOKEN_MISMATCH(r) IN_SET(r, -EREMCHG, -ENOANO, -EPERM, -ENOSTR, -EREMOTE, -EADDRNOTAVAIL)
#if HAVE_TPM2
#ifndef SYSTEMD_CFLAGS_MARKER_TPM2
static SD_VARLINK_DEFINE_ERROR(KeyBelongsToOtherTPM);
static SD_VARLINK_DEFINE_ERROR(TPMInDictionaryLockout);
static SD_VARLINK_DEFINE_ERROR(UnexpectedPCRState);
+static SD_VARLINK_DEFINE_ERROR(NVIndexUnusable);
SD_VARLINK_DEFINE_INTERFACE(
io_systemd_Credentials,
SD_VARLINK_SYMBOL_COMMENT("The TPM is in dictionary lockout mode, cannot operate."),
&vl_error_TPMInDictionaryLockout,
SD_VARLINK_SYMBOL_COMMENT("Unexpected TPM PCR state of the system."),
- &vl_error_UnexpectedPCRState);
+ &vl_error_UnexpectedPCRState,
+ SD_VARLINK_SYMBOL_COMMENT("The NV index referenced by the key is missing, unwritten, or unusable, it could be for another system."),
+ &vl_error_NVIndexUnusable);