Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp125965imj; Wed, 13 Feb 2019 05:50:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IbxALIEaLFaF/jvMpSISCM34KMrO5U6DIBJcR7wv0YcI/6dYqsRqUzajM+fILuqZs0q9bBq X-Received: by 2002:a17:902:6948:: with SMTP id k8mr672143plt.2.1550065819482; Wed, 13 Feb 2019 05:50:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550065819; cv=none; d=google.com; s=arc-20160816; b=bMBibL4e9CnuCiK3cUvy6fa7/wK92ROio7FoxwsoyPhJh7Zw7r7dsN0+lN6NZYZylI 7votnqfhmivRWLkVrELeK9Bo+kOw00ShZw6JV5adzVq2kiAIXmvInIqc6gjUCiy95mio proxmt50Ai54geo6wYYhhjOdW0lmHOOpHDQGOZ6pYM+exVbM8OKf7SoXppqq3+CXt1Bj YvciAL8jXX7TUNDy3hYpvfHXmOIacoF2WS4U0Z8b/wRJKVHYfupvd2hRZKV7gK9syldB aO19zoDzXvOnXv9y9RuxH96LCy9GZcPK+W5DB8fQz1Oy+ASKwdsycdotk2ThJPnP+jjB /Kmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=n8AsgIsM7mW1vZjwx5hdhY9cfDVcuOuei5X45KPKIcw=; b=j9POs3ea2PpZMd/903jtflrbAANu27rvEpp9lWS3TWM+trLhpFLHMIR7P6hTT/kTEG QvS4PYh1SpC6GdKqPtlfM5QuGbIdlSy/++Ewmn3A6hyHC2jpqrjN2trC65aOXkq/e9zd KKQIqnFVdFXIlZE5nmDwmJN92nmZNKJ5dk7RHcFmsCrZp9rESpJZyz+7ig+5N0mnbrg/ +H1zbKHx90s71lC9Qk1c/EVlz9IUHpq/rTZKDd5gFxi/PUpmc3CW9KX579Llco2MKtWc OAhh1gsUleyLQl0kii1Uo4Uo23zh5J6Ihi4kayLxLQ3RwWNaNaUTJS8V9C8J/1O3/9yS 2vbQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si16079453plk.133.2019.02.13.05.50.03; Wed, 13 Feb 2019 05:50:19 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391730AbfBMLO5 (ORCPT + 99 others); Wed, 13 Feb 2019 06:14:57 -0500 Received: from mga12.intel.com ([192.55.52.136]:4817 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391691AbfBMLOw (ORCPT ); Wed, 13 Feb 2019 06:14:52 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2019 03:14:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,365,1544515200"; d="scan'208";a="126113237" Received: from sorenthe-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.151]) by orsmga003.jf.intel.com with ESMTP; 13 Feb 2019 03:14:43 -0800 Date: Wed, 13 Feb 2019 13:14:43 +0200 From: Jarkko Sakkinen To: bsz@semihalf.com, matthewgarrett@google.com Cc: linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, peterhuewe@gmx.de, ard.biesheuvel@linaro.org, tweek@google.com, mingo@kernel.org, hdegoede@redhat.com, leif.lindholm@linaro.org, mw@semihalf.com Subject: Re: [PATCH 1/5] tpm: Copy calc_tpm2_event_size() to TPM library Message-ID: <20190213111443.GE7087@linux.intel.com> References: <20190211143052.3128-1-bsz@semihalf.com> <20190211143052.3128-2-bsz@semihalf.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190211143052.3128-2-bsz@semihalf.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 11, 2019 at 03:30:48PM +0100, bsz@semihalf.com wrote: > From: Bartosz Szczepanek > > Function to calculate event size in TPM 2.0 log will also be needed in EFI > stub. Separate it to library to make it accessible out of TPM character > driver. > > It will be removed from tpm2.c in subsequent commit. > > Signed-off-by: Bartosz Szczepanek Collides with Matthew's patch set, which has priority over this because it was sent earlier. Matthew, what you think of this? Maybe could replace 1/4 with this in your patch set? Somehow feels a bit cleaner approach. > --- > lib/tpm.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 80 insertions(+) > create mode 100644 lib/tpm.c > > diff --git a/lib/tpm.c b/lib/tpm.c > new file mode 100644 > index 000000000000..aaeeafe52426 > --- /dev/null > +++ b/lib/tpm.c > @@ -0,0 +1,80 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2016 IBM Corporation Do we want copyright statements to new files? I'm sure that this code would have more copyright holders than just IBM (eg VMWare). Git documents this anyway. This is something that will be left unmaintained. > + * Parts of this file based on earlier work by: > + * Nayna Jain > + * Petr Vandrovec Please remove these three lines. These type of lists are just inaccurate presentaion of the commit log. > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version > + * 2 of the License, or (at your option) any later version. You already have SPDX identifier. Unncessary repeat. > + */ > +#include > +#include > +#include > +#include > + > +/* > + * 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. > + */ > +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; > +} > +EXPORT_SYMBOL(calc_tpm2_event_size); > -- > 2.14.4 >