Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1350877ybp; Thu, 17 Oct 2019 11:27:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOMG2C8zTmhcrjoGpOPnaShOaOv4TI3S57JZ8h03/rn0IFv4r9rr5vG6hIo0do0yZVhBKQ X-Received: by 2002:a17:906:4a97:: with SMTP id x23mr4731127eju.218.1571336853200; Thu, 17 Oct 2019 11:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336853; cv=none; d=google.com; s=arc-20160816; b=sgjVwvA7glC4+xHb4z74G1zEJeClQRNwjHbgU/fQKueK4XbkB4vt2rfMugaRy8MLsE HaNCiD3iU5jiN+JwDaVePH75OXsiZaDTGsbc55VQ86b35j8l9/M8EQ3oViv0bz5YDnMq yk9ytrxx2KQVdWS5xroQkMsZU5h1nJ6eIVpvliz0GtFApuyDh4RwRNw8BKzMw9Gk8BCn J9W7uISraf4nE75K4Q6S2AvkYGyqkoxkjOSCZAh0vyCMxB6EHEr8YrhBGwtniv4i18jg P9D0+fSOJWHrr9oqnBGln7Da4aCpVZgPUoTxaO694e4ovJ4TPt44j+nmOjNro4QGLKNQ VciQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5XKYeHaRgdARMY0DiSEzuGuaAYSEKKcZZDZs/lAhOak=; b=tq8re28sv84wRn77t1eZRI8cHSYOdXT4rBNHJUVtGjQPjg4yVqjEWJE4Ei7Ut2T4DI AsqXbl7PVecOw08yzT7u8qH7gL0p13v9a+H0fsvInAMo3KWYGpkDtlY3FVJsiaJVPt7u ZXyJSnJ+nTA7qXmLItitxxcbXwOILx7Cm5QMaheJc0f7nWWktsoT528G69oHOzGuBtFu D8vPhMbde959YFoKsOM6O1Btod0cm6uDiM232plKRQRvpe6aLWFAN1xDUfQcAUA+/KFx PdQQyalbzVbO43j1Qrf3dpBkzu8oAY3dxx9DJeruIQmUIXy7RTd4O9WnePref5j0EoZq bhTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=De6ExkF7; 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 w30si2240217edd.137.2019.10.17.11.27.07; Thu, 17 Oct 2019 11:27:33 -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=@kernel.org header.s=default header.b=De6ExkF7; 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 S2406874AbfJPWEi (ORCPT + 99 others); Wed, 16 Oct 2019 18:04:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:53148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438357AbfJPV7B (ORCPT ); Wed, 16 Oct 2019 17:59:01 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D96221A49; Wed, 16 Oct 2019 21:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263140; bh=4xJdH9kiHe2LVsMTel/OrXlDj2ZKHxjrUQ6T4JRXoFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=De6ExkF7wVeRRDdy58ATeybhFXTE+n8SMTprMei9r9u8MpT6tet/tiK9J5V4fDe7c qNi7JEuiL4QNNKmYfefq4sXUB0BW9vXDli0SZPQ8zG3+E8uMdM1tw4vheH2XmBCDhB bClbO3RykCYJPYzpPPFRp1nCb3YCkOP/hvFynsJs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lyude Paul , Peter Jones , Jarkko Sakkinen , Ard Biesheuvel , Matthew Garrett , Ben Dooks , Dave Young , Jerry Snitselaar , Linus Torvalds , Lukas Wunner , Octavian Purdila , Peter Zijlstra , Scott Talbert , Thomas Gleixner , linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, Ingo Molnar Subject: [PATCH 5.3 064/112] efi/tpm: Dont traverse an event log with no events Date: Wed, 16 Oct 2019 14:50:56 -0700 Message-Id: <20191016214901.749711997@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Jones commit 05c8c1ff81ed2eb9bad7c27cf92e55c864c16df8 upstream. 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. Tested-by: Lyude Paul Signed-off-by: Peter Jones Signed-off-by: Jarkko Sakkinen Signed-off-by: Ard Biesheuvel Reviewed-by: Jarkko Sakkinen Acked-by: Matthew Garrett Acked-by: Ard Biesheuvel Cc: Ben Dooks Cc: Dave Young Cc: Jerry Snitselaar Cc: Linus Torvalds Cc: Lukas Wunner Cc: Octavian Purdila Cc: Peter Zijlstra Cc: Scott Talbert Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Cc: linux-integrity@vger.kernel.org Cc: stable@vger.kernel.org Fixes: c46f3405692d ("tpm: Reserve the TPM final events table") Link: https://lkml.kernel.org/r/20191002165904.8819-5-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/tpm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -75,11 +75,16 @@ 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); + + 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));