From patchwork Mon Mar 4 10:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 777816 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E4FB36B02 for ; Mon, 4 Mar 2024 10:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549062; cv=none; b=teuctDtelip01g70At7JZ0I6hN0WKk4CSgQcaJGLM4hjbU5GSRVBYjqAK3HG73q5oiXFuZOO4Z6CglKr3lIIpO1vnQOv97S/FmecmPfo4502EliSG3Yxi8k5CAu6DJNFTiBN0H4H146NMeWrESJCbUTv9V7F5I8PSfQ1lC4GKp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549062; c=relaxed/simple; bh=rUoVnOWH3KhRLUKAtu1Bvtoi9WLHLAW4FJRtXzFfz+s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZfQBc/sYsSU9sKfFd0k9kOvJRglhKI4WDslIjzJ1gt0tgneJdi+Q71//vmxBRXEIi2ScxQqRjlSuLh5z/gYPwm/4pPVeZXAw8nqWGbUrNwphBrcwfjddHwhO82NKqsrUkFfPQbzr3qJpUossVViAIKPyNdmTwhAQ1czjkeCmjVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1LR66oSP; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1LR66oSP" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60966f363c1so62289017b3.3 for ; Mon, 04 Mar 2024 02:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709549059; x=1710153859; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fye5J1IiDjNC2HBYOqjmRhNgF2oCbMDVZrQYExDvAzk=; b=1LR66oSPAalyePaBYwRvgc7qxcfovATYaFD2HZnJnqAT/WW1oZoTneZJBlmOSTtUEe Zo9dxxELL/bwInUvDs/SQ+1JweY0yoqxmhF8RQ0nQ1mtPC5U9CKCj+mjtRLfAinpOZbs WpBqIfGP2y96nPt82X9+XGae+gtDGPxY2ABCIG0I+25zA8XAJ69QIsc7OVIXcrO7ETpE O7LkJVQ5vS+kWI6uRK6s27WI3+poeZRLkJXu5wYiO15EOU1kIMu4RFJqJfVajwQ0z7Oz QRn9pihM2SueLsesTfplVOEnCgG94BCfQ6l7VfpsWKrz8wnK1Pa15MxXHv+EZwbamo5U W2QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709549059; x=1710153859; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fye5J1IiDjNC2HBYOqjmRhNgF2oCbMDVZrQYExDvAzk=; b=nBnfVqImmPs/EAYaeg2sgHZMfEf3M4eQ4DfpOZ6hMM3BqruKRXFd0k2Tzggqri8X1R AHVQ5Dsg/Q4iFpV60AuzvZIb4DjFHQvvfd8Y/kfcbkIbLAa+wsGms9zJ+XTZhY85kEfB Jtrv/62OxNONMbSdoj30m+T3EfkstzLBObWsSLtb8vTB9CtS1VOiMh/T2vYzPt1CONbi +DUeGUdmeQkezcdVncvL86T1XPKOPkvfZT8zpxs/Lxi7FpDq5RNrJZOxD27MEYGWEVWe eI3jaRaxiGi7hC8nTdHtfWJSkwZ4no5ytf9nGXu6i9NFyXarsGh84WR0EtZTGukSyZoa CtZg== X-Gm-Message-State: AOJu0YzN52IStS5bfLbrfPRzF3tNzi9j25tv+mlMcjci8clXKTFi8Nqv /zBvT/rQFzePs8+Yj6w3ZN5W5sBtsNJJoVzGFqIRF5lNb4zGF5S3YI/ohuA8gH1A1FYpUdfJjh7 Nrhce3hE6PhzhIU9thZHK9hKrVLE2wCn/j02EpsegztbrjOydAOQnqncVb+cRpcsiSuAAupCHoN 0Qnts/ZSKWqe3jX95WXq3Ijn9jyw== X-Google-Smtp-Source: AGHT+IHXmJQ3fSGBPDoQ0htYLOQVoTJ++JV+eq2yjUmQQZRpdKsvl73/it0N89uJ+lh/IPExp8QgkL5k X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:4cc2:0:b0:608:ce01:9aa3 with SMTP id z185-20020a814cc2000000b00608ce019aa3mr2458238ywa.3.1709549059549; Mon, 04 Mar 2024 02:44:19 -0800 (PST) Date: Mon, 4 Mar 2024 11:44:11 +0100 In-Reply-To: <20240304104409.2326422-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304104409.2326422-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4246; i=ardb@kernel.org; h=from:subject; bh=f7pGP0YQg7y2zqt1UlrYoWJvFsxXx7WoCxt8tiOGVWw=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXp0t/JU+bLBu7aKFOy/66pxu0Lj0q8rBZ5FU/cvONvl xHbQZb5HaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAibqaMDI3rbQ2LJpuuqNYR um2t16ogk/Hkferxol93y+dtFIx738nwz1CDp9PsVsy1wn8e4s9YjO49NBK5OOvZvBvrt75kctw fygwA X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240304104409.2326422-7-ardb+git@google.com> Subject: [PATCH 1/4] efi/libstub: Fold efi_tcg2_tagged_event into efi_measured_event From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ilias Apalodimas From: Ard Biesheuvel In spite of the efi_ prefix, struct efi_tcg2_tagged_event is specific to the EFI stub, and so we can tweak it to our liking if needed, e.g., to accommodate the TDX variant of the TCG2 measurement protocol. In preparation for that, get rid of it entirely, and combine it with the efi_measured_event struct used by the measurement code. Signed-off-by: Ard Biesheuvel Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/firmware/efi/libstub/efi-stub-helper.c | 26 ++++++++------------ drivers/firmware/efi/libstub/efistub.h | 18 ++++++++------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index bfa30625f5d0..0dbc9d3f4abd 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -193,7 +193,7 @@ void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_si *load_options_size = load_option_unpacked.optional_data_size; } -enum efistub_event { +enum efistub_event_type { EFISTUB_EVT_INITRD, EFISTUB_EVT_LOAD_OPTIONS, EFISTUB_EVT_COUNT, @@ -221,44 +221,38 @@ static const struct { static efi_status_t efi_measure_tagged_event(unsigned long load_addr, unsigned long load_size, - enum efistub_event event) + enum efistub_event_type event) { + struct efistub_measured_event *evt; + int size = struct_size(evt, tagged_event_data, + events[event].event_data_len); efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; efi_tcg2_protocol_t *tcg2 = NULL; efi_status_t status; efi_bs_call(locate_protocol, &tcg2_guid, NULL, (void **)&tcg2); if (tcg2) { - struct efi_measured_event { - efi_tcg2_event_t event_data; - efi_tcg2_tagged_event_t tagged_event; - u8 tagged_event_data[]; - } *evt; - int size = sizeof(*evt) + events[event].event_data_len; - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, (void **)&evt); if (status != EFI_SUCCESS) goto fail; - evt->event_data = (struct efi_tcg2_event){ + evt->event_data.tcg2_data = (struct efi_tcg2_event){ .event_size = size, - .event_header.header_size = sizeof(evt->event_data.event_header), + .event_header.header_size = sizeof(evt->event_data.tcg2_data.event_header), .event_header.header_version = EFI_TCG2_EVENT_HEADER_VERSION, .event_header.pcr_index = events[event].pcr_index, .event_header.event_type = EV_EVENT_TAG, }; - evt->tagged_event = (struct efi_tcg2_tagged_event){ - .tagged_event_id = events[event].event_id, - .tagged_event_data_size = events[event].event_data_len, - }; + evt->tagged_event_id = events[event].event_id; + evt->tagged_event_data_size = events[event].event_data_len; memcpy(evt->tagged_event_data, events[event].event_data, events[event].event_data_len); status = efi_call_proto(tcg2, hash_log_extend_event, 0, - load_addr, load_size, &evt->event_data); + load_addr, load_size, &evt->event_data.tcg2_data); efi_bs_call(free_pool, evt); if (status != EFI_SUCCESS) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index c04b82ea40f2..b2c50dce48b8 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -843,14 +843,7 @@ struct efi_tcg2_event { /* u8[] event follows here */ } __packed; -struct efi_tcg2_tagged_event { - u32 tagged_event_id; - u32 tagged_event_data_size; - /* u8 tagged event data follows here */ -} __packed; - typedef struct efi_tcg2_event efi_tcg2_event_t; -typedef struct efi_tcg2_tagged_event efi_tcg2_tagged_event_t; typedef union efi_tcg2_protocol efi_tcg2_protocol_t; union efi_tcg2_protocol { @@ -882,6 +875,17 @@ union efi_tcg2_protocol { } mixed_mode; }; +union efistub_event { + efi_tcg2_event_t tcg2_data; +}; + +struct efistub_measured_event { + union efistub_event event_data; + u32 tagged_event_id; + u32 tagged_event_data_size; + u8 tagged_event_data[]; +} __packed; + struct riscv_efi_boot_protocol { u64 revision; From patchwork Mon Mar 4 10:44:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778956 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7E4436B02 for ; Mon, 4 Mar 2024 10:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549064; cv=none; b=oqPgyC/FERFYF9ZkpXaCPzlL/Fk0M5j++oUB3qF0YZxbZZ+oS7LFi3JXAsHdmSy6iFVVQD/Sq6ttbU+p1vVvyN6BegO9OW5nvLp+S0jm+MKs+yLcPAi76rvnNQhDqtLVw9bVSVHxKBWT8qRD8p6OPVf+8owtsORj/NyIWsX68r8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549064; c=relaxed/simple; bh=VVhdioOphzTA9PdgdT1aZk9Erf/HsszlM5PhQ4qdocQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K8veGIRI/gclfCEjJ9+Uvwj/F1Gnw7saW8bojsuo++ggBUW3NGntOod4Oz33tGtXo909s0Z7P33lT/odyjTp+eP5mcDRNJatpNAm6NlC8A/HRqEywmRiMIf8SFPzMVF+prgV6mJ2PKaGkVYxxU2m74OjeF+JWKaruLg4T3E2oR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KaYtpMil; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KaYtpMil" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6096493f3d3so54104847b3.2 for ; Mon, 04 Mar 2024 02:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709549062; x=1710153862; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZB9BYcBxd51GsXGosNFX5daYhYq4BEI2v6YX0r+bKnk=; b=KaYtpMilVtJg4gVwcrxVLZRcLwH6fSfQc0tXOk/gyp3SlG3LTaI8IsGrJkm15LtcYw MVEgzwSEe7CN48RW9zAwbYbALcIA51UDTEdWlb38oJMtSrhzfzbUzHKcsXuxOtgcARy2 sIf+qoPn3Fj7e4CVS+RREnKrUuwJatPJrTnnb3/Bfc6QcgZu+DRCJJboQs7HEgfqqW4v uNpjX+y9fGKY7FFdemVGZt0T7PCkuS+DYHZ2Pio3yTU4WF8NdSsawUwuZIhaD1OtgRww yHO9/R5tyj6xxLLWUhTUQfwUZ2JjzGbngMgJQMPeH4fHQxE4E9uyoMa4oITy0uJF220n 0uFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709549062; x=1710153862; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZB9BYcBxd51GsXGosNFX5daYhYq4BEI2v6YX0r+bKnk=; b=gwxhGi6+jcgLFcLv4FlH1L+hK4vkrWSyBvDdruzWQ+UtmogDJgT0OLH/3xu0+44C5F 08a12IWaKWZeXW8UD0wBsE7AoxVZ+jZvnl2bodJ8LqJY/YczofI5I9HA0ve58ztPUuVU TmtJXpoab+iq4JE+bZAx3GLBpcae7uWFl+MGceMFGpDBzf47b2nALaLzntc3RcP3ezF5 GET65Wp9pWj/RSzxcOaVOeuzo09CdhQJb4Y9G5enEm+A5v9kcdfDOJrOx8SdvUHUQLQQ LWRLPfZNFUjsCU04Hb8uk6RWViYnJCpsDagUqylIFEZ1oxT40g0ZRsEgTDD6t3NPvIV4 7y8Q== X-Gm-Message-State: AOJu0Yxa1de4oWK7dK3s9buIj3q4p2LiRivBH0G7llJ52a5QugyYhoZX WUSWYF4Xk72D55/fFAverFUBZphgHpYeBnm83JfoLw9unnM16DbhAR3cBxdmoHK2c56ehxHDTjH AnzR131LA7ItwrT59BlcCu1OTNCyR8nFKtvdAVPSJRS2DQmLDmPwQ1NBO0ZuYcKo2qkXv91YgAD IhWT6NJQmVXPr0KMBSGRlv2RWFNA== X-Google-Smtp-Source: AGHT+IEh0Y1celsmfHJbvT2yoGIO6YXPE30dXTAqGpSknauBkrJ/Kgh3XI3lye1cnFXnuSlD+284678V X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:9b97:0:b0:609:3c53:d489 with SMTP id s145-20020a819b97000000b006093c53d489mr1852594ywg.3.1709549061921; Mon, 04 Mar 2024 02:44:21 -0800 (PST) Date: Mon, 4 Mar 2024 11:44:12 +0100 In-Reply-To: <20240304104409.2326422-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304104409.2326422-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3924; i=ardb@kernel.org; h=from:subject; bh=AOuCJuHy1QOC0jeM/cJGLY/9Zjk5me9HEaE3HQHVYw4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXp0j9z/v6JD2GP/O7za8a/pUzbThhtc4pduPX8pounn KZP/djR2VHKwiDGwSArpsgiMPvvu52nJ0rVOs+ShZnDygQyhIGLUwAmsqaM4Z+alUZXyP5uQeYz Re322uEF+xmrBEuyvqqaXjzwyVjUyYHhv0/CObXJfDqsKoV7VogvXjnTevbKhhzr+6eZPoVmayq r8AEA X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240304104409.2326422-8-ardb+git@google.com> Subject: [PATCH 2/4] efi/libstub: Add Confidential Computing (CC) measurement typedefs From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ilias Apalodimas From: Kuppuswamy Sathyanarayanan If the virtual firmware implements TPM support, TCG2 protocol will be used for kernel measurements and event logging support. But in CC environment, not all platforms support or enable the TPM feature. UEFI specification [1] exposes protocol and interfaces used for kernel measurements in CC platforms without TPM support. More details about the EFI CC measurements and logging can be found in [1]. Link: https://uefi.org/specs/UEFI/2.10/38_Confidential_Computing.html#efi-cc-measurement-protocol [1] Signed-off-by: Kuppuswamy Sathyanarayanan [ardb: Drop code changes, keep typedefs and #define's only] Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 79 ++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 80 insertions(+) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index b2c50dce48b8..d621bfb719c4 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -875,6 +875,85 @@ union efi_tcg2_protocol { } mixed_mode; }; +typedef struct { + u8 major; + u8 minor; +} efi_cc_version_t; + +typedef struct { + u8 type; + u8 sub_type; +} efi_cc_type_t; + +/* EFI CC type/subtype defines */ +#define EFI_CC_TYPE_NONE 0 +#define EFI_CC_TYPE_AMD_SEV 1 +#define EFI_CC_TYPE_INTEL_TDX 2 + +typedef u32 efi_cc_mr_index_t; + +struct efi_cc_event { + u32 event_size; + struct { + u32 header_size; + u16 header_version; + u32 mr_index; + u32 event_type; + } __packed event_header; + u8 event_data[0]; +} __packed; + +typedef struct efi_cc_event efi_cc_event_t; + +typedef u32 efi_cc_event_log_bitmap_t; +typedef u32 efi_cc_event_log_format_t; +typedef u32 efi_cc_event_algorithm_bitmap_t; + +typedef struct { + u8 size; + efi_cc_version_t structure_version; + efi_cc_version_t protocol_version; + efi_cc_event_algorithm_bitmap_t hash_algorithm_bitmap; + efi_cc_event_log_bitmap_t supported_event_logs; + efi_cc_type_t cc_type; +} efi_cc_boot_service_cap_t; + +#define EFI_CC_EVENT_HEADER_VERSION 1 + +#define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004 + +typedef union efi_cc_protocol efi_cc_protocol_t; + +union efi_cc_protocol { + struct { + efi_status_t + (__efiapi *get_capability)(efi_cc_protocol_t *, + efi_cc_boot_service_cap_t *); + + efi_status_t + (__efiapi *get_event_log)(efi_cc_protocol_t *, + efi_cc_event_log_format_t, + efi_physical_addr_t *, + efi_physical_addr_t *, + efi_bool_t *); + + efi_status_t + (__efiapi *hash_log_extend_event)(efi_cc_protocol_t *, u64, + efi_physical_addr_t, u64, + const efi_cc_event_t *); + + efi_status_t + (__efiapi *map_pcr_to_mr_index)(efi_cc_protocol_t *, u32, + efi_cc_mr_index_t *); + }; + struct { + u32 get_capability; + u32 get_event_log; + u32 hash_log_extend_event; + u32 map_pcr_to_mr_index; + } mixed_mode; +}; + union efistub_event { efi_tcg2_event_t tcg2_data; }; diff --git a/include/linux/efi.h b/include/linux/efi.h index c74f47711f0b..2f57fec2e629 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -400,6 +400,7 @@ void efi_native_runtime_setup(void); #define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72) #define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed) #define EFI_CC_BLOB_GUID EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42) +#define EFI_CC_MEASUREMENT_PROTOCOL_GUID EFI_GUID(0x96751a3d, 0x72f4, 0x41a6, 0xa7, 0x94, 0xed, 0x5d, 0x0e, 0x67, 0xae, 0x6b) /* * This GUID is used to pass to the kernel proper the struct screen_info From patchwork Mon Mar 4 10:44:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 777815 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C31F364C8 for ; Mon, 4 Mar 2024 10:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549068; cv=none; b=gBvqh0othhlFWboHy6ZFO28133L9k1fSdFRSIYww+840Gdvq9DJ7Ss+TXbBDD0PZU1DOiyZZos0w/6QEAgQm5IIpDK5XDq29tgIElw9zq1zZEYwnW/vIz6lubf9kwkWIoJO72uagcLhT3wLhINRFUl4s4MmP/R86/haz7hWcz/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549068; c=relaxed/simple; bh=J9xhqifDnYz9MiaIJkP6q3vXgzeQIiGNnswih3Z1vgU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K9efpGLCodsOGqzNpkRGEyiLS+PRxiNfoJQE3YtHMJSIWNt282WKjSbzn+2fqwvKIOnkT1KINKhOJpG5/PPeW43f7IPXz0tCNA63nytnPXnl7Ot7TDmp0K6e78sZgF6XkclZZ5km3UTrbrrIMtFNpDjkJ3gumzGih1vC5qUwVpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Gu0+ZBrH; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Gu0+ZBrH" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-412b2321084so21431525e9.2 for ; Mon, 04 Mar 2024 02:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709549064; x=1710153864; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zOqtzBzdQ3hsbbykV18UWs1iRDCBoMzO5Q6nZSM61S4=; b=Gu0+ZBrH3YCPbV7JH8oYHoAUBF28PVGaKvBKxa8sIn7SPTIS3tOeuhaRW8scdpcnsT tYl5FPv+s7L3v/7nNjLj1tXWj/72dI4ZlES+XHM1sGR8SgfgujF7tN5/XBMPGvCzG1Gq Xs+7Zkg/4Ba52r/vmXHyynyrqHxjnJw+JkiIHSeG1dfZ7LDrjiBLpkl+VzvoJXJj15ke 0GHwaO0X2Eoc3rixZMth2b24YzAfd0+LtX7jeJuHXQ0RZqgQ6tNLJJ7K8hce9GcZIl3L av6d9tK90JY6NVQl7Cp/dVLjqGB7mb0HbMjhBaYIDWN/xUjHNrI5hk5BKLXqVozj6Pna a34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709549064; x=1710153864; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zOqtzBzdQ3hsbbykV18UWs1iRDCBoMzO5Q6nZSM61S4=; b=rhB4BFHzToH0eLgzvmzfpqHwEy5cBpoi4uGiVkJf2Bc8eI+LT4S1kkesU2sogREoQq g8BB6x0VD075IQFEEPqTS3ExJR2hYMleBvbU9LoPURAebFVzvF/9YwS76YYS5eEi08Rn xLpMelG1OjNjXTOX4a2DPwornmcJ95ZcoV7UXdKHbPMUv8XMC5GD48ldWF2iHtKt+DXW 8znIl3VqQzwXZC54vEcYLHxZZmuRn473PRcN8ccx1KFKFLYm4pOYEU0NeYq6oZkoY4CT 89K30N8fE2IjTBj7mOB114nR5Qmr+f0ExfOA9qiO9ETln8h/CTFDjbHJN/OS3AKZnZZ/ GQPQ== X-Gm-Message-State: AOJu0Yx9ESFAq/2LBtzIsE7p9VStWklpn4xOsPXtn6fw5Y5SQ3TsikE0 ked2XsNMI3kWsush7mB/EF6hDsS+Z7sPjnFkuMgLYDtKikcF45h1pMMOh3Q/Um9nD5C+boB3Rea fxjiDyyUc8jmqmrapXMER9j8JIx+UIB1XTtaR/2lTEl1SsgJWhslFG3xywxGBe7CjVIfwxpzzp9 hOgjZB1bLljYje7d6u0PrtKDu2vA== X-Google-Smtp-Source: AGHT+IFoh3MiEbo+i5gxYuvpUFWRazSxQ0iZaiC0JSivBmzLJvi4VcOqefxHjzhS0Noyw7RS9sQlQeto X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:1c0a:b0:412:e84f:4e08 with SMTP id j10-20020a05600c1c0a00b00412e84f4e08mr8462wms.8.1709549064092; Mon, 04 Mar 2024 02:44:24 -0800 (PST) Date: Mon, 4 Mar 2024 11:44:13 +0100 In-Reply-To: <20240304104409.2326422-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304104409.2326422-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4787; i=ardb@kernel.org; h=from:subject; bh=xichEWK5e4/jRYNdIPGHE18RWlrz3XDPAK0FIojpjW4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXp0r/vbbfqzTdapv79ktHamcfmVGbveOP72+vbkmuhv O/36hjt6yhlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATeaTHyPD+aeaHUqaORUuX aHOxHL5xfD97VMKJg9NXaOTrpFja15YxMnQ/Nr3+XNyai6NMUaej+p+P0WHWeW9N254aqZtknxP rYgAA X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240304104409.2326422-9-ardb+git@google.com> Subject: [PATCH 3/4] efi/libstub: Measure into CC protocol if TCG2 protocol is absent From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ilias Apalodimas From: Ard Biesheuvel To accommodate confidential compute VMs that expose the simplified CC measurement protocol instead of the full-blown TCG2 one, fall back to the former if the latter does not exist. The CC protocol was designed to be used in this manner, which is why the types and prototypes have been kept the same where possible. So reuse the existing code, and only deviate from the TCG2 code path where needed. Signed-off-by: Ard Biesheuvel Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/firmware/efi/libstub/efi-stub-helper.c | 67 +++++++++++++++----- drivers/firmware/efi/libstub/efistub.h | 3 + 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 0dbc9d3f4abd..21f4567324f6 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -223,44 +223,77 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr, unsigned long load_size, enum efistub_event_type event) { + union { + efi_status_t + (__efiapi *hash_log_extend_event)(void *, u64, efi_physical_addr_t, + u64, const union efistub_event *); + struct { u32 hash_log_extend_event; } mixed_mode; + } method; struct efistub_measured_event *evt; int size = struct_size(evt, tagged_event_data, events[event].event_data_len); efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; efi_tcg2_protocol_t *tcg2 = NULL; + union efistub_event ev; efi_status_t status; + void *protocol; efi_bs_call(locate_protocol, &tcg2_guid, NULL, (void **)&tcg2); if (tcg2) { - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&evt); - if (status != EFI_SUCCESS) - goto fail; - - evt->event_data.tcg2_data = (struct efi_tcg2_event){ + ev.tcg2_data = (struct efi_tcg2_event){ .event_size = size, - .event_header.header_size = sizeof(evt->event_data.tcg2_data.event_header), + .event_header.header_size = sizeof(ev.tcg2_data.event_header), .event_header.header_version = EFI_TCG2_EVENT_HEADER_VERSION, .event_header.pcr_index = events[event].pcr_index, .event_header.event_type = EV_EVENT_TAG, }; + protocol = tcg2; + method.hash_log_extend_event = + (void *)efi_table_attr(tcg2, hash_log_extend_event); + } else { + efi_guid_t cc_guid = EFI_CC_MEASUREMENT_PROTOCOL_GUID; + efi_cc_protocol_t *cc = NULL; - evt->tagged_event_id = events[event].event_id; - evt->tagged_event_data_size = events[event].event_data_len; - - memcpy(evt->tagged_event_data, events[event].event_data, - events[event].event_data_len); + efi_bs_call(locate_protocol, &cc_guid, NULL, (void **)&cc); + if (!cc) + return EFI_UNSUPPORTED; - status = efi_call_proto(tcg2, hash_log_extend_event, 0, - load_addr, load_size, &evt->event_data.tcg2_data); - efi_bs_call(free_pool, evt); + ev.cc_data = (struct efi_cc_event){ + .event_size = size, + .event_header.header_size = sizeof(ev.cc_data.event_header), + .event_header.header_version = EFI_CC_EVENT_HEADER_VERSION, + .event_header.event_type = EV_EVENT_TAG, + }; + status = efi_call_proto(cc, map_pcr_to_mr_index, + events[event].pcr_index, + &ev.cc_data.event_header.mr_index); if (status != EFI_SUCCESS) goto fail; - return EFI_SUCCESS; + + protocol = cc; + method.hash_log_extend_event = + (void *)efi_table_attr(cc, hash_log_extend_event); } - return EFI_UNSUPPORTED; + status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, (void **)&evt); + if (status != EFI_SUCCESS) + goto fail; + + evt->event_data = ev; + evt->tagged_event_id = events[event].event_id; + evt->tagged_event_data_size = events[event].event_data_len; + + memcpy(evt->tagged_event_data, events[event].event_data, + events[event].event_data_len); + + status = efi_fn_call(&method, hash_log_extend_event, protocol, 0, + load_addr, load_size, &evt->event_data); + efi_bs_call(free_pool, evt); + + if (status == EFI_SUCCESS) + return EFI_SUCCESS; + fail: efi_warn("Failed to measure data for event %d: 0x%lx\n", event, status); return status; diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index d621bfb719c4..4bf9a76796b7 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -954,8 +954,11 @@ union efi_cc_protocol { } mixed_mode; }; +static_assert(sizeof(efi_tcg2_event_t) == sizeof(efi_cc_event_t)); + union efistub_event { efi_tcg2_event_t tcg2_data; + efi_cc_event_t cc_data; }; struct efistub_measured_event { From patchwork Mon Mar 4 10:44:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778955 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE97364CF for ; Mon, 4 Mar 2024 10:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549069; cv=none; b=V/F1PuiQdQiXo2a2AfOwkOU7JXTz5aJtX6cQlo6D11QesX/Kp2+L8mMe8N/yfQ7tWKc1cPt1yILgEdlfS9U1Lw1i/i6ov7OfUcOmZAXQKlOCxsV5VTFuZCN9sUuYEyeNyxkgWW58LWUOL25JmX9C9NAkZ6jWx04Md1TgwY21yKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549069; c=relaxed/simple; bh=yKk7DgcgzXFZiUmFOwLqLLIsHe1XDQot/WyBU4BCRg0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jk8PBIqzJyhWv+GudND35LWzEu812du/3+ArGlFzD9T5Ha2z5MhoO16bNfXtwTKkdb0qenXUVw5d2l7D+NkFYmuNJL/aG5eEPz/757WAKs6+tvBqolOgjwzUzlUkk/CqcgUcDNDwbz0orxR7jaEnNrejvDjVlcopTP/3QbmAX9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=g2RCP/JY; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g2RCP/JY" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4128defb707so21485345e9.0 for ; Mon, 04 Mar 2024 02:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709549066; x=1710153866; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9jO2xNPIVNjLVhvHwuXBWw/Z0nGFsjqfUoNUcFbTuDs=; b=g2RCP/JYQBcxA2MWOSZUN3vcrR14jgq9NXeQMKKuK7fDJhecF6iiqcj0IdeFd1Sk8B nX+lY7nV1Gs9qOzqrORoLIjz4T3jY5NmRYdTTX/AyCiIIC45QziCBcjm4ng97zwvv8Nc 8Q8quRqUPOqIod0M7CqJwM/JEl+tVV3iaOOwtt+62UFTQdDUOz5Agwe0YfhgulX4cS3K Dm+uxmFst97QPlVo5yzK0Mn0yRwPfOOefeloylTTFQHC+b8bLsJtC7i598tRnEh+iJvF HXmVKpObV+skAm23dDZqMxtdh86Hk8u3pMjJUH9Ytu8v6yQXtSz+a43StTuO2UxLak/j gqOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709549066; x=1710153866; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9jO2xNPIVNjLVhvHwuXBWw/Z0nGFsjqfUoNUcFbTuDs=; b=SHZooN7ctA0OH562VqI03/yksWACAvi9e87ML6rftpynJmgEGo7NM2t+zrE9G0/WOO s7Hz8cSBzwGhEnOYu6bXNVjZUubYAE8GSwXD10YoJkvTDbeKKAwJok7DcH2qJeH7m1Gj jpGzcPALIuZa+6Lu7pPn96uuEyHsV/RJxuOS30GQAOmdxaMQYYZEz53wsgE3Nrli3dJh ca7EEYkPSxarIaOihV89iJOxS8VGXTMVeRZK8MCxJEHoJcEYDz8vmjugypeqD0d4t2HP ee/FYXS6BHXZu2QKAavipM1LAR5+SZmjLXw1WZzqiRXBEAvr7lOmH1FX/+tJHQtYAWw0 9eFg== X-Gm-Message-State: AOJu0YzCnhRHPAvV/B1+9y1CVygW/lKFiGBErLzljOqlny5XUDdaCuk2 FQymFH35XleQlBdgnE3kj5mxbEe0RYwQISXohwvagGGNYP4vL2BBALLalhzO96+orBQqxrKkZ5G qfu9deIDmS3cX6Bgx3I/qak4FEEMPxGmz87Zu7VHotlGC2nDFVI85kyRqTtbeQl7xMMDLgACmMR WKuoH9uKIYdHvTVVHBApDVaq8MPw== X-Google-Smtp-Source: AGHT+IEErJd24A/Y+Cv23GzYzUip41zWKdz6AJfeyJ5OivLH9WaLXb8sa+PD7mMpPczGu8bDWsD6QHMj X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:5024:b0:412:e6de:1b87 with SMTP id n36-20020a05600c502400b00412e6de1b87mr21791wmr.4.1709549066271; Mon, 04 Mar 2024 02:44:26 -0800 (PST) Date: Mon, 4 Mar 2024 11:44:14 +0100 In-Reply-To: <20240304104409.2326422-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240304104409.2326422-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7368; i=ardb@kernel.org; h=from:subject; bh=5UEzyMfXx1/Eo1U2xzRcfiH7tP4avZMenbC8OCUzQgg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXp0n9zn7DoC6iG5/49Zv5cbNJF9fsvuPYlS7413nXx0 M7ndWvPdZSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJfM5l+J/zXL3656fzj//r WS+rCTkfKZv+7cwp8dcvb80PZJzu8KySkWHmvzQf3S+Ki0vua6pcMni0vjl8+ieWmd75UdYVE+X /WTEDAA== X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240304104409.2326422-10-ardb+git@google.com> Subject: [PATCH 4/4] efi/libstub: Add get_event_log() support for CC platforms From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ilias Apalodimas From: Kuppuswamy Sathyanarayanan To allow event log info access after boot, EFI boot stub extracts the event log information and installs it in an EFI configuration table. Currently, EFI boot stub only supports installation of event log only for TPM 1.2 and TPM 2.0 protocols. Extend the same support for CC protocol. Since CC platform also uses TCG2 format, reuse TPM2 support code as much as possible. Link: https://uefi.org/specs/UEFI/2.10/38_Confidential_Computing.html#efi-cc-measurement-protocol [1] Signed-off-by: Kuppuswamy Sathyanarayanan [ardb: reorganize logic slightly to share more code] Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub.c | 2 +- drivers/firmware/efi/libstub/efistub.h | 4 +- drivers/firmware/efi/libstub/tpm.c | 74 +++++++++++++------- drivers/firmware/efi/libstub/x86-stub.c | 2 +- include/linux/efi.h | 3 + 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index f9c1e8a2bd1d..958a680e0660 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -167,7 +167,7 @@ efi_status_t efi_stub_common(efi_handle_t handle, si = setup_graphics(); - efi_retrieve_tpm2_eventlog(); + efi_retrieve_eventlog(); /* Ask the firmware to clear memory on unclean shutdown */ efi_enable_reset_attack_mitigation(); diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 4bf9a76796b7..e0a2766a70c0 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -922,6 +922,8 @@ typedef struct { #define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004 +#define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002 + typedef union efi_cc_protocol efi_cc_protocol_t; union efi_cc_protocol { @@ -1147,7 +1149,7 @@ static inline void efi_enable_reset_attack_mitigation(void) { } #endif -void efi_retrieve_tpm2_eventlog(void); +void efi_retrieve_eventlog(void); struct screen_info *alloc_screen_info(void); struct screen_info *__alloc_screen_info(void); diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c index 7acbac16eae0..c35f99f259c1 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -47,39 +47,18 @@ void efi_enable_reset_attack_mitigation(void) #endif -void efi_retrieve_tpm2_eventlog(void) +static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_location, + efi_physical_addr_t log_last_entry, + efi_bool_t truncated) { - efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID; efi_status_t status; - efi_physical_addr_t log_location = 0, log_last_entry = 0; struct linux_efi_tpm_eventlog *log_tbl = NULL; struct efi_tcg2_final_events_table *final_events_table = NULL; unsigned long first_entry_addr, last_entry_addr; size_t log_size, last_entry_size; - efi_bool_t truncated; - int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; - efi_tcg2_protocol_t *tcg2_protocol = NULL; int final_events_size = 0; - status = efi_bs_call(locate_protocol, &tcg2_guid, NULL, - (void **)&tcg2_protocol); - if (status != EFI_SUCCESS) - return; - - status = efi_call_proto(tcg2_protocol, get_event_log, version, - &log_location, &log_last_entry, &truncated); - - if (status != EFI_SUCCESS || !log_location) { - version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; - status = efi_call_proto(tcg2_protocol, get_event_log, version, - &log_location, &log_last_entry, - &truncated); - if (status != EFI_SUCCESS || !log_location) - return; - - } - first_entry_addr = (unsigned long) log_location; /* @@ -93,8 +72,11 @@ void efi_retrieve_tpm2_eventlog(void) * get_event_log only returns the address of the last entry. * We need to calculate its size to deduce the full size of * the logs. + * + * CC Event log also uses TCG2 format, handle it same as TPM2. */ - if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) { + if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 || + version == EFI_CC_EVENT_LOG_FORMAT_TCG_2) { /* * The TCG2 log format has variable length entries, * and the information to decode the hash algorithms @@ -129,6 +111,8 @@ void efi_retrieve_tpm2_eventlog(void) */ if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID); + else if (version == EFI_CC_EVENT_LOG_FORMAT_TCG_2) + final_events_table = get_efi_config_table(LINUX_EFI_CC_FINAL_LOG_GUID); if (final_events_table && final_events_table->nr_events) { struct tcg_pcr_event2_head *header; int offset; @@ -165,3 +149,43 @@ void efi_retrieve_tpm2_eventlog(void) err_free: efi_bs_call(free_pool, log_tbl); } + +void efi_retrieve_eventlog(void) +{ + efi_physical_addr_t log_location = 0, log_last_entry = 0; + efi_guid_t tpm2_guid = EFI_TCG2_PROTOCOL_GUID; + int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; + efi_tcg2_protocol_t *tpm2 = NULL; + efi_bool_t truncated; + efi_status_t status; + + status = efi_bs_call(locate_protocol, &tpm2_guid, NULL, (void **)&tpm2); + if (status == EFI_SUCCESS) { + status = efi_call_proto(tpm2, get_event_log, version, &log_location, + &log_last_entry, &truncated); + + if (status != EFI_SUCCESS || !log_location) { + version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; + status = efi_call_proto(tpm2, get_event_log, version, + &log_location, &log_last_entry, + &truncated); + } + } else { + efi_guid_t cc_guid = EFI_CC_MEASUREMENT_PROTOCOL_GUID; + efi_cc_protocol_t *cc = NULL; + + status = efi_bs_call(locate_protocol, &cc_guid, NULL, (void **)&cc); + if (status != EFI_SUCCESS) + return; + + version = EFI_CC_EVENT_LOG_FORMAT_TCG_2; + status = efi_call_proto(cc, get_event_log, version, &log_location, + &log_last_entry, &truncated); + } + + if (status != EFI_SUCCESS || !log_location) + return; + + efi_retrieve_tcg2_eventlog(version, log_location, log_last_entry, + truncated); +} diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 99429bc4b0c7..d09aa13c7ff0 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -923,7 +923,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle, efi_random_get_seed(); - efi_retrieve_tpm2_eventlog(); + efi_retrieve_eventlog(); setup_graphics(boot_params); diff --git a/include/linux/efi.h b/include/linux/efi.h index 2f57fec2e629..a69c08b90e74 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -440,6 +440,9 @@ void efi_native_runtime_setup(void); /* OVMF protocol GUIDs */ #define OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49) +/* CC GUIDs */ +#define LINUX_EFI_CC_FINAL_LOG_GUID EFI_GUID(0xdd4a4648, 0x2de7, 0x4665, 0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46) + typedef struct { efi_guid_t guid; u64 table;