From patchwork Thu Mar 7 16:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778654 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 DBCA512BF3B for ; Thu, 7 Mar 2024 16:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828550; cv=none; b=W6QVZkV+QOrTDGpQVUtAV3XdBS9HH+i5VhCiLP4oYvl99ELVgykAzl2O8MxmCfUPuqke2jemD/OPUHRMN7DCOaEY0HqZPinyZo2OS0eicwmI90jbOfWIZfGTC3JY3mJaYuRaB1mfsv5XytirwQwwzkmlWVAY8qqDURUvlC5zwfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828550; c=relaxed/simple; bh=vx6gy63bvKwEcZKAJOMT4vamJcfs5j218q6IeLLsKmc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qcQYeQH6ytYYufR4zNJs8RvgKqRSNXIiUWdvHzFfwIqUWilZQT9qQ3VCwfDdWs3xF+/keIChklQQNIGwCrMxHFQ+sdYe4jii45ar8i3l0WLFMf2ogfeaiS5RjvLbgXwt1cqtKjR7D6WcLsjqxOQ+lQPX+22PkHoCBnjI60rnPnE= 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=R/pAEaxA; arc=none smtp.client-ip=209.85.219.201 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="R/pAEaxA" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b2682870so1838321276.0 for ; Thu, 07 Mar 2024 08:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709828548; x=1710433348; 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=NIPwglx+vpLGh3Clnv1DsOBYHxPQ5NB3VMfnxKm7TDg=; b=R/pAEaxAEdD1sc7O8/3YEeQVZFfoSt1oi4/9NkU1KOedxtvqrIpiIfkxjYdyYCUbhq 5jmTHNeXxzpvAP29h3ZwSfOpW7+cpgQRb5dyaQTYdb/0d6RNCKM+6EyS+dEUWIEt4XKK Oanwh7Unbxu75gBnxi1EaUEkbf93v1OYakxLcMS7CPmmunqA6sk64XZK64OvRpzwggak b+x+O1Cl1puxORw/Wqs5X93x/gtddqdb4r62cLGyrbTdHKzBARPqNb7yFKzUM8lZBivq ycWlWnj97V+/SReSlIoPNGbOp5j4/ADtaeeU1verpRgzw6V5y/WwKceV/9iwltPVRcO6 rxNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709828548; x=1710433348; 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=NIPwglx+vpLGh3Clnv1DsOBYHxPQ5NB3VMfnxKm7TDg=; b=M1pRYvCDFM1UQRcD1r8Kr2gELX27dUoBVJkkSecrH7N5pLCB2v8+srjP/Gif6KBM+L lMFKp+mhho4EuHqO6QAv937+gUaGrP5z2O+1EZ5uunSg3M3/O6jjL8+BP7IoOLpj734z C7wyMCdB+orogtMRsp2ct8FYz4r92gL8q1cvy50ZLdsE/pQFLTEHsdZ8lNK4dwcM+6pb cJ4qZ51mcYQLkVHaEQevYscOKjNDoodX2UF7ZlBCjRR3m2h0mWDawquP1qLcscW5YCWC 01XcNVojltS9zLZHWAAa32CxQ1qFfFeB7ENTUaWI1TQPCr/6SXqDBQ4/6b+jxPPlM5ZJ r2bw== X-Gm-Message-State: AOJu0Yzlf/eMOi/cE7dp4c6d+YkLvQYbxmV096ZV5D2CA3znrMmUqp1y HEz1+ZIZFWy2YD+lb/RvvSwynkK3pao6eqMy+xtee18F3xmr0rl4GOFiljAWQJLseVomQJXoYPw hsy9R5W60fZ+g8EvcYtNnCQXw3DE2lhgQHuZet4af5uA8XKJ2hh5Xxh4/fmn5SMqSDatF3d7dLA 5SUmJKOKr3ICrU6PJ9B5ZnNXOhXw== X-Google-Smtp-Source: AGHT+IGBkbaDLEA8X6Cjwf7LKdHd/BuwHE4A3vMIBnYcw5h1dlxgzanmSobPx3kCNvYTCaIXxnQ+CVqd X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1823:b0:dc6:e8a7:fdba with SMTP id cf35-20020a056902182300b00dc6e8a7fdbamr4665957ybb.4.1709828547777; Thu, 07 Mar 2024 08:22:27 -0800 (PST) Date: Thu, 7 Mar 2024 17:22:16 +0100 In-Reply-To: <20240307162214.272314-7-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: <20240307162214.272314-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4361; i=ardb@kernel.org; h=from:subject; bh=HowsP3Xpey7zNPaFKSGnjwc0I59oEtS2s4G34jdbb+U=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXly53fdURN/1c0yJv2Op7Ysdjsac0kCaZJrLd3eS2Pn J/m2cXRUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbSL8Hwh+fVzQnfHJ/J1rXY y/C9y1X5u+APW7HkpOecr0tTOnqnXmf4w/lloVj9nejrNQyF21/MrT715N9Lrt9Sb55/4e77V8U 1kwEA X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307162214.272314-8-ardb+git@google.com> Subject: [PATCH v2 1/5] 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. Reviewed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Ard Biesheuvel Reviewed-by: Ilias Apalodimas --- drivers/firmware/efi/libstub/efi-stub-helper.c | 38 +++++++++++--------- drivers/firmware/efi/libstub/efistub.h | 7 ---- 2 files changed, 22 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..186ced8371ac 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -193,7 +194,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, @@ -219,46 +220,51 @@ static const struct { }, }; +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; + 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..dae635cc3d4f 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 { From patchwork Thu Mar 7 16:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778941 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 186651EB40 for ; Thu, 7 Mar 2024 16:22:31 +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=1709828554; cv=none; b=mCxwYkmCswkdsRO/7p7RU02FVz7yWP/thrQ8lvLh4PZ3Inaa/O9QjJjmD/izq/F7ENvsN0GGqiB58Kwx+Xg3Ibgj/8ycihIwXpLaq4IdouAH941n45RFHoF/dXTdfvm4F7pvcgnKKAOYT+5PDnetgOVuiYvQ+T0KMvbm5EFzh4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828554; c=relaxed/simple; bh=nRs7smSFu9gNMmmv6GR83kKT/YuFKakEuv80+1ggkYQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iouat1XEpf6tzdSAhH/4ic0LPMnziB25MqJlUQW+joiF8hRHOs/O5mJba6M3YbXvZe28JGCqCpx+bLX10y2MKarPEyyS7JOLLM11StrY0IE3UkWkh72wMsdHq5oTlOq1KCoIUizZTLCkOEXZ2nrKkV93tQv8vJsXSO3lBWlFq8U= 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=jEINTs66; 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="jEINTs66" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-412dcaf0bd6so5254615e9.0 for ; Thu, 07 Mar 2024 08:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709828550; x=1710433350; 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=YcGpQbIMa731PfgfQ8GqyBdWvH8ozo+871W27IhQ7R8=; b=jEINTs662EYmqZPCN08KQPf6ugrYpD6yYIebYg5ixhuuA5kE5R8lXlpTzmz7ER/CoX o4VIaKJzb7vnPc5KPaHzbG0yh0rCiVt34WKLz/1xa/s472rsXbFiUTW1reyuwtuXLmQC 168GIMCVmMZ5gPoUKHNAlc0hdBjwIRFzKRrXQmrPNoQFokcfodhOvfz6qSS59SbIUJH8 PPaGeYjpTESWP3pChTpIyx7QyK16IY+g5tflRx9r9xOJSyE8SwAhpy1sB47MIC6YbpVn 3b0EYWx7oX7KiG3ZFxtl8pm/IgzGpT7TAHC9gHe8MogG/sLeJABRrFPSCz1/i6DtiGN5 YzYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709828550; x=1710433350; 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=YcGpQbIMa731PfgfQ8GqyBdWvH8ozo+871W27IhQ7R8=; b=cjXJlUNvGiTns1FyG9yZMGQVVl0FvM06kHSq/GR2H5LVGQlT0Ko+OS2CbbQCLCaNmH ake10kPZf5odXQvtDFkpZDfrQ0p/i57SonwxJNLQoD0p1/Fa6r2ELb2NgG7Std+56LGG fejf3KR3JeXFBGVagtSsMQpaxB4JRJJXZj9Df/QkNixOcyndgkCgHgiTQAhFaJT5ttFN 4UpUjr3BPVDrceF8HJe8uTxk7x9zFaIq5aNYU0PV+p3WFGLMUwfAockN59pafQ6Oksu1 d2fnHOi18CraMeVUdD9PLoNmE4U3mm3BdmMO4fTXuE1xOpW71KED5rOCXJHfoL9AMXLu d6Hw== X-Gm-Message-State: AOJu0YxkVez9ZvemU3eVdfZtRGFYIzuJ/kR65k0wkAjWhrfmWH06mS44 9GPeo4N+bmO5+tdt8M2aEmTl0i0cQ9iSEIbWowjGK8GXn85WPc6RsnLEnDp/NFEudkilKEz0NiG oZhfh05RHN3TTdIUSK8RvHXtDFQkdyXGaQosnWPPnYgAaoyJlqsZaTr+DU0HUg+Roz4oVKqlScL TAtpR1dLI4vlZ94dKcFSjim9JSPg== X-Google-Smtp-Source: AGHT+IEYsQtP5jByJdNtIQoLE4rWxh3m2YZgLVdBL0tKXgx7k3IlXVDr7Sfd232aLxZI1ClBXsvJIXLl X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:9d8f:0:b0:33e:7380:df3b with SMTP id p15-20020adf9d8f000000b0033e7380df3bmr807wre.10.1709828549913; Thu, 07 Mar 2024 08:22:29 -0800 (PST) Date: Thu, 7 Mar 2024 17:22:17 +0100 In-Reply-To: <20240307162214.272314-7-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: <20240307162214.272314-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4203; i=ardb@kernel.org; h=from:subject; bh=AiCD+AShD+1g23OfVNA41j0MFtZc6w00dmlkIIJ6T0E=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXly11cC6cEeBTO2v7g0l0ZkxOv9W6I2j1earIntufpt Ecrn7lJd5SyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJfM5j+Kf7JuDjhLd+v99H +T/NcnqgtCeHueN85Nkzwd57Dh4qe1fH8D/88m37yqM7K3hnrW6In7aw49XRi/lbX6qaSXsnMWn H7GYGAA== X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307162214.272314-9-ardb+git@google.com> Subject: [PATCH v2 2/5] efi/tpm: Use symbolic GUID name from spec for final events table From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ilias Apalodimas From: Ard Biesheuvel The LINUX_EFI_ GUID identifiers are only intended to be used to refer to GUIDs that are part of the Linux implementation, and are not considered external ABI. (Famous last words). GUIDs that already have a symbolic name in the spec should use that name, to avoid confusion between firmware components. So use the official name EFI_TCG2_FINAL_EVENTS_TABLE_GUID for the TCG2 'final events' configuration table. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 2 +- drivers/firmware/efi/libstub/tpm.c | 2 +- include/linux/efi.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 4fcda50acfa4..f6cfd29308d9 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -597,7 +597,7 @@ static const efi_config_table_type_t common_tables[] __initconst = { {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, &efi_mem_attr_table, "MEMATTR" }, {LINUX_EFI_RANDOM_SEED_TABLE_GUID, &efi_rng_seed, "RNG" }, {LINUX_EFI_TPM_EVENT_LOG_GUID, &efi.tpm_log, "TPMEventLog" }, - {LINUX_EFI_TPM_FINAL_LOG_GUID, &efi.tpm_final_log, "TPMFinalLog" }, + {EFI_TCG2_FINAL_EVENTS_TABLE_GUID, &efi.tpm_final_log, "TPMFinalLog" }, {LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" }, {LINUX_EFI_INITRD_MEDIA_GUID, &initrd, "INITRD" }, {EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" }, diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c index 7acbac16eae0..a880f7374c27 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -128,7 +128,7 @@ void efi_retrieve_tpm2_eventlog(void) * final events structure, and if so how much space they take up */ if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) - final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID); + final_events_table = get_efi_config_table(EFI_TCG2_FINAL_EVENTS_TABLE_GUID); if (final_events_table && final_events_table->nr_events) { struct tcg_pcr_event2_head *header; int offset; diff --git a/include/linux/efi.h b/include/linux/efi.h index c74f47711f0b..464fe16411b8 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -386,6 +386,7 @@ void efi_native_runtime_setup(void); #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0) #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) +#define EFI_TCG2_FINAL_EVENTS_TABLE_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25) #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) #define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d) #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9) @@ -411,7 +412,6 @@ void efi_native_runtime_setup(void); #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f) #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b) #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa) -#define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25) #define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2) #define LINUX_EFI_INITRD_MEDIA_GUID EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, 0x89, 0x88, 0xa3, 0x89) From patchwork Thu Mar 7 16:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778653 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 868531E878 for ; Thu, 7 Mar 2024 16:22:33 +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=1709828555; cv=none; b=WMVgNpGPFbI3MlZuAo9tGXErSe0x2/86UQCROai5dGVgwO/di+T/oR169GPVax2cHBVizv1XeMYZffcVQ1Dg9LXm9qVDJM+QiSNYUPSOKi//Syo6s0Q5LLfJyK3mhqrysBsYG8aWh4zluNSyRvq0+jOZFuv4WlN1txOlWU7bzf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828555; c=relaxed/simple; bh=1v5qDaflI1flKXQvcNnTLi+DdUuCqFGLba7GP8djNmM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XxAf1BQsvM8k3tK/PpiEX1jhCh1J7RdgrRozgzM3602UWAdTCxYhuzwH0/TWq4kCcACQDDvH6Nl7eezhhYyEJYrD4E0UmPq2C3mjOvHw0lOtFTDBODsxTKZ90sns6arZgYIYZP53g6EWxGF2lDv1gq2Mlr4FZ9Xjhi3bCF5s15c= 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=LBU2Mc27; 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="LBU2Mc27" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6047fed0132so16936877b3.1 for ; Thu, 07 Mar 2024 08:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709828552; x=1710433352; 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=brWE58VkfvSmOu5ITgNbNdxBlUJvRdpQgw8XNQfzcrQ=; b=LBU2Mc27f2VZjREYtUd+Hp7xV8pjv9Q09a88L4uswFddhAV0LSgN0lW7C/HYQciFSd 4hamb3STI/qTh6c0PsUk0LAOkJ0+HqRNanqHvCl+oon1l6KKJhhkZVCO7jvHEjxPVgjN t9/BbBzinpzSPzKYqxs6TK3y1ilIS+tMAjITF84Kdfv7C6QVwYRv7pOV7AuAY1nA3H2q 6QZQuSVRsNadM9ymNlPtE1A3uFzUHIO/QIK4ulC1W6XpTFTCyd4CmLQP+nP01IEOS9sG wTY36EMBGCqBuNfiX8fvEi7ngedA7Wzs+SzHHYfHKocnDT4ZAG8Ub2uhemK4EFdxgl1U PeBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709828552; x=1710433352; 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=brWE58VkfvSmOu5ITgNbNdxBlUJvRdpQgw8XNQfzcrQ=; b=NAyNCOABMcNj4rXItgg2F8GolFJ/MuVEcBEUxIxU6QLZd+eqNovX3r9qkMZFkzd1P5 e8bBX+RNkstgG8i6bUBI8yowIzd1VS3vdk8Mt828oK640FsQGQJy6KBoo7vKbEv1ol0K WDMdVPHH1AuWtZm1v7WI4fwh2OLcaZUePDAutMYNLN7RAMfA+eRja66WIupQYyVmMJzW aLpqkaMr2op6gFZ4LGhGFu7q4Xu/4EpbigmtGLVKEXubIitagsSrFZzQVs/LN7WZC3/q OVbxrDsAe8txpyHjsyvYswHAge14b82fpn/PJcvFEuzKXkl0TamB+umO/yE5e05SID2G LyvA== X-Gm-Message-State: AOJu0YxvqkS3oMAg22p1+fJ9a1qMvTAF1aGykDz5r94IxMDb8EbSFWHV oIGm62nIT3LS9TLFy1ajA9agcaejLdEcTQGJbTSSIcZQkqFDF076XxaW9Fy3Yo1joCODfgUdjZJ Zmc/bnCWzGrHwuS6Vlf5yHJjLx1jagDJ9ZXCEah6nZsfa2p9xkrYOk3obOvwJ7IO1KOP2feh+H5 BT50QF5QJW/sI70wV27sfy1babog== X-Google-Smtp-Source: AGHT+IFWASN387DLEosD5gjIT/FyNLTFzQJi0kuM9OoomWialMcEfVeyb9OU0suFf/qXQMvzNP0/vgSz X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:729:b0:dc7:66ec:9038 with SMTP id l9-20020a056902072900b00dc766ec9038mr826012ybt.1.1709828552450; Thu, 07 Mar 2024 08:22:32 -0800 (PST) Date: Thu, 7 Mar 2024 17:22:18 +0100 In-Reply-To: <20240307162214.272314-7-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: <20240307162214.272314-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3931; i=ardb@kernel.org; h=from:subject; bh=8Do1tMdDVHm6ro61VFSQzGVzzJldNBeK41qZOtuu6kQ=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXly92n5t5ZdkZu6sz16d+mpDrLFid8ydz+ROiPwO67F 7Q+FCS+7yhlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATMZnI8D9t5U7HjqpDkZ8Z GFnvyyZ86Jp1d6rD44CfhSqCanF3zqkzMvz2qebb73DyvbD0wZM7U19O+qOmue1RVt6RLzwvt9t Uf2QDAA== X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307162214.272314-10-ardb+git@google.com> Subject: [PATCH v2 3/5] 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 dae635cc3d4f..72181c04420c 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 follows here */ +} __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; +}; + struct riscv_efi_boot_protocol { u64 revision; diff --git a/include/linux/efi.h b/include/linux/efi.h index 464fe16411b8..2493d3d4429b 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -401,6 +401,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 Thu Mar 7 16:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778940 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 F0ACC1E878 for ; Thu, 7 Mar 2024 16:22:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828557; cv=none; b=cc2DNtg4ZnJ6XjfkzG2W0j8quWP6J736B5p673VkzMy5SkLd3bvVhKAr3P8zUc/9t15n90lXGseOqmPa6keRfQrg0QtT+l//x/U7bSclYQBkZhWT8praNN4J93H+eqe3urM1c2QY4mafB58vGWG3crHbKR/L0u4O/HV6SojFupk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828557; c=relaxed/simple; bh=SoIaXrJGI2TPdCnYEbQBmioks4lWKOS+7GEz43YxA7c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LuLYcK0AxN6RelQjYD3uqaF7MY0ld2z0/HSksdaalJC939yDuJlNSD7vVhEpmmqTqJ8Te1EUxOu9IEt8yuokeM8YS3BoKPe7u2l5d+wwmOVKUn0ETb+SoYuF2LCFZKbCw2NP4/xBjSuxYQPWuLNOYVvIJcQhr5GWKpsIPK8guWA= 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=m7d2RKLW; arc=none smtp.client-ip=209.85.219.201 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="m7d2RKLW" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcf22e5b70bso1783894276.1 for ; Thu, 07 Mar 2024 08:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709828555; x=1710433355; 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=uuv7R6J6cPZcnSD1YmsTMTUsB4usMCYn74Y3UHhuK9A=; b=m7d2RKLWAat327eo+XT6UX+af1XU5hxLkfInllzSSQu6+qfGtFPxzZwI8X0LkHkI+S xoaOItQfrlOWqzhHEiq5HILOhMF8tQhodOEGncGeP41bChFwL33O2ZX6wzl6sYapVnRV x2JKtUVyVWUFk1J/8t5H1HrEJBSe8Y2G9XwkDAT1VvkO3B3cw+6lm2C+Tb0+wd5xOJc0 XGjOIjTYRm/J+tSvCE8Ol7meAtI91IahLw5ehy2IQ9zqsqt/AnbI89b+7/8AJUewhvb3 OQ/hXo1IK8eOU6EqT3JsiRaHz/hnOMkUdCare+/0RdJF/uylkcdrVjL7SgRnwXlf88nL 9J2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709828555; x=1710433355; 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=uuv7R6J6cPZcnSD1YmsTMTUsB4usMCYn74Y3UHhuK9A=; b=Gx7EqdUOR/P/eKXduJbaogrBDFVFhzIvCJ9ksqCiInse013BT9Qj0igm/1QuMR1woF fby1ciWP0vOjszB1lQQ2AMEUZgUeqZFBllj1r5Mh041siKAAuM+rrRg1yjJARtzSaGk5 eTC973WbhEh636IETXjeoImeSdYg71JH+HYtVvEf/V4Fv2lMuCOYzQYRJxgv/dnru0iX 1h6CoCVOXNuas17j/hGS9VPAxudDqrs/jmby83c5SzjhynEHnMUlUOOE3klvrVAfOZjH 88SkrBVFP4bceAP2vs7yvzlfTCm8Jk4806Zj5HPqaqy7AScoPbVLPD6CrT8D4g/H/+oi leQg== X-Gm-Message-State: AOJu0Yx8WZ4vehqVtGriiwur3XnCXCmdaZgJ5vnXYatH9/1iO+ZrlHxU SVEcY23L6ycyxvtfeqZ8vPLJ6j4OPlTgBozjmZZ4Ulv2srps5r2B+EhNVbcRLZbFPOuUjNWfaKi jaetel+tGzZyaX0vnSVRB/eRzAj+AfmHbsyhIIDDTjXjNmmmi6MZ02NmxKF9PUDnerk7z5woC+0 llEitQ7veCQEpBiQHG/c7V4PTDXg== X-Google-Smtp-Source: AGHT+IElobcdMYwnKdcXBTJUv05H8jBKow+I07kzaRwdKB0ENl7Vu0DnWj8fShy3foUsQrI2H7HeXV2Z X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:100d:b0:dcc:8be2:7cb0 with SMTP id w13-20020a056902100d00b00dcc8be27cb0mr673231ybt.0.1709828554981; Thu, 07 Mar 2024 08:22:34 -0800 (PST) Date: Thu, 7 Mar 2024 17:22:19 +0100 In-Reply-To: <20240307162214.272314-7-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: <20240307162214.272314-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4576; i=ardb@kernel.org; h=from:subject; bh=TNQf4Yorjyby48cRqVB4XsLdQEf+HzREUwZZ+kg0fYA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXlyz0Xso6cW53/R4uP5YuZ/4Kzcxg+2L38mC42oefs4 /87boZs7ihlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATCX7AyDA7u/l21cTsf4vj XSxeaafce3PF70uzMsfzew1v9pRttbnH8L923r+pe7K6DcszpY+qByjJun69m6HL1u+wik109au pf1kA X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307162214.272314-11-ardb+git@google.com> Subject: [PATCH v2 4/5] 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. Reviewed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 70 +++++++++++++++----- 1 file 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 186ced8371ac..993c58e2221b 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -220,8 +220,11 @@ static const struct { }, }; +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 { @@ -235,44 +238,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; From patchwork Thu Mar 7 16:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 778652 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.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 5AE5D12FB07 for ; Thu, 7 Mar 2024 16:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828561; cv=none; b=e/Hmu0agXKicn/rzpeak51uzy60VxqF1JME2oasF3K74C5ss4wxeGIxkVNY2iTN6Dl1Fb+lje8NmoJVyrWY8doTIqnP4vuk476DAXZXiuHNHhD25lulvyU6qy9crZY5ieFzIERyZBD1Fp5uxOu6ayKEx7+DnVb4zIizEkpqYggc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709828561; c=relaxed/simple; bh=iOKGmoiAtyaNEfPspMbGXngumI1iLOe4JU6F3yUH0X4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LEFE1AbmUIN8Ekdc8eRMrBdVjZ/V5s2SgWas4vcENBRelx8KSOqMfFbcEAz62CqqUwD6WPYPL0VeagQcdD2NH1u/90Na2oU43r5SB9+uRcUXe53K8mwAe+aP4avA7n0qp5fWbMc5Czg/OGNdA6u1WZm1yXMNnVLx2ciHCgs3lKg= 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=PI7MPIFX; arc=none smtp.client-ip=209.85.221.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="PI7MPIFX" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-33d60ac6781so453691f8f.0 for ; Thu, 07 Mar 2024 08:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709828557; x=1710433357; 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=Eey6UyU1uwGR1Imal6YxDk1CY4N/8kV8iyzGripb3QY=; b=PI7MPIFXXAh/bz4VqioPZLc5H3x5Ht7yGvZlxgaU6+FjPgvI8ijTWif8pK3waaU2DS lJCsQXYXq+h069gPf9WExiM+KUnT+HR9nHQWfFeucerOvR+DhpjM75aSKRYwsTlIuVKu ukuiEXsvVx7uJ9WajGSZF6Aj3HNzVMzbzeK9g0947GJyIRmWEJyU2myiYOPG7ahGDSRk cbb6QK5rNWdj9KU472fwraJupXpbLn0iLWajoy5nZb5IYEyTImipD4MLTwQ73K1MTWXc 2Yb89+kQ4B8Mo00Dlm1dA6Rv73fc/rsfE6ry0RsNnne/boAuyftAlbb4Ri3dWq+MDtsA MV8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709828557; x=1710433357; 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=Eey6UyU1uwGR1Imal6YxDk1CY4N/8kV8iyzGripb3QY=; b=aWtNGEmBkQyW2tsZ2o4gVqsXV0sK5U3st+7Uo386QLq0LRBpJFVnHwhl5URDrwQb04 8IavVesxxvv/kBM+y29Zs+COHvntU538NiWNj8IRV+v7QyQcHkHOSYoej+CW9lV9Oami exBdFtTPhcStQbjcLCTs3JgdzvkP1DrecvuXSnzF/XKm/3tZcBIxtYIGkL0/RWL/WFiJ vRk0mRl20bcq/yNA/jbvnIvVN1wASuFdo7tD8gWIcmk4ItoUqg7vm3zAPpYaQoT9znMx xmDKHq8zMtlnaKUnNYvJbUpNGzmvyruKav2nJnciqJL0hyGXOVOB3kK6ymDEnLmYlFKT GdBg== X-Gm-Message-State: AOJu0YybV6H6m2Gp2ah7iVNY7iApSUOIoHuRlmM8aFejoI8q5ZIeyQbK vLiSXNPC8eMiYgvlKhFXQuka6Z2jw6txazJ8IqKeOHPPZYzdjwxPZHfOHJToqIQhNBJ3ulcnRrF xvu0vexE9WZQzbLW9+Fj4P10X4ikUs9/eMb/mUR3oVrMo2DPYX0LCjJ2zCUxpqTvtC3nhYCkVz4 W4eJT0dv/kCFKwriHMhzVbc4mPng== X-Google-Smtp-Source: AGHT+IGRPtIfr2iqOrNdUj7DjFQwFRWxX9RydrlLCGUt/kdGkLkB71s9kU8j/RMRgNywZw0GsQ7WxsNq X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a5d:4fcd:0:b0:33e:40fc:3f8e with SMTP id h13-20020a5d4fcd000000b0033e40fc3f8emr31745wrw.9.1709828557363; Thu, 07 Mar 2024 08:22:37 -0800 (PST) Date: Thu, 7 Mar 2024 17:22:20 +0100 In-Reply-To: <20240307162214.272314-7-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: <20240307162214.272314-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=8766; i=ardb@kernel.org; h=from:subject; bh=Ub3tRaDvB+l63Oo+C+ZOR6R+ShHznPHMO9YFSMaaOTs=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXly70MR4t+aW86xLxFyGCB07+qWI0VD/6oLb0i/kldR vv0tr7kjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJrAhXJwCMBEfPUaG15UFrgc+dl2t28Cu svga83oWufp5x/13cM+79TZNfW7Ie0aGe22WNjdv7nLKfPvzU030+VcP5r9tPFVclZESnlwm80+ ZDwA= X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307162214.272314-12-ardb+git@google.com> Subject: [PATCH v2 5/5] 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 Link: https://lkml.kernel.org/r/0229a87e-fb19-4dad-99fc-4afd7ed4099a%40collabora.com [ardb: Split out final events table handling to avoid version confusion] Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 1 + drivers/firmware/efi/libstub/efi-stub.c | 2 +- drivers/firmware/efi/libstub/efistub.h | 4 +- drivers/firmware/efi/libstub/tpm.c | 82 +++++++++++++------- drivers/firmware/efi/libstub/x86-stub.c | 2 +- include/linux/efi.h | 2 + 6 files changed, 62 insertions(+), 31 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index f6cfd29308d9..8859fb0b006d 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -598,6 +598,7 @@ static const efi_config_table_type_t common_tables[] __initconst = { {LINUX_EFI_RANDOM_SEED_TABLE_GUID, &efi_rng_seed, "RNG" }, {LINUX_EFI_TPM_EVENT_LOG_GUID, &efi.tpm_log, "TPMEventLog" }, {EFI_TCG2_FINAL_EVENTS_TABLE_GUID, &efi.tpm_final_log, "TPMFinalLog" }, + {EFI_CC_FINAL_EVENTS_TABLE_GUID, &efi.tpm_final_log, "CCFinalLog" }, {LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" }, {LINUX_EFI_INITRD_MEDIA_GUID, &initrd, "INITRD" }, {EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" }, 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 72181c04420c..8abd2a1195d6 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 { @@ -1133,7 +1135,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 a880f7374c27..df3182f2e63a 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, + struct efi_tcg2_final_events_table *final_events_table) { - 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,10 @@ 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_1_2) { /* * The TCG2 log format has variable length entries, * and the information to decode the hash algorithms @@ -127,8 +108,6 @@ void efi_retrieve_tpm2_eventlog(void) * Figure out whether any events have already been logged to the * final events structure, and if so how much space they take up */ - if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) - final_events_table = get_efi_config_table(EFI_TCG2_FINAL_EVENTS_TABLE_GUID); if (final_events_table && final_events_table->nr_events) { struct tcg_pcr_event2_head *header; int offset; @@ -165,3 +144,50 @@ void efi_retrieve_tpm2_eventlog(void) err_free: efi_bs_call(free_pool, log_tbl); } + +void efi_retrieve_eventlog(void) +{ + struct efi_tcg2_final_events_table *final_events_table = NULL; + 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 { + final_events_table = + get_efi_config_table(EFI_TCG2_FINAL_EVENTS_TABLE_GUID); + } + } 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); + + final_events_table = + get_efi_config_table(EFI_CC_FINAL_EVENTS_TABLE_GUID); + } + + if (status != EFI_SUCCESS || !log_location) + return; + + efi_retrieve_tcg2_eventlog(version, log_location, log_last_entry, + truncated, final_events_table); +} 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 2493d3d4429b..a66d905caa7a 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -402,6 +402,8 @@ void efi_native_runtime_setup(void); #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) +#define EFI_CC_FINAL_EVENTS_TABLE_GUID EFI_GUID(0xdd4a4648, 0x2de7, 0x4665, 0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46) + /* * This GUID is used to pass to the kernel proper the struct screen_info