Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2755825imj; Mon, 11 Feb 2019 08:01:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IanH/JLUNEyInmdrseq5bS9Y2Z34ZtRZQJ2TOxk7w3hr7CvwRmuIWZv2kkxbG0nEKHz8Mc5 X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr38453889plr.128.1549900910397; Mon, 11 Feb 2019 08:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900910; cv=none; d=google.com; s=arc-20160816; b=GtkcR80lxuxl3hrYbpzs8QAxvkq41tzch3lkoqO1m5lcWwkpP+IHl7atQUo12hu7AV FcJP7F7run3xw5LS6LXXEg2QmjYKN+05Y12EcEWLCKyAr2fY8Xba+ctPlNM9oTmg+BH9 DMU3iermJoPLqoYztIprJFTqg4Q5PxTM+UmaRhg2+c1APEe3T93mUKxd85+Lxqksko4r krLHvqU5I+YWETEyHh7b3SI2vCxZIWIWzDXHJ0dvgYTJa6AcFAz7uIzadB+RxC+s+79H e7ARXRyFtD3BBWbqZnKd/jne9T6mXRVfJIWS6oS7bfVzpWQMbCgW+TjYzaF9Xr4FmbJz RoXA== 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=zdCd+eahJl+Jgx83sGQrXrCpsjO9ENXDoI/VLqO8N5s=; b=S+Bm2pMH8LeqLjMogDtcJe+LGiufr4wahg4zGCk7d6ijGvTW5yRe0UoNhHN3hY1oeE itUxjapOJP9O2ieqyh8tZUnWhjnkiZd2KswIvsx5R3B0zt9suCEpvj+pPW61aubFLvHO u45fXfbSJnUiJz0c/ZQYI+S1qb+qWBNes4S4SB6ikhDnPVXvgH9cv7o0szvbvfxx3BAh 98+4bmOXAxovGbr7UW57KOmc7Vdlb5aimYDEg54v0C0upviuOuvJEkh13s1Wv1FqGEwg VDFh25FPC7zrXAkBeOSUEdAZkMmcUNnqoeM6cOBE2WotO42J9d/LL0ZnbJOX0vGgWy3c isqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=g0WkK0wA; 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 t9si10928488pfk.35.2019.02.11.08.01.29; Mon, 11 Feb 2019 08:01:50 -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=g0WkK0wA; 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 S1730562AbfBKQAf (ORCPT + 99 others); Mon, 11 Feb 2019 11:00:35 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:43887 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730317AbfBKObe (ORCPT ); Mon, 11 Feb 2019 09:31:34 -0500 Received: by mail-lf1-f68.google.com with SMTP id j1so7884849lfb.10 for ; Mon, 11 Feb 2019 06:31:32 -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=zdCd+eahJl+Jgx83sGQrXrCpsjO9ENXDoI/VLqO8N5s=; b=g0WkK0wADX8usdHfa0VcNaX+oFsXFAHJ7hqtjYsXRj13tO75890Yt7ke+hAf3zNhO4 qvpNKp8vZzVbGiWc6pNTDqZFddInSVwpzCPBjWZnRMKFwHfzQNDEEOFR5lCVyaY1Rk20 XB/9OiEbnok9nElviucOobsJrWqxiDRl2ylaMkTL26Qb6GSmrGjrlTgjj450XtF29Vi3 kbXv9UKnZrqWAU8bTnzoheeEJ/cjRj7UHK/5V7qBxH5yeEi1u6We0QjZGBWASReXZmEs 0bN8HQxhah2hDaYTbFRLmV8LZNBVHAhRC+wIA9QS67dlmCAjymW+8v83YyRPhhsluckM ojdg== 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=zdCd+eahJl+Jgx83sGQrXrCpsjO9ENXDoI/VLqO8N5s=; b=IPrFLIxYkXJt3iGRND8rBXzuUQF7D+wppomxi9EvWfWPXI06gbYUFQVVDapuZbKTXM 9jQRxYDzM5IftdLSTzbSRSj0R89RjHo8tihxUiNe20av9FnihnwspalyDB6UvgLbtPDT WFQSNEDP9qauAF9ddGammlSNbEIsHIqpUN4uH7/gli+1+rxanWzgLUnMu6EBDw+B84F2 tlCD11XdIfXUCTIMEGj2d1NkQyCy9ZhkVYtkrV5KISaa67BEQx6UyiFlMfkAyaVfHYdd egDfUO2GkW644swDPTV6TgiWAtmpHLpGT+UQtrO5MSKmfpXDFzj8CUslN3oSGD7TJfPZ 6nRA== X-Gm-Message-State: AHQUAuYPgFItSZGatFC5FDUckI5zTJnYApBGGfnmFCalbKNW808BDeV6 u4Wha1h/eNOQhwsvqU6f1E6BIg== X-Received: by 2002:ac2:43b7:: with SMTP id t23mr1696969lfl.50.1549895491490; Mon, 11 Feb 2019 06:31:31 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 06:31:31 -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 2/5] tpm: Change calc_tpm2_event_size signature Date: Mon, 11 Feb 2019 15:30:49 +0100 Message-Id: <20190211143052.3128-3-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 Pass tcg_efi_specid_event as an argument instead of tcg_pcr_event, as the former is what is actually needed to compute event size. tcg_pcr_event structure describes TPM event log header (even though its name), from where efispecid can be extracted -- it seems cleaner and less misleading to do it out of calc_tpm2_event_size function. Also, use ssize_t instead of int for event log size. Signed-off-by: Bartosz Szczepanek --- lib/tpm.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/tpm.c b/lib/tpm.c index aaeeafe52426..263ccfdaefa5 100644 --- a/lib/tpm.c +++ b/lib/tpm.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * calc_tpm2_event_size() - calculate the event size, where event @@ -23,19 +24,18 @@ * Family "2.0". * @event: event whose size is to be calculated. - * @event_header: the first event in the event log. + * @efispecid: pointer to structure describing algorithms used. * - * Returns size of the event. If it is an invalid event, returns 0. + * Returns size of the event. If it is an invalid event, returns -EINVAL. */ -int calc_tpm2_event_size(struct tcg_pcr_event2 *event, - struct tcg_pcr_event *event_header) +ssize_t calc_tpm2_event_size(struct tcg_pcr_event2 *event, + struct tcg_efi_specid_event *efispecid) { - struct tcg_efi_specid_event *efispecid; struct tcg_event_field *event_field; void *marker; void *marker_start; u32 halg_size; - size_t size; + ssize_t size; u16 halg; int i; int j; @@ -45,11 +45,9 @@ int calc_tpm2_event_size(struct tcg_pcr_event2 *event, 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; + return -EINVAL; for (i = 0; i < event->count; i++) { halg_size = sizeof(event->digests[i].alg_id); @@ -64,7 +62,7 @@ int calc_tpm2_event_size(struct tcg_pcr_event2 *event, } /* Algorithm without known length. Such event is unparseable. */ if (j == efispecid->num_algs) - return 0; + return -EINVAL; } event_field = (struct tcg_event_field *)marker; @@ -73,7 +71,7 @@ int calc_tpm2_event_size(struct tcg_pcr_event2 *event, size = marker - marker_start; if ((event->event_type == 0) && (event_field->event_size == 0)) - return 0; + return -EINVAL; return size; } -- 2.14.4