From patchwork Mon Mar 19 16:01:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132068 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp3111630edb; Mon, 19 Mar 2018 11:04:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELsL9xZ1uOM+F0Yxq5/ijQt7QIV1EAZjZPKNXI3Sxzy8ZZp0SwTnEPxafH1tcDplevr+AfxO X-Received: by 2002:a17:902:b703:: with SMTP id d3-v6mr13157700pls.209.1521482691021; Mon, 19 Mar 2018 11:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521482691; cv=none; d=google.com; s=arc-20160816; b=FxQRi22XehlCSPNO/8yFmNgrmk9wl5YpWiZ6dry60SRYAbSQKwR9ncXONFuwr5xmjR LtmLAqvUWNir46M1EwaH4kWnq6z6mPhF+2nCTfpB6ilZ0F3YivGngfExjyz2Vc7ELpvt Au24lFJyqSTRyVlrMnzSjhSoB7vDhCGuaYT/o3ZcbRQL4KYOTt1jgKPf1e+VyM7uo77D t3HBipC+rnvbsh4d+6ULToXFSf96T7Tq9+NKuF+kRJO/ZixRUgcrjK36x9O76rNiZXm+ 6u/PrgbUVsp2yf9vDNPraVeRmlPnO41pq5DdBWR5FMnfWnFP6RrnxSy+eog9q8c/E6ue cTwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=7tytLtDOBJ5LLbNyfNKuXG8RVC+BsYgf/Vb15U5l/ek=; b=f3xQdNpkzJbSdfDjSNuos6JrCftP8akOm6hAoWoj2KlvwtqLW3aP7owW289e2GMjcL 9kuNDa++ySiJfnMg8meZ1EpKhxCb2d8JtwkWAUXYhTjJ2b2Gjo3ywfZ0AuzgxHVZJzLe j1v2FBL+izEpX+Qg7pcDv0QthsM2ELiK5vBhF7Orje/j2lgQ8Gy6IAgKjvQVDG6IKDLS vAEdPYupp3K7/W/U/7z/UryP5Til4bKPdF3HKMDhsVPN/vOxdEZ7dtX2XZL3QCNR2b60 6uNnrTctSl6zAqo5twGRh6o4BqsjpvW8hOvRRFDBDwNjx/XTFCF1dc1xwWUEab6BrxK0 ivRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Hppp06an; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si307404pgf.251.2018.03.19.11.04.50; Mon, 19 Mar 2018 11:04:51 -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=@microsoft.com header.s=selector1 header.b=Hppp06an; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968400AbeCSSEr (ORCPT + 28 others); Mon, 19 Mar 2018 14:04:47 -0400 Received: from mail-by2nam01on0098.outbound.protection.outlook.com ([104.47.34.98]:46928 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935039AbeCSQDu (ORCPT ); Mon, 19 Mar 2018 12:03:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7tytLtDOBJ5LLbNyfNKuXG8RVC+BsYgf/Vb15U5l/ek=; b=Hppp06ani0q1luAOGdKpUlhhz+4NOBWBllBHlj9mlx0fw0147UZt6O8WLfn9gt9s+NMykSgmo0GGP3aRS0HSqi4QAM+GWKkzRc2Z2Bs69mu5N5rMtlxIvscHT/+ykZULnLIgmaZ1ZzVJbNWNsDBpk8Gau59WAd3Z8vt4PKCIiG4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1077.namprd21.prod.outlook.com (52.132.130.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.1; Mon, 19 Mar 2018 16:03:48 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:03:48 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Ard Biesheuvel , Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 184/281] arm64: kernel: restrict /dev/mem read() calls to linear region Thread-Topic: [PATCH AUTOSEL for 4.9 184/281] arm64: kernel: restrict /dev/mem read() calls to linear region Thread-Index: AQHTv5uMkPGhfWxvC0eqDvDM+I+3Kw== Date: Mon, 19 Mar 2018 16:01:31 +0000 Message-ID: <20180319155742.13731-184-alexander.levin@microsoft.com> References: <20180319155742.13731-1-alexander.levin@microsoft.com> In-Reply-To: <20180319155742.13731-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB1077; 7:3Z6rTWAmpfaE99gYggAOwvTbeQMc5UI4suVPWjZrPhdwh6+K5lb12nBLypBNoMUPF4sAUJWBzO8Ah/K41VHr32nl34zDWN5S1X+AP2MmK7pz44eBh0GGoO3YOOwK83U8GJ2e1UbXyqU1xFRtFUFBpfQI6+3vVNBSFDkaBwmkJnC8E21GRHZi5LA73XcT46bRiN2+T0Zc9hQzboRIwiW6MmjW+tBsGXDzp2NaQHaiQ8x0VlvKbQnvna0k7uNd3APn; 20:oFr3gzr0S+y9bfr6opkWPfG2mg+g2N33ayTBS7vctfM0V7l+niA5hcA/22VARpY3kLNKwVRdawuSri5JEcrs/4dPkgvdmkIrWyAm3GNznlrozJGt2CiMn2wu1s7PYKAnnXkcvpPWLexuuGsUI4JAudrXs2aAHtRnpNRmLDdFVMI= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 2fd036d6-3e07-420a-d794-08d58db30036 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB1077; x-ms-traffictypediagnostic: DM5PR2101MB1077: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:DM5PR2101MB1077; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1077; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(979002)(346002)(376002)(39860400002)(396003)(39380400002)(366004)(199004)(189003)(110136005)(36756003)(3280700002)(66066001)(3660700001)(4326008)(6666003)(2950100002)(25786009)(86612001)(105586002)(10090500001)(68736007)(22452003)(99286004)(106356001)(5660300001)(7736002)(305945005)(76176011)(54906003)(5250100002)(97736004)(316002)(2501003)(3846002)(6116002)(1076002)(2906002)(14454004)(2900100001)(6512007)(8936002)(186003)(478600001)(10290500003)(53936002)(8676002)(107886003)(6436002)(81166006)(86362001)(6506007)(59450400001)(102836004)(26005)(72206003)(6486002)(81156014)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1077; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: c9QaUzwrfnjknWvYyCJKEuCXl4oBUXhoWnBRwbdg079t5YcRv+qLBAjWybPYBsUBkKW5MphbpRpNe/hCVThNXWIJJP/seygz5GJ1JgIfEnaJOKY1iUXD762pvSn5dsSuEyAEXJk1vgIJqlImxNFzOhkmsL/oU2hDD+2QGXO8dTiq3l8xViEzsjmy4KOcqmA46xcLQFXejzcFsXoptJ2Jw0MHAw0gSEz6gRm1BfQlhXXREL/zDX9b/MzwdOZ5I3NHXpOuB3hPbNG/4dX4fh9hKQD5RDCMA0ZxSQpgnE7qZaESvi2LesTx7EKjsC78U0CNEaTEK26rndSyRkjsg7hUJA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fd036d6-3e07-420a-d794-08d58db30036 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:01:31.5844 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1077 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 1151f838cb626005f4d69bf675dacaaa5ea909d6 ] When running lscpu on an AArch64 system that has SMBIOS version 2.0 tables, it will segfault in the following way: Unable to handle kernel paging request at virtual address ffff8000bfff0000 pgd = ffff8000f9615000 [ffff8000bfff0000] *pgd=0000000000000000 Internal error: Oops: 96000007 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1284 Comm: lscpu Not tainted 4.11.0-rc3+ #103 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 task: ffff8000fa78e800 task.stack: ffff8000f9780000 PC is at __arch_copy_to_user+0x90/0x220 LR is at read_mem+0xcc/0x140 This is caused by the fact that lspci issues a read() on /dev/mem at the offset where it expects to find the SMBIOS structure array. However, this region is classified as EFI_RUNTIME_SERVICE_DATA (as per the UEFI spec), and so it is omitted from the linear mapping. So let's restrict /dev/mem read/write access to those areas that are covered by the linear region. Reported-by: Alexander Graf Fixes: 4dffbfc48d65 ("arm64/efi: mark UEFI reserved regions as MEMBLOCK_NOMAP") Signed-off-by: Ard Biesheuvel Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/mm/mmap.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) -- 2.14.1 diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 01c171723bb3..caf75abf6ae7 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -102,12 +103,18 @@ void arch_pick_mmap_layout(struct mm_struct *mm) */ int valid_phys_addr_range(phys_addr_t addr, size_t size) { - if (addr < PHYS_OFFSET) - return 0; - if (addr + size > __pa(high_memory - 1) + 1) - return 0; - - return 1; + /* + * Check whether addr is covered by a memory region without the + * MEMBLOCK_NOMAP attribute, and whether that region covers the + * entire range. In theory, this could lead to false negatives + * if the range is covered by distinct but adjacent memory regions + * that only differ in other attributes. However, few of such + * attributes have been defined, and it is debatable whether it + * follows that /dev/mem read() calls should be able traverse + * such boundaries. + */ + return memblock_is_region_memory(addr, size) && + memblock_is_map_memory(addr); } /*