Received: by 10.223.185.116 with SMTP id b49csp6026031wrg; Thu, 8 Mar 2018 00:06:55 -0800 (PST) X-Google-Smtp-Source: AG47ELs7Is8uA7n1YIcNAni+XeLDYvrPLkG7zun9Cilpv3j8kiFhn3urwQlvRelSM+BFpYbBdaVh X-Received: by 2002:a17:902:b904:: with SMTP id bf4-v6mr22839024plb.195.1520496415761; Thu, 08 Mar 2018 00:06:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496415; cv=none; d=google.com; s=arc-20160816; b=pCXKQK+oKFqqFyDY28qG4v9sqij6Lw2/6gMh3lDIZybbuQE4n+2xu/j/zneWzacrRO QQ6y6z9uHCSefw3i8gkWHkuTgx+okZ85tPWzQXROzkopplgOeAUYrg7d3xbpx52MDhK4 1kRmajQIVwZjzStSwGBkwNoMZ50EuHEZD0K5/XO+zATp6gYDxaaNZVdAJP0CUQw/iwGK 9ppFy70rCgkS6TybtxiZ4eUTQMcyzyOLx/+mQsrQo8al/nAglfCnO2MmIUP2NNnMtU+3 Bd6d/2M+3ZZP6DeUNNsONk/UEfih8lMgoUa3aO2cLsqJvGeLCvwdw1kV9ILPsSe5zjfA s96w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=UTuDxQkBXmMMOkquvbph9w1W2XXzx2CFnI3LSvE+I2W9c0Ym2OEjc6IkWfYP72so/R iDkuEIsIPWekfSHZmvOWumX71oB07/ULtnAccwRC0p4WssaDYiwd9mjkYp0Srmz+PEhX Ai9UjqE8ewyQqFaLbjBD+TW1TK3rs9H1jAdf+iiDYI+ng52RJ8l/VR3+pOeovY2S1b/+ ej9m6yraCQiE0qK6VYT2GKlCKpyM1Ug6URrPcxEwDZFQnDsosdfosdMqijm5gvyuOUPB p5WKeGMmXv7jUv1yWANWbP0hQI8CEbntCvO+6tt8aQbteVhL1wfaLaGcsQwwxz4igQsO /NdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W//rEZfl; 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 z2si11467258pgo.720.2018.03.08.00.06.41; Thu, 08 Mar 2018 00:06:55 -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; dkim=pass header.i=@linaro.org header.s=google header.b=W//rEZfl; 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 S964971AbeCHIB6 (ORCPT + 99 others); Thu, 8 Mar 2018 03:01:58 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36225 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935358AbeCHIBx (ORCPT ); Thu, 8 Mar 2018 03:01:53 -0500 Received: by mail-wm0-f68.google.com with SMTP id 188so9277034wme.1 for ; Thu, 08 Mar 2018 00:01:53 -0800 (PST) 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; bh=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=W//rEZflJewEIGqYimBGW4YEyvXzAlHPpIx7VN86+ZlSs+6be/mlz6enk3JfdlGWrh SI6v+/Cfao5ASnrJveEQ3/70cNvbrJ8eqIynSr6iFhkOKBFSXHZ20vyYsfMpb/IRbjw7 eRnbDVTRpJvliNwXBgngDDAwlgrVICvjP01jI= 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; bh=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=pZFQVN4cM/eX1ROrLSEUVq0Q6z+OVBZjJCWmZxj+17zetBa1PxeUK5gzijrTl339SU WanxqVT1Bx8PboX3SxGT3BTDljXsQt2W1DWZ4ijajidf4/oa5lH1jKeEKg/89XiHiCol nzn1xB89Wmvwe/u81nggiuuf77I6/cLn+obFpsmFn2MtVRzCb3ZQrvQapNDDJAqhuvkW 3yrwUS6e2e0GDnc/tayYbmc7LR0B1OrHr3cSG43A7gO5R5u8k3EHfn6qL/mYPjbKU/p7 CSroH0bkKr0dJRN6OYMzt762NY8u0BnT6JiI0sIU8yHdglRO2LNO46qfi65YIZYvVgF/ o8dw== X-Gm-Message-State: AElRT7EokUxrIuAQDgN3WYvpM/SDZeoiUWAzxlQcZwplyTSYC3GLm8aG KPEVuWT9MS6x45UKrAZiFGs03Q== X-Received: by 10.28.20.74 with SMTP id 71mr15315608wmu.71.1520496112526; Thu, 08 Mar 2018 00:01:52 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.01.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:01:51 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Mark Rutland , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] efi/arm*: Only register page tables when they exist Date: Thu, 8 Mar 2018 08:00:09 +0000 Message-Id: <20180308080020.22828-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland Currently the arm/arm64 runtime code registers the runtime servies pagetables with ptdump regardless of whether runtime services page tables have been created. As efi_mm.pgd is NULL in these cases, attempting to dump the efi page tables results in a NULL pointer dereference in the ptdump code: /sys/kernel/debug# cat efi_page_tables [ 479.522600] Unable to handle kernel NULL pointer dereference at virtual address 00000000 [ 479.522715] Mem abort info: [ 479.522764] ESR = 0x96000006 [ 479.522850] Exception class = DABT (current EL), IL = 32 bits [ 479.522899] SET = 0, FnV = 0 [ 479.522937] EA = 0, S1PTW = 0 [ 479.528200] Data abort info: [ 479.528230] ISV = 0, ISS = 0x00000006 [ 479.528317] CM = 0, WnR = 0 [ 479.528317] user pgtable: 4k pages, 48-bit VAs, pgd = 0000000064ab0cb0 [ 479.528449] [0000000000000000] *pgd=00000000fbbe4003, *pud=00000000fb66e003, *pmd=0000000000000000 [ 479.528600] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 479.528664] Modules linked in: [ 479.528699] CPU: 0 PID: 2457 Comm: cat Not tainted 4.15.0-rc3-00065-g2ad2ee7ecb5c-dirty #7 [ 479.528799] Hardware name: FVP Base (DT) [ 479.528899] pstate: 00400009 (nzcv daif +PAN -UAO) [ 479.528941] pc : walk_pgd.isra.1+0x20/0x1d0 [ 479.529011] lr : ptdump_walk_pgd+0x30/0x50 [ 479.529105] sp : ffff00000bf4bc20 [ 479.529185] x29: ffff00000bf4bc20 x28: 0000ffff9d22e000 [ 479.529271] x27: 0000000000020000 x26: ffff80007b4c63c0 [ 479.529358] x25: 00000000014000c0 x24: ffff80007c098900 [ 479.529445] x23: ffff00000bf4beb8 x22: 0000000000000000 [ 479.529532] x21: ffff00000bf4bd70 x20: 0000000000000001 [ 479.529618] x19: ffff00000bf4bcb0 x18: 0000000000000000 [ 479.529760] x17: 000000000041a1c8 x16: ffff0000082139d8 [ 479.529800] x15: 0000ffff9d3c6030 x14: 0000ffff9d2527f4 [ 479.529924] x13: 00000000000003f3 x12: 0000000000000038 [ 479.530000] x11: 0000000000000003 x10: 0101010101010101 [ 479.530099] x9 : 0000000017e94050 x8 : 000000000000003f [ 479.530226] x7 : 0000000000000000 x6 : 0000000000000000 [ 479.530313] x5 : 0000000000000001 x4 : 0000000000000000 [ 479.530416] x3 : ffff000009069fd8 x2 : 0000000000000000 [ 479.530500] x1 : 0000000000000000 x0 : 0000000000000000 [ 479.530599] Process cat (pid: 2457, stack limit = 0x000000005d1b0e6f) [ 479.530660] Call trace: [ 479.530746] walk_pgd.isra.1+0x20/0x1d0 [ 479.530833] ptdump_walk_pgd+0x30/0x50 [ 479.530907] ptdump_show+0x10/0x20 [ 479.530920] seq_read+0xc8/0x470 [ 479.531023] full_proxy_read+0x60/0x90 [ 479.531100] __vfs_read+0x18/0x100 [ 479.531180] vfs_read+0x88/0x160 [ 479.531267] SyS_read+0x48/0xb0 [ 479.531299] el0_svc_naked+0x20/0x24 [ 479.531400] Code: 91400420 f90033a0 a90707a2 f9403fa0 (f9400000) [ 479.531499] ---[ end trace bfe8e28d8acb2b67 ]--- Segmentation fault Let's avoid this problem by only registering the tables after their successful creation, which is also less confusing when EFI runtime services are not in use. Reported-by: Will Deacon Signed-off-by: Mark Rutland Acked-by: Will Deacon Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/arm-runtime.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 1cc41c3d6315..86a1ad17a32e 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -54,6 +54,9 @@ static struct ptdump_info efi_ptdump_info = { static int __init ptdump_init(void) { + if (!efi_enabled(EFI_RUNTIME_SERVICES)) + return 0; + return ptdump_debugfs_register(&efi_ptdump_info, "efi_page_tables"); } device_initcall(ptdump_init); -- 2.15.1