From cdbcb1fe6e7ab5ec001b81d99f6e2ae2f94e9604 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Jan 2024 17:33:59 +0100 Subject: [PATCH 1/2] creds-util: simplify offset calculation a bit Don't recalculate the overall offset entirely each time we process another header. Instead, if we already validated an earlier offset, just reuse the result, it's readily available in 'p'. No change in behaviour, just a bit of code simplification. --- src/shared/creds-util.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 434907c998..3514902c68 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -1170,7 +1170,7 @@ int decrypt_credential_and_warn( /* Ensure we have space for the full TPM2 header now (still don't know the name, and its size * though, hence still just a lower limit test only) */ if (input->iov_len < - ALIGN8(offsetof(struct encrypted_credential_header, iv) + le32toh(h->iv_size)) + + p + ALIGN8(offsetof(struct tpm2_credential_header, policy_hash_and_blob) + le32toh(t->blob_size) + le32toh(t->policy_hash_size)) + ALIGN8(with_tpm2_pk ? offsetof(struct tpm2_public_key_credential_header, data) : 0) + ALIGN8(offsetof(struct metadata_credential_header, name)) + @@ -1190,8 +1190,7 @@ int decrypt_credential_and_warn( return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Unexpected public key size."); if (input->iov_len < - ALIGN8(offsetof(struct encrypted_credential_header, iv) + le32toh(h->iv_size)) + - ALIGN8(offsetof(struct tpm2_credential_header, policy_hash_and_blob) + le32toh(t->blob_size) + le32toh(t->policy_hash_size)) + + p + ALIGN8(offsetof(struct tpm2_public_key_credential_header, data) + le32toh(z->size)) + ALIGN8(offsetof(struct metadata_credential_header, name)) + le32toh(h->tag_size)) From a9e4057f1f49ab3d10a32d898b904c4ccfeeb41e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Jan 2024 15:21:35 +0100 Subject: [PATCH 2/2] creds-util: drop unnecessary include Follow-up for: e653a194e490fae7d166f40762c334006d592051 --- src/shared/creds-util.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 3514902c68..0325f6e129 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -28,7 +28,6 @@ #include "sparse-endian.h" #include "stat-util.h" #include "tpm2-util.h" -#include "virt.h" #define PUBLIC_KEY_MAX (UINT32_C(1024) * UINT32_C(1024))