Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3323233imu; Sun, 11 Nov 2018 12:21:52 -0800 (PST) X-Google-Smtp-Source: AJdET5c2T8E3XM9+QfwD8ak4J4wMwE27rb8vlkjXhx9OdDtIZqMmJu7k0vTJjo87JZ+9ZKStUqLa X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr17486786pln.129.1541967712001; Sun, 11 Nov 2018 12:21:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967711; cv=none; d=google.com; s=arc-20160816; b=fznjKzU0c2eba2DaSCaUgga7mOfVMklYekW288b3oTYkmOco8HFM7of3KAS7xOAaOU UAVTno170TlwA46vC+250UsJ8CtnWRzNtFraVxkxmMiF+Y90w3ZLLUhyCCMrDTRiZoS1 p6Y5bSRv3dmrIjXD36c9Lzl3QXjV7K4KTC5L7pJGLBA28tof5KVSmLFS47HFSMV2A1uR L4iFAK0R4ysd2r4rzC+U63pau3GW2nsH9VsKcmKpcRqDum+hYfCpkfmSN6fmqLK/oyNo BKdwVZeKoK+GlwaMzIGeU88ArLuNmw0DunroGrpE2cZ74L5sBrpMVCTbarWmKGvP6b3A pgzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=gQUijW47EZjX/uIZ5yCVKi0IqFNuAhhdY7cHRze6Ryw=; b=D80ZX6d4mSdSWw97sL4hfgRo/dcP9fFwILRMA9yOF3HuOZu2EFvFguwbBXbvBuGDRH 7/+y2kBEuRM65rQYM/VtE5cAeQZ0drPJXhGRot3k0O8JgP+Ck5ZJMoZ3kCVflsz6uaRP vrDeDydAXx4OJwTFOWcgO3/7JjHACOgc/c3qNxp/M9l8hPyKEyx+V8VrW2FtImaiFlMu ogJC2GulCMLeG6WeYvwuYRNXRQhXg+kQn8gkOsp0HeAC30Uh1VkUCBnJWe6OY2FveQrF XuNl/BJQCFHW1sRPeJzIHOevBcLoEOnxw+iAT9ghn1Gzij6mXoZkFWVQuhktVqfj/2pU ihrA== ARC-Authentication-Results: i=1; mx.google.com; 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 t10-v6si10860164plh.416.2018.11.11.12.21.37; Sun, 11 Nov 2018 12:21:51 -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; 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 S1731170AbeKLGKf (ORCPT + 99 others); Mon, 12 Nov 2018 01:10:35 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:53518 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731963AbeKLGKJ (ORCPT ); Mon, 12 Nov 2018 01:10:09 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt3-0000l7-Dh; Sun, 11 Nov 2018 19:59:13 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsR-0001Ws-KM; Sun, 11 Nov 2018 19:58:35 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mark Williamson" , "Linus Torvalds" , "Naoya Horiguchi" , "Konstantin Khlebnikov" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 124/366] pagemap: hide physical addresses from non-privileged users In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Konstantin Khlebnikov commit 1c90308e7a77af6742a97d1021cca923b23b7f0d upstream. This patch makes pagemap readable for normal users and hides physical addresses from them. For some use-cases PFN isn't required at all. See http://lkml.kernel.org/r/1425935472-17949-1-git-send-email-kirill@shutemov.name Fixes: ab676b7d6fbf ("pagemap: do not leak physical addresses to non-privileged userspace") Signed-off-by: Konstantin Khlebnikov Cc: Naoya Horiguchi Reviewed-by: Mark Williamson Tested-by: Mark Williamson Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: - Add the same check in the places where we look up a PFN - Adjust context] Signed-off-by: Ben Hutchings --- fs/proc/task_mmu.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -862,6 +862,7 @@ struct pagemapread { int pos, len; /* units: PM_ENTRY_BYTES, not bytes */ pagemap_entry_t *buffer; bool v2; + bool show_pfn; }; #define PAGEMAP_WALK_SIZE (PMD_SIZE) @@ -921,12 +922,13 @@ static int pagemap_pte_hole(unsigned lon static void pte_to_pagemap_entry(pagemap_entry_t *pme, struct pagemapread *pm, struct vm_area_struct *vma, unsigned long addr, pte_t pte) { - u64 frame, flags; + u64 frame = 0, flags; struct page *page = NULL; int flags2 = 0; if (pte_present(pte)) { - frame = pte_pfn(pte); + if (pm->show_pfn) + frame = pte_pfn(pte); flags = PM_PRESENT; page = vm_normal_page(vma, addr, pte); if (pte_soft_dirty(pte)) @@ -966,7 +968,7 @@ static void thp_pmd_to_pagemap_entry(pag * This if-check is just to prepare for future implementation. */ if (pmd_present(pmd)) - *pme = make_pme(PM_PFRAME(pmd_pfn(pmd) + offset) + *pme = make_pme((pm->show_pfn ? PM_PFRAME(pmd_pfn(pmd) + offset) : 0) | PM_STATUS2(pm->v2, pmd_flags2) | PM_PRESENT); else *pme = make_pme(PM_NOT_PRESENT(pm->v2) | PM_STATUS2(pm->v2, pmd_flags2)); @@ -1075,7 +1077,7 @@ static void huge_pte_to_pagemap_entry(pa pte_t pte, int offset, int flags2) { if (pte_present(pte)) - *pme = make_pme(PM_PFRAME(pte_pfn(pte) + offset) | + *pme = make_pme((pm->show_pfn ? PM_PFRAME(pte_pfn(pte) + offset) : 0) | PM_STATUS2(pm->v2, flags2) | PM_PRESENT); else @@ -1167,6 +1169,10 @@ static ssize_t pagemap_read(struct file goto out_task; pm.v2 = soft_dirty_cleared; + + /* do not disclose physical addresses: attack vector */ + pm.show_pfn = file_ns_capable(file, &init_user_ns, CAP_SYS_ADMIN); + pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT); pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_TEMPORARY); ret = -ENOMEM; @@ -1241,9 +1247,6 @@ out: static int pagemap_open(struct inode *inode, struct file *file) { - /* do not disclose physical addresses: attack vector */ - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; pr_warn_once("Bits 55-60 of /proc/PID/pagemap entries are about " "to stop being page-shift some time soon. See the " "linux/Documentation/vm/pagemap.txt for details.\n");