Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2410656yba; Fri, 17 May 2019 16:55:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqygt9SAojWHafQsIdOHiwXx/LUFxeKuAdEuYjxZsUTF/AtcJw8CjhzTFXsWrPbcznjZ3wSa X-Received: by 2002:a17:902:bd94:: with SMTP id q20mr37229763pls.146.1558137314767; Fri, 17 May 2019 16:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558137314; cv=none; d=google.com; s=arc-20160816; b=kvq0zhS5bsW1UzXiYWqw04NQq5NhX8C4NTItDy9cdcFVwts0MsXadCj2BDvEegr8r/ F210SOSpe5a8r5aV4YX9eMjXRJoG7IPYp1z46jg79BwbNrr9sx+ow9dGY3FYWWPvtMkM dwoLo1JS/9PeJbepLMktmV2cjktfK2/RWRGxE7Q1hOwChUUw27DGkEVFMdRuduK2M21r RrJOyhCdMwGDKWWRcW3IaA8oRcA4Y0eiUaCfsp1XtxiyoOQx0gAVNhnipFhFqHi6eGUz CRFErUolM9DNRB07yvXQS5x6k3pzai07p1Eo1LRT4u31xcyrdt38AVfZFnl3NfNng/0l 5vdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=27XlZCkUSOvunq8Y7K1xpByb07sERoUPEIdUjg1Yu24=; b=GVq2OXKKO47BZN8HY5M3SsFjzXP3hOX9yQ9hwda+Xjg+yKCq/K/ZnjEBw1QQEyrEA6 o2LO3XLjpPOqm0ScTAhA1iMUsz4KgYhBvEKCZEqDDq4tIY75XWRogPuRKEKXaAMNgMdR PY0xnZPHQ8jUMSuabKfcVMwp1A6a6pNSt+MDO0sWm4mDWe5eIpbAts0lWT9D8rB6vQDY sMgmRnml9NUP/IKyKyhnWrDjRRJaws/JrS4KMdSskxIKnL9zMkWsIly0waEjSGIGahIU kvzOneMVav22MFDz/FiAVo0f8tb5Bg4HH5zDx8LHmmZ2nspqT6WFxttYuCCaq+H4FGpj SpYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Nmj5WsGp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be11si9231126plb.303.2019.05.17.16.54.57; Fri, 17 May 2019 16:55:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Nmj5WsGp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729625AbfEQVjd (ORCPT + 99 others); Fri, 17 May 2019 17:39:33 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:38604 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729606AbfEQVj3 (ORCPT ); Fri, 17 May 2019 17:39:29 -0400 Received: by mail-pf1-f201.google.com with SMTP id x5so5356902pfi.5 for ; Fri, 17 May 2019 14:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=27XlZCkUSOvunq8Y7K1xpByb07sERoUPEIdUjg1Yu24=; b=Nmj5WsGpY6eH5l1CIzj3XtT6AYXnaMsyBZtfyh/nKuUM187l2YkpGAA/m01INmJdCj xTEWTeS4ckCQpsaBY4MHAahrSjUgJBXHhMd0P/lhlpALNnqGNP+miZJWEG1F85Yjw0qg kIGf97H9mKa5d0NdiOVUgDC7Jbji9+oM22lsZX5Jl8d7ifoKK4BzTH6oJ3hNpAxuN1xU LWPbBhFDhE2cJc8xROiesWla2sxdmnTNBAFXUZ/5fI3RvpwuJXYE0nTLgCrta5A+z/vQ AvgXW9HGXOWpYCfC14ILu/IA0ft1qk+WTSMNFA1zjj2oXn6Ni3ohT12QbV13T1ZOasxB hNLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=27XlZCkUSOvunq8Y7K1xpByb07sERoUPEIdUjg1Yu24=; b=D6YqMwGJMuZjsHxThGkxR3Acfd/DNMVRqZhDvT+mVq+ThMy3h1jNGskt0xXMFXwAHK sWBNHgpU9fuwaZ5dWuaY0TnehLA9lN5StJBtu89q3evr+mLGEBUn5sPbP5BRegXV7Da8 VNXtLIkF1fYnQ5vXuTiGbJMrGQYWLQrHXXhP/WG8Ptc20klOeD2nluZGBpsJlphSY6pU nKkkQbUzb6WzJVYcF8D6zfQySY9Ka/pcsEkPqk/PhCPeeEG3qwtQwF0lnZwVnpWqngzt 8keb2QYIuFE8ECRxjRBZeIMLpe6tVz9tlW+kzD7AWZAWmnEuzXXWFt3pxzp5dEPLNrrW pEBg== X-Gm-Message-State: APjAAAWXSFe307kBg/7kcNpR+RWs04NaKsqtJweHRPWO0frm/gtB++vR VZt9fy/9o+K+K7UR4o6q0sxiAF1C1fI7xjQLIogOSA== X-Received: by 2002:a63:5b5c:: with SMTP id l28mr15268814pgm.158.1558129169103; Fri, 17 May 2019 14:39:29 -0700 (PDT) Date: Fri, 17 May 2019 14:39:17 -0700 In-Reply-To: <20190517213918.26045-1-matthewgarrett@google.com> Message-Id: <20190517213918.26045-4-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190517213918.26045-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH V6 3/4] tpm: Append the final event log to the TPM event log From: Matthew Garrett To: linux-integrity@vger.kernel.org Cc: peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, jgg@ziepe.ca, roberto.sassu@huawei.com, linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, tweek@google.com, bsz@semihalf.com, Matthew Garrett Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Garrett Any events that are logged after GetEventsLog() is called are logged to the EFI Final Events table. These events are defined as being in the crypto agile log format, so we can just append them directly to the existing log if it's in the same format. In theory we can also construct old-style SHA1 log entries for devices that only return logs in that format, but EDK2 doesn't generate the final event log in that case so it doesn't seem worth it at the moment. Signed-off-by: Matthew Garrett Tested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/eventlog/efi.c | 50 ++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c index 3e673ab22cb4..9179cf6bdee9 100644 --- a/drivers/char/tpm/eventlog/efi.c +++ b/drivers/char/tpm/eventlog/efi.c @@ -21,10 +21,13 @@ int tpm_read_log_efi(struct tpm_chip *chip) { + struct efi_tcg2_final_events_table *final_tbl = NULL; struct linux_efi_tpm_eventlog *log_tbl; struct tpm_bios_log *log; u32 log_size; u8 tpm_log_version; + void *tmp; + int ret; if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) return -ENODEV; @@ -52,15 +55,48 @@ int tpm_read_log_efi(struct tpm_chip *chip) /* malloc EventLog space */ log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); - if (!log->bios_event_log) - goto err_memunmap; - log->bios_event_log_end = log->bios_event_log + log_size; + if (!log->bios_event_log) { + ret = -ENOMEM; + goto out; + } + log->bios_event_log_end = log->bios_event_log + log_size; tpm_log_version = log_tbl->version; - memunmap(log_tbl); - return tpm_log_version; -err_memunmap: + ret = tpm_log_version; + + if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR || + efi_tpm_final_log_size == 0 || + tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) + goto out; + + final_tbl = memremap(efi.tpm_final_log, + sizeof(*final_tbl) + efi_tpm_final_log_size, + MEMREMAP_WB); + if (!final_tbl) { + pr_err("Could not map UEFI TPM final log\n"); + kfree(log->bios_event_log); + ret = -ENOMEM; + goto out; + } + + tmp = krealloc(log->bios_event_log, + log_size + efi_tpm_final_log_size, + GFP_KERNEL); + if (!tmp) { + kfree(log->bios_event_log); + ret = -ENOMEM; + goto out; + } + + log->bios_event_log = tmp; + memcpy((void *)log->bios_event_log + log_size, + final_tbl->events, efi_tpm_final_log_size); + log->bios_event_log_end = log->bios_event_log + + log_size + efi_tpm_final_log_size; + +out: + memunmap(final_tbl); memunmap(log_tbl); - return -ENOMEM; + return ret; } -- 2.21.0.1020.gf2820cf01a-goog