From patchwork Wed Oct 2 16:59:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175022 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020436ill; Wed, 2 Oct 2019 10:04:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4LzVqjr+KqfcX97r83FiK9JHJ0rYlmfwfjzgoc/c8UResK0+CiGxeyfVDCDqLvuBsVbaB X-Received: by 2002:a17:906:c310:: with SMTP id s16mr4060881ejz.178.1570035840462; Wed, 02 Oct 2019 10:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035840; cv=none; d=google.com; s=arc-20160816; b=lBjyZOrLH4QA1TY6TSChqz/KoeMwVuXLL0DBwqIzkQizrdKY3SoqilJcfPbsIV8yNt Jn8KIyJd9gxH+NOGXFQSml1AKgQt1nPsdLbPywdg94hGYWc6Dt+VTbO+rLZlpSiE9a8w z8HPpL3b0mAMUAIdOVrgIQEalJnPlZlQYSufW8Sc5MUXrWnopCc2amhVkR+QYF9vXkr6 keNDsUIayXbA9KtlBPRwbDnS6Lw/S5LetovSwkeueuNDlubQc7y81Or5znvaX26MSBk5 E4WfhHC1ch60fvfOlTssgfsLaJFS0jBEODxY/bWm4b74fwIa4OHtbFuyb1fNx3nwWn24 78nQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4a/CPg2xqZ+b/NZpx616PMtohSxll231qGMOuYzcxWE=; b=VZzG8faZU3IHHLi9yg0JXdpLRJqJadu6mbjBy9/00D5Qe7gz188k6PI3v2fXdxIuEc hWUn+51Yt0PdeEL+3uvPr2EiN37Yk7cYFwZJlGWqlOJc7PU93k70e5M/ZM1iLuUdzSPP 1bf+LuEBvQlqpzQw4Dof10xiKyNGFrW4fyESDtJm2JcqSu2rC0/xulLU8Zh8jTdhfkww F08JNAuSPnPHcV0MSorimvMrjp1EKvdi3b41tld8nF8DuZBuGH69BxdncqBG0VmnQ/oW iBQ3wgcUKFP4MAoqnc/RnNPWeEHfpOQ96CFRahhZjJ8NMT5unrLr/oVN0qTTLbZjd5D/ 4SXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tdnoIcnm; 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 q15si4768244ejj.183.2019.10.02.10.04.00; Wed, 02 Oct 2019 10:04: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=tdnoIcnm; 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 S1728787AbfJBRD7 (ORCPT + 27 others); Wed, 2 Oct 2019 13:03:59 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:47094 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728663AbfJBRD4 (ORCPT ); Wed, 2 Oct 2019 13:03:56 -0400 Received: by mail-wr1-f65.google.com with SMTP id o18so20484744wrv.13 for ; Wed, 02 Oct 2019 10:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4a/CPg2xqZ+b/NZpx616PMtohSxll231qGMOuYzcxWE=; b=tdnoIcnmIker0lvF0KY3CO60+cNs1URBTEXXNXeUHW2fshCRDEH9xmYdis8pb1fbyb vNRpKz04Fu+yWrCMZl4FUbI/pJEuRCInVKToqfVtof3VoXvgmrFZtNwmeBWMGXrl00xF FqVum7Wmu5DH4DDvKIL3nYWX00HsxNPaIzDN5jDm0hi91BB0lXTB58XpG5EYQ6fIvWns 3YVbuJarZaqE5M9XLA0CmxLCQ7htEsQld6/RrO2fbgf84bF3w1DL/ozhBDdgqWWWOwyz NsAL2C7i/UyXnd35g6XPDzPh2xyrhVXOtrhyCG/WpIOwdMbI5nzYR9ztd3wtLNA46vQj HAUA== 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:mime-version:content-transfer-encoding; bh=4a/CPg2xqZ+b/NZpx616PMtohSxll231qGMOuYzcxWE=; b=VT6w3bFtHsA38vmv+2X0dm2f0ZmjXnlEfCCDZIMbTsrza/3onblbS9bMLUtK1FVEfC Ku4Yeda3QiqjoDWPaqtOGQv/NIDZrzpKUtgzY5bOIixF+0VjLePESHohd/v4GDIblYyD pgVuJx3W9NSUVwOLuNtbUroNxGLz031Dr7k6WNVSjFikzIEGNTpMTUZrEmvSm6eBGGiZ hPxigNmxJ37HHamRzaFrx2K7PrURbTRFOSlbt9UFGzJLtOSg3mOficE3jV1aW6Q+FUZ8 8v8EsbKseZQ45bH6GA92W0q79xNzPxnxdbjXPlKS6NApNcluXmYFndHiIcbRflS69Fdn 9hBQ== X-Gm-Message-State: APjAAAVOzclutW60vrywqRVk0HkoM5W7/JIOlr7ZwxaqU/HjgDCaiF9I 9IGkFH0Ap10w70dyXCEjCvll3A== X-Received: by 2002:adf:e849:: with SMTP id d9mr3616348wrn.358.1570035834376; Wed, 02 Oct 2019 10:03:54 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:f145:3252:fc29:76c9]) by smtp.gmail.com with ESMTPSA id f18sm7085459wmh.43.2019.10.02.10.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:53 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Ben Dooks , Dave Young , Jarkko Sakkinen , Jerry Snitselaar , linux-integrity@vger.kernel.org, Lukas Wunner , Lyude Paul , Matthew Garrett , Octavian Purdila , Peter Jones , Scott Talbert Subject: [PATCH 4/7] efi/tpm: don't traverse an event log with no events Date: Wed, 2 Oct 2019 18:59:01 +0200 Message-Id: <20191002165904.8819-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191002165904.8819-1-ard.biesheuvel@linaro.org> References: <20191002165904.8819-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Jones 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. Fixes: c46f3405692d ("tpm: Reserve the TPM final events table") Cc: linux-efi@vger.kernel.org Cc: linux-integrity@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Peter Jones Tested-by: Lyude Paul Reviewed-by: Jarkko Sakkinen Acked-by: Matthew Garrett Acked-by: Ard Biesheuvel Signed-off-by: Jarkko Sakkinen Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/tpm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index 1d3f5ca3eaaf..b9ae5c6f9b9c 100644 --- 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));