Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2755358imj; Mon, 11 Feb 2019 08:01:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IZTA4MCkPfPCW0QN1aOeiqQTX0zU9CetkLiGDnIdUT0aOBvEJDulRaT8obIiX6L4tOBZ+tl X-Received: by 2002:a62:ab04:: with SMTP id p4mr6675432pff.142.1549900887900; Mon, 11 Feb 2019 08:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900887; cv=none; d=google.com; s=arc-20160816; b=vM/Sg3aoxrDJgm4Pv5ASzV4HyaXEI/CaXprqjBsOQ/rHoogIeymphpnyltJ1dlJeJv ifIYOcVY9AyhSUghyfiW4p0lr0eNEnTXqRQOFfjUVBHK59N3UXr/YP8CJma3xKwQtjYv jFql311wU7wwf509z/aokqIr7YmUl9B3dIbOejZWZxiSazITf4rAXnssLD5VbNVf3VSR 3kfXMtOIHr7YD2+g0bgzA4c2khwhaLBTAcAu0yJa3eFsRBQ4IyQHJJ361/RZmN08Dl8v C1/N9sYuRmC1mdoGrbMtJP64DqHQs0ymOsThwXQkJwPnBWgcvQVOpkcJkbPAi2p9cyHl 9jQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=4mT+Uw4qv/27OkDGZ2Z4PNLv1X7pO+nJwrUwXygNfR4=; b=xkPIpXNSxgRIJx65coeewGaN2bIkiGo/M+yTRaDfcVneTZNnnGGDG1LQhh9wQrQZii Cbmd9gRdhr20dv8528GeeECeMbjrlQ3Ey0KVnFoMld2RZE9tzXj/2emtraJktJEbzBQH QfA+a2XAKX12F6m/+O4Yw7Ux008QjI/T4BOqTm04jkJnIIlddaTtIsAriobBXV+w5dYL d1n05/rrMReBQbzDZD5qZfcwE3ztb7TYGX7jjps3kbBMTASqzI4fshv9VPB28TFc9hCe JAtLhjz5GPdTj69V4hTKmR5tbjzNs5E0RGLe70iq2zESNYsv7+GeXb020Ck84bujH8lp S50w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=Ksoo+IaF; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si1402405pgh.564.2019.02.11.08.01.09; Mon, 11 Feb 2019 08:01:27 -0800 (PST) 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=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=Ksoo+IaF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728815AbfBKObo (ORCPT + 99 others); Mon, 11 Feb 2019 09:31:44 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40527 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730329AbfBKObi (ORCPT ); Mon, 11 Feb 2019 09:31:38 -0500 Received: by mail-lf1-f68.google.com with SMTP id t14so7895435lfk.7 for ; Mon, 11 Feb 2019 06:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4mT+Uw4qv/27OkDGZ2Z4PNLv1X7pO+nJwrUwXygNfR4=; b=Ksoo+IaFbmKFle9VdM18OBfuhuq0AORuU9TMZhqnGG4BhuOcpzLfP39+nSSNz7guOj XUj4NweOocnRBgkvfUoJK0CMB9l4DHseIMOriF3dxaLxaJ/+iQRiPRIbsoxL6mcO8HCN vPmU884prGZIfUgXceoHizmjqzdssXSpY4R50ThjS33EhEcvzPDUgD1FYMeBqIgG2+eZ 0S2IfTSoAd86+Dv20Iqj+LOvwAT/FFAqaUxExdYsPFcfIqHCeI1IdBETTMMWaSb43ohW FUiCCNZV8GHyPxOVHkYJu8Gmfd1L2KIHdIwWpCLLuy2ILht2E7alJHc2LpUjgf2e9iQz LdwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4mT+Uw4qv/27OkDGZ2Z4PNLv1X7pO+nJwrUwXygNfR4=; b=NXd/+LBcxtaOzRHRgWcW9TI7zDPDe2q9ohIi1t3fTZW40xJ7O5ohuRCZI6lv2BdxRh SdvrE6zucIyzTbV82IeVHXYMN7O/KaLF4nBHGgvOu6S/tlz4JN4jywY5IV6oLXF6D79V zjqxmdkWRgN6Rx8h25z/jzeWurQxe0zresYBDwRY0geFRidacbnJjFliyEERDHy7GRae IeH3+DbMp+BLwM0W7plJkCICsWZ4ubTnh+/7l1LQNTyWrr5cmohUUlqcJ7gbU5Nr/7eb sZSf4+eJDUvfJip9RyiJFDeeUMMXVHbbefIAHwQmSy6FvMIhNpYIIEm93/8gjd4lknRc u3Jw== X-Gm-Message-State: AHQUAuZKMKanEPoFQbcihVfGzMU7XfL/t7hCq430jRwMFiJ9I/T9p4tZ exDO5ZKtB8bWKQ1Wh9LdYOhhVQ== X-Received: by 2002:a19:59c2:: with SMTP id n185mr21587542lfb.118.1549895495351; Mon, 11 Feb 2019 06:31:35 -0800 (PST) Received: from bsz-kubuntu.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id z6sm2322373lfa.87.2019.02.11.06.31.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 06:31:34 -0800 (PST) From: bsz@semihalf.com To: linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, ard.biesheuvel@linaro.org Cc: tweek@google.com, mingo@kernel.org, hdegoede@redhat.com, leif.lindholm@linaro.org, mw@semihalf.com, Bartosz Szczepanek Subject: [PATCH 3/5] tpm: Use library version of calc_tpm2_event_size in sysfs code Date: Mon, 11 Feb 2019 15:30:50 +0100 Message-Id: <20190211143052.3128-4-bsz@semihalf.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211143052.3128-1-bsz@semihalf.com> References: <20190211143052.3128-1-bsz@semihalf.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Szczepanek Expect negative values from calc_tpm2_event_size as error codes. Pass efispecid instead of event header to calc_tpm2_event_size. Also, include tpm library in the build. Signed-off-by: Bartosz Szczepanek --- drivers/char/tpm/eventlog/tpm2.c | 89 ++++++++-------------------------------- include/linux/tpm_eventlog.h | 3 ++ lib/Makefile | 2 + 3 files changed, 22 insertions(+), 72 deletions(-) diff --git a/drivers/char/tpm/eventlog/tpm2.c b/drivers/char/tpm/eventlog/tpm2.c index 1b8fa9de2cac..5230821d5b1c 100644 --- a/drivers/char/tpm/eventlog/tpm2.c +++ b/drivers/char/tpm/eventlog/tpm2.c @@ -26,80 +26,20 @@ #include "../tpm.h" #include "common.h" -/* - * calc_tpm2_event_size() - calculate the event size, where event - * is an entry in the TPM 2.0 event log. The event is of type Crypto - * Agile Log Entry Format as defined in TCG EFI Protocol Specification - * Family "2.0". - - * @event: event whose size is to be calculated. - * @event_header: the first event in the event log. - * - * Returns size of the event. If it is an invalid event, returns 0. - */ -static int calc_tpm2_event_size(struct tcg_pcr_event2 *event, - struct tcg_pcr_event *event_header) -{ - struct tcg_efi_specid_event *efispecid; - struct tcg_event_field *event_field; - void *marker; - void *marker_start; - u32 halg_size; - size_t size; - u16 halg; - int i; - int j; - - marker = event; - marker_start = marker; - marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type) - + sizeof(event->count); - - efispecid = (struct tcg_efi_specid_event *)event_header->event; - - /* Check if event is malformed. */ - if (event->count > efispecid->num_algs) - return 0; - - for (i = 0; i < event->count; i++) { - halg_size = sizeof(event->digests[i].alg_id); - memcpy(&halg, marker, halg_size); - marker = marker + halg_size; - for (j = 0; j < efispecid->num_algs; j++) { - if (halg == efispecid->digest_sizes[j].alg_id) { - marker += - efispecid->digest_sizes[j].digest_size; - break; - } - } - /* Algorithm without known length. Such event is unparseable. */ - if (j == efispecid->num_algs) - return 0; - } - - event_field = (struct tcg_event_field *)marker; - marker = marker + sizeof(event_field->event_size) - + event_field->event_size; - size = marker - marker_start; - - if ((event->event_type == 0) && (event_field->event_size == 0)) - return 0; - - return size; -} - static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) { struct tpm_chip *chip = m->private; struct tpm_bios_log *log = &chip->log; void *addr = log->bios_event_log; void *limit = log->bios_event_log_end; + struct tcg_efi_specid_event *efispecid; struct tcg_pcr_event *event_header; struct tcg_pcr_event2 *event; - size_t size; + ssize_t size; int i; event_header = addr; + efispecid = (struct tcg_efi_specid_event *) event_header->event; size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event) + event_header->event_size; @@ -115,16 +55,16 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) if (*pos > 0) { addr += size; event = addr; - size = calc_tpm2_event_size(event, event_header); - if ((addr + size >= limit) || (size == 0)) + size = calc_tpm2_event_size(event, efispecid); + if ((addr + size >= limit) || (size < 0)) return NULL; } for (i = 0; i < (*pos - 1); i++) { event = addr; - size = calc_tpm2_event_size(event, event_header); + size = calc_tpm2_event_size(event, efispecid); - if ((addr + size >= limit) || (size == 0)) + if ((addr + size >= limit) || (size < 0)) return NULL; addr += size; } @@ -135,6 +75,7 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, loff_t *pos) { + struct tcg_efi_specid_event *efispecid; struct tcg_pcr_event *event_header; struct tcg_pcr_event2 *event; struct tpm_chip *chip = m->private; @@ -144,6 +85,7 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, void *marker; event_header = log->bios_event_log; + efispecid = (struct tcg_efi_specid_event *) event_header->event; if (v == SEQ_START_TOKEN) { event_size = sizeof(struct tcg_pcr_event) - @@ -151,8 +93,8 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, marker = event_header; } else { event = v; - event_size = calc_tpm2_event_size(event, event_header); - if (event_size == 0) + event_size = calc_tpm2_event_size(event, efispecid); + if (event_size < 0) return NULL; marker = event; } @@ -163,8 +105,8 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, v = marker; event = v; - event_size = calc_tpm2_event_size(event, event_header); - if (((v + event_size) >= limit) || (event_size == 0)) + event_size = calc_tpm2_event_size(event, efispecid); + if (((v + event_size) >= limit) || (event_size < 0)) return NULL; (*pos)++; @@ -180,10 +122,13 @@ static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v) struct tpm_chip *chip = m->private; struct tpm_bios_log *log = &chip->log; struct tcg_pcr_event *event_header = log->bios_event_log; + struct tcg_efi_specid_event *efispecid; struct tcg_pcr_event2 *event = v; void *temp_ptr; size_t size; + efispecid = (struct tcg_efi_specid_event *) event_header->event; + if (v == SEQ_START_TOKEN) { size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event) + event_header->event_size; @@ -193,7 +138,7 @@ static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v) if (size > 0) seq_write(m, temp_ptr, size); } else { - size = calc_tpm2_event_size(event, event_header); + size = calc_tpm2_event_size(event, efispecid); temp_ptr = event; if (size > 0) seq_write(m, temp_ptr, size); diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 20d9da77fc11..872ab1545456 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -121,4 +121,7 @@ struct tcg_pcr_event2 { struct tcg_event_field event; } __packed; +ssize_t calc_tpm2_event_size(struct tcg_pcr_event2 *event, + struct tcg_efi_specid_event *efispecid); + #endif diff --git a/lib/Makefile b/lib/Makefile index e1b59da71418..4458d914f40b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -276,3 +276,5 @@ obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o obj-$(CONFIG_OBJAGG) += objagg.o + +obj-$(CONFIG_TCG_TPM) += tpm.o -- 2.14.4