Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2194784ybl; Sat, 31 Aug 2019 09:48:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwo76g+33dnQqr3ZfDzCRHWskE6BiOQj47pUMMzaT0HN2XJxSVy2V+q9OMjYnxuzQ19ml2W X-Received: by 2002:a62:3083:: with SMTP id w125mr5851793pfw.102.1567270080070; Sat, 31 Aug 2019 09:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567270080; cv=none; d=google.com; s=arc-20160816; b=N3w1KzpKYnbNQ6XqPG1dsGvY7Xdh+hhS+bLgVfHArf6ZMzsk7HScboXiETtOjLpRB6 /ejJJ/RL98QzyQyLi2s0/qfZUpp9rtWcMgIyueEEijKMB2bkvKjbvyfnGmk77AUrOdJs w+h2fxG+vw1qRUM9L+iET4DTqXt5HuEcKAuar7/XSe18T9OCmF9C9WKuv8BTExtnZrjT gqxBma0B8tUy8JW4y9IhdjfvBZpu+OeN/0sBmj2MhP/bW2rPRGtmm9sysih1j5LHPF8V EH89Zuq64ElMsG4ckdd+M4JZS1GGl+Xbrh8Jxej3dK3pMzEePotJ3o42l8tpY9SRHGlx rM6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bWNyzY6frPd9AVvoBYLqQl+upEDUNdJLOAMB1R+T9tw=; b=kgMCO8HslTd6l6fcIv4cDnj+wOgqALRnWGEf2QLpK964g7Dc7hgPB1SPrCj9m7KxYA VTmT6w45JRDvth2fTVr3ZOqrEdI6vDX2dXSc1DZcx05ZtwUl++Tn5TfcAr97j/MwEQU0 2cPDj3rk6jTF6UavjwyFH+B4O9i68Q+f4pltKS0v71iA+m9qsz7mB1orfh6zPH8OHsSr XJN3q/mfMmZ5DCEbTgx65miVKmF4MNxSlIRcLWccS3NA+og5uUm3shZVkQL1/aSzJpui dkJ3hBmasBtHLiN5boTPx6HWeQlUw8+WZG0o9OgBJ5UFIrII93oed9VraytU3PgzpltJ nkRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fS+2dRlM; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26si9150120pfn.94.2019.08.31.09.47.45; Sat, 31 Aug 2019 09:48:00 -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=@linaro.org header.s=google header.b=fS+2dRlM; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728465AbfHaQqO (ORCPT + 99 others); Sat, 31 Aug 2019 12:46:14 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:32860 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727836AbfHaQqO (ORCPT ); Sat, 31 Aug 2019 12:46:14 -0400 Received: by mail-wm1-f68.google.com with SMTP id r17so8664753wme.0 for ; Sat, 31 Aug 2019 09:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bWNyzY6frPd9AVvoBYLqQl+upEDUNdJLOAMB1R+T9tw=; b=fS+2dRlMhE+Nq5glJysLmAuytzq9t4tg0oXMrARfiKlHHK7ICA88SF8nlV23LyVver dZ7iD91N78LuBLyx36/IgB3mzS7pCjbMu0Burnkf9y8qaVzliT7X6jKR8Mkps5/hhljF coeveC5lriwf0g1b01PlY3yav3r33RPaCOgRS7wd/DMXs+mIxBj/wk5zu7+sT7wxjGTr fTHxhUPECasNXgXz79az5b4ChhtUd6Q2wxz6iuDKEqo+jjJiLwc9xdDZSusSWlvBgeJT la19MgY9UhYxuhZ5wIeIVhMH0u3Loaw13hgns8mk//FxDYwBUuP/T2oWBLYXdu4kzfr5 c/rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bWNyzY6frPd9AVvoBYLqQl+upEDUNdJLOAMB1R+T9tw=; b=UQrmAaNGTneniIwR30BVLSy8NziXKvBfZYwKVy51ptXGxvoxC2E5i52RLR6AatS214 31+TiZRx3VJ8Ih5pH4JMqJ8zDtzWrK5vKwLbGrnGWNEPYNRXSDor/NdzTl74X9OwS3/g sWVivEIMLMhafYXcxYssQ1JXtv/pgxQTsUGgj2M9n1HkV7rmxlv8MCGRlEYAL0BVMEeL 5gwXhIAa0Z8cjWLN56+vn6xkzkJHA8bOPcuXadLmQOZQ6AsMFXThBWi1oq5u6xJokvKY +RKZqUDIg0D/d3Ztqv0568N6Jd9xz5jr28TVOtHQPO8sTmR48MWKudzKu8JelzeGlT/O AjiA== X-Gm-Message-State: APjAAAWiu35az3K1Z54v+jrusUn/qch/iwYq3Gb5sWmXksuDV2j9A0Zw yFqPfv+G/Pm2FP7LnsVUIL6iO6Fnf0KJQXQ42Ig7Nw== X-Received: by 2002:a7b:cb8e:: with SMTP id m14mr26387918wmi.10.1567269971792; Sat, 31 Aug 2019 09:46:11 -0700 (PDT) MIME-Version: 1.0 References: <20190826153028.32639-1-pjones@redhat.com> <20190826153028.32639-2-pjones@redhat.com> In-Reply-To: <20190826153028.32639-2-pjones@redhat.com> From: Ard Biesheuvel Date: Sat, 31 Aug 2019 19:46:00 +0300 Message-ID: Subject: Re: [PATCH 2/2] efi+tpm: don't traverse an event log with no events To: Peter Jones Cc: Jarkko Sakkinen , Roberto Sassu , Matthew Garrett , Bartosz Szczepanek , Lyude Paul , linux-efi , Linux Kernel Mailing List 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 On Mon, 26 Aug 2019 at 18:30, Peter Jones wrote: > > When there are no entries to put into the final event log, some machines > will return the template they would have populated anyway. In this case > the nr_events field is 0, but the rest of the log is just garbage. > > This patch stops us from trying to iterate the table with > __calc_tpm2_event_size() when the number of events in the table is 0. > > Signed-off-by: Peter Jones > Tested-by: Lyude Paul > --- > drivers/firmware/efi/tpm.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c > index 1d3f5ca3eaa..be51ed17c6e 100644 > --- a/drivers/firmware/efi/tpm.c > +++ b/drivers/firmware/efi/tpm.c > @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) > goto out; > } > > - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log > - + sizeof(final_tbl->version) > - + sizeof(final_tbl->nr_events), > - final_tbl->nr_events, > - log_tbl->log); > + tbl_size = 0; > + if (final_tbl->nr_events != 0) { > + void *events = (void *)efi.tpm_final_log > + + sizeof(final_tbl->version) > + + sizeof(final_tbl->nr_events); Please put a newline here With that fixed, Acked-by: Ard Biesheuvel > + tbl_size = tpm2_calc_event_log_size(events, > + final_tbl->nr_events, > + log_tbl->log); > + } > memblock_reserve((unsigned long)final_tbl, > tbl_size + sizeof(*final_tbl)); > early_memunmap(final_tbl, sizeof(*final_tbl)); > -- > 2.23.0.rc2 >