From patchwork Wed Oct 2 16:58:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175027 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020967ill; Wed, 2 Oct 2019 10:04:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaq/pzjHD8mxJN6I6Ip3l6lwLet7/xnc8tCwdFAXNKIog60/6PIcVZEAZ2FKjdgqYNLAsC X-Received: by 2002:a17:906:3495:: with SMTP id g21mr4074835ejb.100.1570035865947; Wed, 02 Oct 2019 10:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035865; cv=none; d=google.com; s=arc-20160816; b=MOW6tLiKhjDIEVlk5JfCjdtRfX+BVobSYLzr1tnoKXkUMNe3yFxHY5/79kxkw0aOcC 5jSXxFL98CckC+5tjgeBCBseGqrMfaYzSWGKzzq8PJH5I9KB/d7PfyNLEoGmLkSBad4n fqmNJj94abuhm8NxTLP/+mC1KngX87OE7Iof0T/hBp4kVGHqi+NV6tt1C9hg3PMOh5To 671Z4oge3sJJoRFiEkfsvJbx5Qz+PDga4j1HO8XQUeS1lt8qqYwHyrNYMssIo1glgK+/ pO2NPohd12fl9FkPWHpQIrX4zx/ui9IlLsmnfqj9uWFUk6BO8rtwyZav4ta9KMdlXYpv uEag== 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=4PokOnzm+oPBOfuUNXGxhTnYV86Xe9IUth6ohOE2Moc=; b=s/DylVVvzxhacsixmtZAhM7nM81Hrq2YLsX/1bCjXZshqsw8CIESZDe3eDcKCJHrHJ yBVY1yO+MxnPvoGr4xYRz80OEiCbXZSHp4JO7ghmXe7pje4PWJXgbi04BHQHVlnqhWsh o3OD5mNE7PvIt5KZnEtTItVQz8Arw+8aHcI7z5z6OhG4j1pplRDtaoLic4kHXLqKL9rK f/vzecVHYGpBD2oBm7Cn+R8qieIYqPQAeHKbQZCmXqFHIesAyqKb/4ZrRLuSV99v4xHS +gHNpso2U1+1g337Txsj5FH+r8vBtTyde2R5oq+hIESkGDUk0v+sUDJ2Lo6ahngPKXUB on6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lbaRKl9S; 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 f30si12200293ede.435.2019.10.02.10.04.25; Wed, 02 Oct 2019 10:04:25 -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=lbaRKl9S; 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 S1728624AbfJBRDy (ORCPT + 27 others); Wed, 2 Oct 2019 13:03:54 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38453 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728049AbfJBRDw (ORCPT ); Wed, 2 Oct 2019 13:03:52 -0400 Received: by mail-wr1-f68.google.com with SMTP id w12so20534363wro.5 for ; Wed, 02 Oct 2019 10:03:51 -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=4PokOnzm+oPBOfuUNXGxhTnYV86Xe9IUth6ohOE2Moc=; b=lbaRKl9Sw32KcoJuKhy42btRwwnIf5qJkXgklbtMtdTbbKv9pfLbW8DQBaa9xY5ueH mmbRwytKylLFYjmSQZTewjfV8VsUpRx3BTL+xqyuRXVafUDmdiCQwyN3rSl8WcqN95Iz kEt0DMUYERZOm/UNlapCkAufqsyg+s2LwOVIiBtgDyHRALMfem6bQFzj6rvW6bTNTQrK chCtI4XLB6lJZAuPsb8nnelrEJPjBDa4btRcSPvvNoI6U7StdRMeAEiqS9g0cTY+LkUb vRoX7QmBpMW4QJw0JDclENNx4D1okrRBxnYuJyl2qTuwqd9bB+ET/kBayqgR2YuoLRPM AdIg== 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=4PokOnzm+oPBOfuUNXGxhTnYV86Xe9IUth6ohOE2Moc=; b=gVJzrEL+kWp4DddaAmzzdynevlHLRmFkhccysCLlmJLUMnqAMUk4f6riiig8qENv1a vU4RP9YhkrLxlvuNn4QVHO8FOxToyDEEOWO0KGrxx70xYTP5SUs7J99RUKRWahWUGh8R 2DW1yO687BV0lBZW6cF80sBNKiE7LvraJETl6aTvf491FKLcn+JHFt37TlGKBKeZ9A3/ 1VfyFwT2Au6gfrAXB0BLsw5HYrMvhYs0zerA62dloNKduw3EXuHUFco0r3YU7hC54eoF fF7oD8odbrzNS8KUM5FgV74v5nf9QjgmBafOvHsyoj70sf7CHD3CwKToAbi03CH/U4zY Vb9g== X-Gm-Message-State: APjAAAXJ1sxEhZtNNQnoznfZXWD1/wE3yDjQrglKgTYx8IFRBuAMITke 9d+AYtjegDbGGVvaCXr3Q53+ng== X-Received: by 2002:adf:ea88:: with SMTP id s8mr3787044wrm.114.1570035830342; Wed, 02 Oct 2019 10:03:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:49 -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 1/7] efi: cper: Fix endianness of PCIe class code Date: Wed, 2 Oct 2019 18:58:58 +0200 Message-Id: <20191002165904.8819-2-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: Lukas Wunner The CPER parser assumes that the class code is big endian, but at least on this edk2-derived Intel Purley platform it's little endian: efi: EFI v2.50 by EDK II BIOS ID:PLYDCRB1.86B.0119.R05.1701181843 DMI: Intel Corporation PURLEY/PURLEY, BIOS PLYDCRB1.86B.0119.R05.1701181843 01/18/2017 {1}[Hardware Error]: device_id: 0000:5d:00.0 {1}[Hardware Error]: slot: 0 {1}[Hardware Error]: secondary_bus: 0x5e {1}[Hardware Error]: vendor_id: 0x8086, device_id: 0x2030 {1}[Hardware Error]: class_code: 000406 ^^^^^^ (should be 060400) Signed-off-by: Lukas Wunner Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/cper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index addf0749dd8b..b1af0de2e100 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -381,7 +381,7 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie, printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx, pcie->device_id.vendor_id, pcie->device_id.device_id); p = pcie->device_id.class_code; - printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]); + printk("%s""class_code: %02x%02x%02x\n", pfx, p[2], p[1], p[0]); } if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER) printk("%s""serial number: 0x%04x, 0x%04x\n", pfx, From patchwork Wed Oct 2 16:58:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175021 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020344ill; Wed, 2 Oct 2019 10:03:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw03f1tXdP5oGkv8Ym+IaG3QTPYKGhc27w92wNqsmvNVfvYdyFtFMhcAZ8Z2KgU28mWBbBa X-Received: by 2002:a17:906:4801:: with SMTP id w1mr3929614ejq.245.1570035836394; Wed, 02 Oct 2019 10:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035836; cv=none; d=google.com; s=arc-20160816; b=KjhqggV4QbQPYOpqPoR7KmUzdeMQ4ZPpf/rdycciSWgwuxHiSDPmaq8ldkRFRQvYhO Dt4tr1e698/KNzmQUN4r09E6jvuvpA1CQ7KXVjEpwGkJaGiYRBXcMpkgMVjxoAu79Wjf qp1vKy4sQx82SINvAzFCT6LUd/k1Czux2TY2gcQzKTTeM+KLGJFgTgDL1C4D1SbKRMP0 QA3CPge5rcJZrhKVMYEAl6tZ0/pS/ru6SSejkbc57jD4LUSIIwdeJ+Ncmqb3yJvjjITM ViGRaJYw2UB3fHEjrMSryHJDP/I/HSL4/1N3oU6CG07vRKh/4Vsmv8hlGdXeVGRO8KrP V7kg== 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=TNYLGJx+lu9+SgPr9a/2JABv2HQmtSq9Qr99wIga2I8=; b=fVr4JrL2aocdx6M2an7egUi8chl7MzaKYkMkcXnm6tvwotCAZr1Jxv/EdEuhjnGLDY cFJblbP6MFZ5lxBED1ka90B4/cLbqICF7sz2mhrh5EGZb5tKotg9j9YMtxp/t+NVq1Q8 BXY88zo0ea+lw3GLWJhF3uQ6Q8UVsasiXrJZpWU6HatqLKIO6mmXoNKvasVVgQGq3hOe 7VGvVTHUeo/OdrIBgZCEwyHh4qNaQRaaqXYU711LiaryZWES62reZ5GSdWAR/EMXxD8a YTaN8ze010qNl1pR/WwgSZWSNlj/tbxIZHGBCJbqMoUdJ+HCT272jJxWhjisKRveKasq 6Uow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rNrSpN2f; 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.03.56; Wed, 02 Oct 2019 10:03:56 -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=rNrSpN2f; 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 S1728685AbfJBRDz (ORCPT + 27 others); Wed, 2 Oct 2019 13:03:55 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38458 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728484AbfJBRDy (ORCPT ); Wed, 2 Oct 2019 13:03:54 -0400 Received: by mail-wr1-f68.google.com with SMTP id w12so20534468wro.5 for ; Wed, 02 Oct 2019 10:03:52 -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=TNYLGJx+lu9+SgPr9a/2JABv2HQmtSq9Qr99wIga2I8=; b=rNrSpN2fIml21+JUO1szkLdGWyZora2ylQ6bw5F7f6ogf4DamBuc3Xq6GoKoTawH+G 8Gn9nGylOrnQYYzu0IiorMdMNunHOEvIi7ZKh49gsQV9PUWdjCMMuxAd6zHDKao+Uu4X 7npGmKdct0a0u8DCW7XocS5rpPhBi6hf6U5yZinYSbdal+++tjG2N9sLY9R9DtuMUEfr kjrazD0vJy1kDoTR3HufHNQLJ1J75VZU+KgunYObAvCkFJhzK18MT5ZH6Jp1dQ3SmXQ2 +h8Mk4lFiAfMuMOu1URy375g2NLitC7Ymi2hmW027ZxoaBL3BZ4NcRkOxNMkhfR3z6EQ cWuQ== 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=TNYLGJx+lu9+SgPr9a/2JABv2HQmtSq9Qr99wIga2I8=; b=JOBlRtK3djil2CrS96MqvC3bW2Ipncg/xgpYthoVfv60MwFekYvgllnUNVgpCvJo6u MI0KNShs5M+iGfrH+H/x5uoP15RDaUTsjdGFDaIsRVd543DVn1K/M57LpuiFFnJEhyiA r1u7fHg1ffSckfd8orYyxQKK8kEk9Xl570ZVhB2oDP8zJgm1rNxtlSEl5x6yP/FbSfEn zrqrk2/xk2a6KlsvfuiEb4Vd+Nn6oscX8Xj+AgvFLNqOEJG5EsCIB0H6O1UAxYvgP3kE LZLQoQ/o/frrk9q0K2+maWtG8P6tpNNVdqX4pfD/3o4i7/TLtWr0K3TGBQmeFzbG8E7s bw0Q== X-Gm-Message-State: APjAAAX7NMgQV0GxX33uPlW8OyiiFG4IrO7Ri4ixsxsdc0Id6gHVrj5L ZDeWNd0Kjmq/yk6HKJZH5yHJUA== X-Received: by 2002:a5d:4a01:: with SMTP id m1mr3517743wrq.343.1570035831778; Wed, 02 Oct 2019 10:03:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:51 -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 2/7] efivar/ssdt: don't iterate over EFI vars if no SSDT override was specified Date: Wed, 2 Oct 2019 18:58:59 +0200 Message-Id: <20191002165904.8819-3-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 The kernel command line option efivar_ssdt= allows the name to be specified of an EFI variable containing an ACPI SSDT table that should be loaded into memory by the OS, and treated as if it was provided by the firmware. Currently, that code will always iterate over the EFI variables and compare each name with the provided name, even if the command line option wasn't set to begin with. So bail early when no variable name was provided. This works around a boot regression on the 2012 Mac Pro, as reported by Scott. Fixes: 475fb4e8b2f4 ("efi / ACPI: load SSTDs from EFI variables") Cc: # v4.9+ Cc: Octavian Purdila Tested-by: Scott Talbert Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.20.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 8d3e778e988b..69f00f7453a3 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -267,6 +267,9 @@ static __init int efivar_ssdt_load(void) void *data; int ret; + if (!efivar_ssdt[0]) + return 0; + ret = efivar_init(efivar_ssdt_iter, &entries, true, &entries); list_for_each_entry_safe(entry, aux, &entries, list) { From patchwork Wed Oct 2 16:59:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175026 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020873ill; Wed, 2 Oct 2019 10:04:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvMlAirE4AgaBpQ4m6Do2dref53qve978nvQaKfbfrEgRkxK79RAKg7Uwqcns/gaOcICx3 X-Received: by 2002:a17:906:a44e:: with SMTP id cb14mr3953942ejb.277.1570035861301; Wed, 02 Oct 2019 10:04:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035861; cv=none; d=google.com; s=arc-20160816; b=tCoZdNEkxHuqcuJCCIPOUxjHHh5zwZ4SATrfu+SiKeY4zhieo13Cmc5tdgMTSZ/X47 xwFu73Mi4ppxTzhzk3OrpXmKiCU1F+C/UF8IJ+GSnoTh4/cMc1a07Db+APSUqevvVrDI LtiuHz5emPh2/HktiaLIwZ5Ykofd3f2X/Ws/M28pxIrrjvLNY5BTF5Sd4dUT65ecSDTa 8v1CcZ/HEtZB4PdLYpnOsLUkvNHAJK+FK11e9BexVTYWwBhub6tLlrjowwgdCHalFiPO 0v1yL5Ff0IHx7FKrlHxkDqnUxy+l9XiGAc2cf1Py+TsimRrAGZS6KOilDF5lWamb73iQ clVg== 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=I5173HAo8p1LhYV3fg4+aqN0iEH53Ly0slEkdev9Cjg=; b=ucFvJBSupQAQyCxh9r/UgTfWz0j6AiImatVOrtgTjFpdLRu2Fthkx1/tNbR2g35woC jg/IQs5tcMPdQQrVwxZoNC3owp5cV3y1cFNWDAbO4ZjDmcciEPEnVrLvQ3d85f6UfIv5 lAT0QL8VR4lWTljYbj5joHG/s4xYJ6uvSX1ApyTV7kH3ceteXPBBWh/lavOKzELv+7GC TMF9yaoHrWvpxlb9+4dYt6tGuZENmUyLo32BJGKsRcTHDuzxDeH1K9QerDujMTSHlpkd C1vq4XaQKqjOgSEUlZTypFyiZbLD4UtZFr3wgyYUbZT7FoeR/sxYAXM5nOZNVgz3o8yf ROkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ff5iuJGq; 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 e5si11115899ejj.70.2019.10.02.10.04.20; Wed, 02 Oct 2019 10:04:21 -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=ff5iuJGq; 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 S1728889AbfJBRET (ORCPT + 27 others); Wed, 2 Oct 2019 13:04:19 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35637 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728612AbfJBRDz (ORCPT ); Wed, 2 Oct 2019 13:03:55 -0400 Received: by mail-wm1-f66.google.com with SMTP id y21so7752390wmi.0 for ; Wed, 02 Oct 2019 10:03:53 -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=I5173HAo8p1LhYV3fg4+aqN0iEH53Ly0slEkdev9Cjg=; b=ff5iuJGqQwK7W8NVggxafmcrET7AQ8KvAtXc439Vhn0YvaoKt3O9eY1Fwk4QhOXb3y b/+lntD2LNGbaNUSQGbZ+9adA2U/h6YUtnqyL3Wl1f5WwwwxSKvZajfn+d+vk6El/F1D B72GlPDKrkfRtJiSH3sKLpJtSzqtM+LOfa8qHZh0wjRAV4UM46VEOVYyBsci5IgRA46a CzstOvEmTXTz8s1hYmNAg+q72lzi62qJjkXoFM59AOpPKif5nn+FfDTXkLuD4e/SzQeA bC19QNkNg3SKzzusUKZwIEu+ws0mJh5XGPzVbDj62+Tb/FrNrgvRLxEVFF7gSUJBuZ1c cX+A== 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=I5173HAo8p1LhYV3fg4+aqN0iEH53Ly0slEkdev9Cjg=; b=SRPyubbfg4seVEStQNa3U6I6qfLID5ivopvEv1dTcmNB+5zKV/9cR/hmDCsOf3+JlF B+QPnMdlubZ5SbyXJzR9LB7f5b2Kdr+WYUb0UWm03xIfFUN5q0kxWeKOwQbqA1uemTk9 4WboumWqABc766iKsnO8D9DM6ZCNaB5MwFKUAbAHMgNmQhjiLvgT5WdGdSsRxy5zTRhU ePdE7eDLEIgiLJPoQ2Bg3eBi5rgcIjMa+h8VRdtd8vZ+pAoiwbWSWWO2xrTZcy2A5yfw 10eBQZqCr7oIrLaDVrjx+GCZaOM4m2Pblpaf7lHckSR2qhd8a2TmeKvOAbFt0GWPgqeK 7Tgg== X-Gm-Message-State: APjAAAUeQgRJlcZBv3Kdq+SS6KbSRevLctjC5XjLR9DnMZLxqIWJfOm3 KyQE/PrK5xYkzXP0yfrFWJ0vVQ== X-Received: by 2002:a1c:3bd6:: with SMTP id i205mr3561886wma.135.1570035833039; Wed, 02 Oct 2019 10:03:53 -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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:52 -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 3/7] efi/tpm: Don't access event->count when it isn't mapped. Date: Wed, 2 Oct 2019 18:59:00 +0200 Message-Id: <20191002165904.8819-4-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 Some machines generate a lot of event log entries. When we're iterating over them, the code removes the old mapping and adds a new one, so once we cross the page boundary we're unmapping the page with the count on it. Hilarity ensues. This patch keeps the info from the header in local variables so we don't need to access that page again or keep track of if it's mapped. Fixes: 44038bc514a2 ("tpm: Abstract crypto agile event size calculations") 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 --- include/linux/tpm_eventlog.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 63238c84dc0b..12584b69a3f3 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, u16 halg; int i; int j; + u32 count, event_type; marker = event; marker_start = marker; @@ -190,16 +191,22 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, } event = (struct tcg_pcr_event2_head *)mapping; + /* + * the loop below will unmap these fields if the log is larger than + * one page, so save them here for reference. + */ + count = READ_ONCE(event->count); + event_type = READ_ONCE(event->event_type); efispecid = (struct tcg_efi_specid_event_head *)event_header->event; /* Check if event is malformed. */ - if (event->count > efispecid->num_algs) { + if (count > efispecid->num_algs) { size = 0; goto out; } - for (i = 0; i < event->count; i++) { + for (i = 0; i < count; i++) { halg_size = sizeof(event->digests[i].alg_id); /* Map the digest's algorithm identifier */ @@ -256,8 +263,9 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, + event_field->event_size; size = marker - marker_start; - if ((event->event_type == 0) && (event_field->event_size == 0)) + if (event_type == 0 && event_field->event_size == 0) size = 0; + out: if (do_mapping) TPM_MEMUNMAP(mapping, mapping_size); 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)); From patchwork Wed Oct 2 16:59:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175025 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020750ill; Wed, 2 Oct 2019 10:04:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMMtX+3psgkTnqToYRbX3HRK67Txas8lPV+DVcHzhKrIrifwPSUu8/QJonAX48oZZ9kqDC X-Received: by 2002:a17:906:7687:: with SMTP id o7mr3984345ejm.213.1570035856038; Wed, 02 Oct 2019 10:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035856; cv=none; d=google.com; s=arc-20160816; b=TB5qxR5Ht41uPQ0DstUcuXNfxUu/ayvnP3xEDbcL9cRRADc47i3Odwfjgpl2YEta4i bq4tQ93i7nebDr7tSRJonPRB09lP5WLCR9b9Gs7LxzY9mXA0IWYA+lON1bwM8aTj+vuf i6zjUgz/5ir9eCFFMCLdb8U0iBW0ZFrfrQd+gm/cENcLn5q09jxyB446JZe60ObZ4p96 Hs+8QRKZcpdUVhgZxkGsfqz+XIs/A8iW0TP7B6sMGzqPYYy/azPG+59SQe2UVhQo2U2i qj7xWSY+JcqoA3UZgkCmtTFv0iB4bbAjLll07cD0uN8GUsHGWgOXDkD6LaxAjRZk6Btl r+lw== 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=WvNNDWNhX2Fb3QLVftkYDMZhyGKIzxVRGVz9KnZzIlA=; b=O5DwJ+jk6hIz9HJZVpq+FNFPswCbTxZ9GzRnP5P+Qi3c07IyIv7L+Q3I7fKV+s7r65 YshKL3VwkohNPz2K06D+f8eBmpltm/1M8MOEdCFTSwrdh1YbDq53hikPxLJAU64rCLX/ l+jaURP1ij6Nnyu1qNatHkPbLMTqnsVBqyXsmrtN8ksxBNzbXPYB8OFLfnOB0pNjRLsw CKpLGMFcca4ShERC7JrWJJ6QLxVErfnfDYosk3+FjuXGbfi2jEtWH9ug+esezPH5m0Gg gLfO1vBbxgLi/7FZf7A4Pt9/81mLvj0cefh2/T2uz1vvJiDQDshxiYbr5f4yuuOzONE6 DIMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGQ3gNIg; 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 u14si11443585edq.167.2019.10.02.10.04.15; Wed, 02 Oct 2019 10:04:16 -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=HGQ3gNIg; 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 S1728873AbfJBREP (ORCPT + 27 others); Wed, 2 Oct 2019 13:04:15 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35599 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728693AbfJBRD5 (ORCPT ); Wed, 2 Oct 2019 13:03:57 -0400 Received: by mail-wr1-f66.google.com with SMTP id v8so20560123wrt.2 for ; Wed, 02 Oct 2019 10:03:56 -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=WvNNDWNhX2Fb3QLVftkYDMZhyGKIzxVRGVz9KnZzIlA=; b=HGQ3gNIggfEXj7AYkwnJT9Qjz0IwaBjNifqvg2AUMkYBpkURvXrJ3mFFLx8YmRM01s MQFAu94mNsU0c82mxdT74zHcr8NAMDdqG/CQgoyxhTzvckbEFrY8NEfFHOxXy2DBxiIL kAVVbEoN5qr+o+totHIOgapck7eivCrc047FPvxseQattsch16J4/BhPLidznQjuCZQ2 BaSOlYPJ3RSY0Ld4a15n0DWzM7NP4SgsUIp/U4lobd0ucRCYxUu+oLRYZwofmZYXR+b9 j2G1/EkIlxdKPW9ZKbQEPAt369KCTEIqTm0hb3O7o8te55yL4yFi4c+TeWxwznbJtmLM TFJg== 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=WvNNDWNhX2Fb3QLVftkYDMZhyGKIzxVRGVz9KnZzIlA=; b=j5I7T9oVQhvw3O7jgqdMW81Gy097DRINSTJWWM4aebmjahBg+xRo6khxTc5mws4mBk yP0rk9v8LYM7DIWdh8BMMTTVBzqf/1Na4lsQLfsXzhx9ntnNYwgXkkwUWtPI3SWONT+D oYSS+0h8nJyr6JMX5YqrIAPKdmepOxXZjIp+C5fq8hBKmzJaCgYZ+n0iqf7VbETVl0qu 2MnSMtslFsRJhd5+nACqctCaHarUfy8D6DqaSVfsJR6KpShq1UUtRebpnzQDhyg3+WK4 vcke4oL1g0rQBlkO2wRwf50Gk2tyeKzEkSfpKzRB13r8eogHNu77HsmOEtNeRhyCBqST A0UQ== X-Gm-Message-State: APjAAAXa09YaRzgZcGMYtUYKfoVy6XsTyLhJOS4T6rgTQokUYmmv+pic nfoJVepAa3TW/2zUWic4t5QipQ== X-Received: by 2002:a5d:490f:: with SMTP id x15mr3410913wrq.375.1570035835970; Wed, 02 Oct 2019 10:03:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:55 -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 5/7] efi/tpm: only set efi_tpm_final_log_size after successful event log parsing Date: Wed, 2 Oct 2019 18:59:02 +0200 Message-Id: <20191002165904.8819-6-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: Jerry Snitselaar If __calc_tpm2_event_size fails to parse an event it will return 0, resulting tpm2_calc_event_log_size returning -1. Currently there is no check of this return value, and efi_tpm_final_log_size can end up being set to this negative value resulting in a panic like the the one given below. Also __calc_tpm2_event_size returns a size of 0 when it fails to parse an event, so update function documentation to reflect this. [ 0.774340] BUG: unable to handle page fault for address: ffffbc8fc00866ad [ 0.774788] #PF: supervisor read access in kernel mode [ 0.774788] #PF: error_code(0x0000) - not-present page [ 0.774788] PGD 107d36067 P4D 107d36067 PUD 107d37067 PMD 107d38067 PTE 0 [ 0.774788] Oops: 0000 [#1] SMP PTI [ 0.774788] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.3.0-0.rc2.1.elrdy.x86_64 #1 [ 0.774788] Hardware name: LENOVO 20HGS22D0W/20HGS22D0W, BIOS N1WET51W (1.30 ) 09/14/2018 [ 0.774788] RIP: 0010:memcpy_erms+0x6/0x10 [ 0.774788] Code: 90 90 90 90 eb 1e 0f 1f 00 48 89 f8 48 89 d1 48 c1 e9 03 83 e2 07 f3 48 a5 89 d1 f3 a4 c3 66 0f 1f 44 00 00 48 89 f8 48 89 d1 a4 c3 0f 1f 80 00 00 00 00 48 89 f8 48 83 fa 20 72 7e 40 38 fe [ 0.774788] RSP: 0000:ffffbc8fc0073b30 EFLAGS: 00010286 [ 0.774788] RAX: ffff9b1fc7c5b367 RBX: ffff9b1fc8390000 RCX: ffffffffffffe962 [ 0.774788] RDX: ffffffffffffe962 RSI: ffffbc8fc00866ad RDI: ffff9b1fc7c5b367 [ 0.774788] RBP: ffff9b1c10ca7018 R08: ffffbc8fc0085fff R09: 8000000000000063 [ 0.774788] R10: 0000000000001000 R11: 000fffffffe00000 R12: 0000000000003367 [ 0.774788] R13: ffff9b1fcc47c010 R14: ffffbc8fc0085000 R15: 0000000000000002 [ 0.774788] FS: 0000000000000000(0000) GS:ffff9b1fce200000(0000) knlGS:0000000000000000 [ 0.774788] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.774788] CR2: ffffbc8fc00866ad CR3: 000000029f60a001 CR4: 00000000003606f0 [ 0.774788] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 0.774788] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 0.774788] Call Trace: [ 0.774788] tpm_read_log_efi+0x156/0x1a0 [ 0.774788] tpm_bios_log_setup+0xc8/0x190 [ 0.774788] tpm_chip_register+0x50/0x1c0 [ 0.774788] tpm_tis_core_init.cold.9+0x28c/0x466 [ 0.774788] tpm_tis_plat_probe+0xcc/0xea [ 0.774788] platform_drv_probe+0x35/0x80 [ 0.774788] really_probe+0xef/0x390 [ 0.774788] driver_probe_device+0xb4/0x100 [ 0.774788] device_driver_attach+0x4f/0x60 [ 0.774788] __driver_attach+0x86/0x140 [ 0.774788] ? device_driver_attach+0x60/0x60 [ 0.774788] bus_for_each_dev+0x76/0xc0 [ 0.774788] ? klist_add_tail+0x3b/0x70 [ 0.774788] bus_add_driver+0x14a/0x1e0 [ 0.774788] ? tpm_init+0xea/0xea [ 0.774788] ? do_early_param+0x8e/0x8e [ 0.774788] driver_register+0x6b/0xb0 [ 0.774788] ? tpm_init+0xea/0xea [ 0.774788] init_tis+0x86/0xd8 [ 0.774788] ? do_early_param+0x8e/0x8e [ 0.774788] ? driver_register+0x94/0xb0 [ 0.774788] do_one_initcall+0x46/0x1e4 [ 0.774788] ? do_early_param+0x8e/0x8e [ 0.774788] kernel_init_freeable+0x199/0x242 [ 0.774788] ? rest_init+0xaa/0xaa [ 0.774788] kernel_init+0xa/0x106 [ 0.774788] ret_from_fork+0x35/0x40 [ 0.774788] Modules linked in: [ 0.774788] CR2: ffffbc8fc00866ad [ 0.774788] ---[ end trace 42930799f8d6eaea ]--- [ 0.774788] RIP: 0010:memcpy_erms+0x6/0x10 [ 0.774788] Code: 90 90 90 90 eb 1e 0f 1f 00 48 89 f8 48 89 d1 48 c1 e9 03 83 e2 07 f3 48 a5 89 d1 f3 a4 c3 66 0f 1f 44 00 00 48 89 f8 48 89 d1 a4 c3 0f 1f 80 00 00 00 00 48 89 f8 48 83 fa 20 72 7e 40 38 fe [ 0.774788] RSP: 0000:ffffbc8fc0073b30 EFLAGS: 00010286 [ 0.774788] RAX: ffff9b1fc7c5b367 RBX: ffff9b1fc8390000 RCX: ffffffffffffe962 [ 0.774788] RDX: ffffffffffffe962 RSI: ffffbc8fc00866ad RDI: ffff9b1fc7c5b367 [ 0.774788] RBP: ffff9b1c10ca7018 R08: ffffbc8fc0085fff R09: 8000000000000063 [ 0.774788] R10: 0000000000001000 R11: 000fffffffe00000 R12: 0000000000003367 [ 0.774788] R13: ffff9b1fcc47c010 R14: ffffbc8fc0085000 R15: 0000000000000002 [ 0.774788] FS: 0000000000000000(0000) GS:ffff9b1fce200000(0000) knlGS:0000000000000000 [ 0.774788] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.774788] CR2: ffffbc8fc00866ad CR3: 000000029f60a001 CR4: 00000000003606f0 [ 0.774788] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 0.774788] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 0.774788] Kernel panic - not syncing: Fatal exception [ 0.774788] Kernel Offset: 0x1d000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) [ 0.774788] ---[ end Kernel panic - not syncing: Fatal exception ]--- The root cause of the issue that caused the failure of event parsing in this case is resolved by Peter Jone's patchset dealing with large event logs where crossing over a page boundary causes the page with the event count to be unmapped. Fixes: c46f3405692de ("tpm: Reserve the TPM final events table") Cc: linux-efi@vger.kernel.org Cc: linux-integrity@vger.kernel.org Cc: stable@vger.kernel.org Cc: Matthew Garrett Cc: Ard Biesheuvel Cc: Jarkko Sakkinen Signed-off-by: Jerry Snitselaar Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/tpm.c | 9 ++++++++- include/linux/tpm_eventlog.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index b9ae5c6f9b9c..703469c1ab8e 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -85,11 +85,18 @@ int __init efi_tpm_eventlog_init(void) final_tbl->nr_events, log_tbl->log); } + + if (tbl_size < 0) { + pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n"); + goto out_calc; + } + memblock_reserve((unsigned long)final_tbl, tbl_size + sizeof(*final_tbl)); - early_memunmap(final_tbl, sizeof(*final_tbl)); efi_tpm_final_log_size = tbl_size; +out_calc: + early_memunmap(final_tbl, sizeof(*final_tbl)); out: early_memunmap(log_tbl, sizeof(*log_tbl)); return ret; diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 12584b69a3f3..2dfdd63ac034 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -152,7 +152,7 @@ struct tcg_algorithm_info { * total. Once we've done this we know the offset of the data length field, * and can calculate the total size of the event. * - * Return: size of the event on success, <0 on failure + * Return: size of the event on success, 0 on failure */ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, From patchwork Wed Oct 2 16:59:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175023 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1020603ill; Wed, 2 Oct 2019 10:04:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxte0p+/ao54RD0WhKY1+GLn6PYwI3YK1XNkR1vkHgkVqK+iYj+NSasfBJBaXxyEaaaD5Y0 X-Received: by 2002:a50:cc4d:: with SMTP id n13mr4940358edi.5.1570035848253; Wed, 02 Oct 2019 10:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570035848; cv=none; d=google.com; s=arc-20160816; b=elaGYiIwLNvpMYohbA3aQxaU8vik3bRDBv/Zyk5Xwk8ynCxRoW099zIhNzEajZjle9 8dSyoGCi+UpkHlAkBFq4UbukpR4A357fZnTsxAR0n7DpQCIAq5JB0M59ZKYZknsiCyi8 dUb7wuahI2OjkWdx3SZDysvrAMb7AIiAbmXONVokea4s2/n+8E5zMbyVnMaLW4RY2//o nA3P96peEp3O+Tx1itdcq9IDkPdHLQwp2Uc61UrzoWaPThi2OKjMtpe0SSlY6ZP/B8hj PfzCrcE8ouqbImd6yUe4nr2tNdvXTMaeaxqURtHJPj1V7GiXEEaoad2jnEKe70ADKNGX 677Q== 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=ba3w9kcbGuMtfRQk+/aw/wvXJx7RCk+NpcTgMqWmzhU=; b=mARNodg3arCgUiR9jlOPo3Z9oT4DDQSbCR27f75tCiP2nA9J0c1zv6wqO/p8D18EHU 0yzRYgu8bvMcLdw2nWXVg6KARByFxyV+WRTEspnoxs2YelqVhupzk8dR1koajy5kXyYt D91XGfwibqt3rpkGVwaqQzqC1xvFQK4iBOKpP7OAEyBPiC3jJBVohkSELJi8SUq9u2pp JLEiB7twRrsbyIPxLhfMZR0K97oFa+T0D1ouKEnYrWPf3SkWtzAtL4tt8kbEDDLpxg4s 4Rd21NF3sTwS+4Ymd6Awwk7XbKBB7J8aSI7xAe9ZbbHrxWZ0Ni8v77uplky7gr2LS5ow Ao7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wzK2Kr+8; 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 u14si11443585edq.167.2019.10.02.10.04.07; Wed, 02 Oct 2019 10:04:08 -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=wzK2Kr+8; 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 S1728844AbfJBREG (ORCPT + 27 others); Wed, 2 Oct 2019 13:04:06 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55595 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728790AbfJBREB (ORCPT ); Wed, 2 Oct 2019 13:04:01 -0400 Received: by mail-wm1-f67.google.com with SMTP id a6so7977181wma.5 for ; Wed, 02 Oct 2019 10:03:59 -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=ba3w9kcbGuMtfRQk+/aw/wvXJx7RCk+NpcTgMqWmzhU=; b=wzK2Kr+8eqFEvQyxP/6nAjwnHPAGzZ8Pr5KF1g4HtEl208yl3hYOPNrU07OMhhzVWi MJKwplxNEH4QgfCZUR4dvDzREYAmCwTg8QcRqVIc+N86yPlchCpdJwH64aDYPis9zk8m TdMyTqaPHvXe6DL+R17NO7Ew8ajZCG6HeEYnB+26TI7BCFOg37ZX69Ifm9cCZnNvptFv dh27JTl0lOOYsJXWAQYHiDsnQ/ysVdZ3EghjNhZgsmHbWK3V+X6gAGNnlR3zit/Lp1L8 mebYi0KthRj672fvFN5LuLKZYDX6z4czZY0Slv+AbT5SR4PFSvdKM/FhltbeInqz6vfK msew== 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=ba3w9kcbGuMtfRQk+/aw/wvXJx7RCk+NpcTgMqWmzhU=; b=TkoK0m4/NqkZmEAsLVIwvvNEpnkVlMGflKpcOuTQ1LRcdCqhZ0JQJpMvpTYVWgxObh O7zhWbqkZFwK9Ny3Gw4X+ZDyXnKZFpdllhw29N3TnrfprdSDCc6wxISgkSXdvOOa5Ryh n0GGrfFkGV1+Cl2lEjahBy71+lXQ6zUreO8uw9qH64pen8zOjAnoBiPcA11Y2rHfMt8p DdsNavTho8baoX46x6JStmwn1jjPUjObmo11kKZ22SBCUsPAQlOM0voaPPUClkKyZ0af JZRU9hBlnLzAwsq+K2MbSTByr6RqAKGofbRx62scEL6hIBn/ly1pRNJV4j1NkO8apKjT VgBA== X-Gm-Message-State: APjAAAUhPzrpHY29rv7vm9fhBbOq9ub94nE6d8malalV6zfHq7VWSOHn JLhQzIUBMzz4aGuJcs+vv4WCFw== X-Received: by 2002:a05:600c:2115:: with SMTP id u21mr3610780wml.168.1570035839244; Wed, 02 Oct 2019 10:03:59 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 10:03:58 -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 7/7] efi/x86: do not clean dummy variable in kexec path Date: Wed, 2 Oct 2019 18:59:04 +0200 Message-Id: <20191002165904.8819-8-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: Dave Young kexec reboot fails randomly in UEFI based kvm guest. The firmware just reset while calling efi_delete_dummy_variable(); Unfortunately I don't know how to debug the firmware, it is also possible a potential problem on real hardware as well although nobody reproduced it. The intention of efi_delete_dummy_variable is to trigger garbage collection when entering virtual mode. But SetVirtualAddressMap can only run once for each physical reboot, thus kexec_enter_virtual_mode is not necessarily a good place to clean dummy object. Drop efi_delete_dummy_variable so that kexec reboot can work. Signed-off-by: Dave Young Acked-by: Matthew Garrett Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 3 --- 1 file changed, 3 deletions(-) -- 2.20.1 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index c202e1b07e29..425e025341db 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -917,9 +917,6 @@ static void __init kexec_enter_virtual_mode(void) if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) runtime_code_page_mkexec(); - - /* clean DUMMY object */ - efi_delete_dummy_variable(); #endif }