Received: by 10.192.165.148 with SMTP id m20csp5225124imm; Wed, 9 May 2018 01:17:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr0Q+Cz9ObyX9Ign26jp0hWlV1YWCnJlSXS8Kfr7JOD/GHS3RbnBL/ScJOduXQqc202Ij6X X-Received: by 2002:a63:18c:: with SMTP id 134-v6mr21288536pgb.138.1525853827416; Wed, 09 May 2018 01:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525853827; cv=none; d=google.com; s=arc-20160816; b=OI/+yS7iW5L2mk531zSCvPudhEHu4X934W89iRV4dXTYkvf8gdzxgp07tueiFsOWHx raGUUenlDzqVcuRSk4R5Dfomw8iN5UCBnm42yU7I6zWHerYDvPJY/4h5llw6At5ifyzu bl9NgjVJRddho2cIRsF4u3mpZOvL0RKHBTkWNT/+5O0ojlzQaljDybpxh96DF84QjyXH ayTpBORKa4WC4Fim3DJ2ngmijaItpFBKLM/uNaCEHMv+0L1pA1c2+KNS0LEa1yT9m1A9 UNv2LhcOWMIxsQ2ca62vFqjrBfBkD6i57qkBmRUZ1JOg8w6X6qTtueo136AuVxwidmCA DUvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Pf92Er/MfqQAgbC28756tha6DwrezVJ3jtwbu/NKM6w=; b=W5LKB0pBEQxFz5q2NQiSar84t5N1E98ERLMY9abaDZL8fVi0l4NdT8Rl7DwztL1qMN iZkvn+zCRev5OT9ZAhx5ye8GKhCz3pFFsW5YE3AI+Y+caw6GK8+bRvbddrNXu8gd5Rx3 qBU5MkRe/FmykNJ4gfCIy2hG053nUQ1ZU+KZtIz1NfdTjokXqjSzw8oB9QwrhPOIviVH mzG4uKxNqAOz6+hxbmE442DQoai6z5gnZRlFVv16qjINwonSNHkwnEnF8w753vewF/gT 18FLfsTmRIfg46pJtkY4sXowxjmBLQGDWjM/vC7PmUHnmw8HaCYjXseTur78QBjPkLEB O8Fw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l2-v6si21068074pgc.438.2018.05.09.01.16.52; Wed, 09 May 2018 01:17:07 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933965AbeEIIQW (ORCPT + 99 others); Wed, 9 May 2018 04:16:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:60400 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933715AbeEIIQS (ORCPT ); Wed, 9 May 2018 04:16:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 45D3AAD5E; Wed, 9 May 2018 08:16:17 +0000 (UTC) Date: Wed, 9 May 2018 10:16:15 +0200 From: Michal Hocko To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Konstantin Khlebnikov , Andrei Vagin , Jerome Glisse , Daniel Colascione , Zi Yan , Naoya Horiguchi , "Kirill A. Shutemov" Subject: Re: [PATCH -mm] mm, pagemap: Hide swap entry for unprivileged users Message-ID: <20180509081615.GF32366@dhcp22.suse.cz> References: <20180508012745.7238-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180508012745.7238-1-ying.huang@intel.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 08-05-18 09:27:45, Huang, Ying wrote: > From: Huang Ying > > In ab676b7d6fbf ("pagemap: do not leak physical addresses to > non-privileged userspace"), the /proc/PID/pagemap is restricted to be > readable only by CAP_SYS_ADMIN to address some security issue. In > 1c90308e7a77 ("pagemap: hide physical addresses from non-privileged > users"), the restriction is relieved to make /proc/PID/pagemap > readable, but hide the physical addresses for non-privileged users. > But the swap entries are readable for non-privileged users too. This > has some security issues. For example, for page under migrating, the > swap entry has physical address information. So, in this patch, the > swap entries are hided for non-privileged users too. Migration entries are quite ephemeral so I am not sure how this could be abused. But I do agree that hiding swap entries make some sense from consistency POV > Fixes: 1c90308e7a77 ("pagemap: hide physical addresses from non-privileged users") > Signed-off-by: "Huang, Ying" > Suggested-by: Kirill A. Shutemov > Cc: Konstantin Khlebnikov > Cc: Andrei Vagin > Cc: Michal Hocko > Cc: Jerome Glisse > Cc: Daniel Colascione > Cc: Zi Yan > Cc: Naoya Horiguchi Acked-by: Michal Hocko > --- > fs/proc/task_mmu.c | 26 ++++++++++++++++---------- > 1 file changed, 16 insertions(+), 10 deletions(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index a20c6e495bb2..ff947fdd7c71 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1258,8 +1258,9 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, > if (pte_swp_soft_dirty(pte)) > flags |= PM_SOFT_DIRTY; > entry = pte_to_swp_entry(pte); > - frame = swp_type(entry) | > - (swp_offset(entry) << MAX_SWAPFILES_SHIFT); > + if (pm->show_pfn) > + frame = swp_type(entry) | > + (swp_offset(entry) << MAX_SWAPFILES_SHIFT); > flags |= PM_SWAP; > if (is_migration_entry(entry)) > page = migration_entry_to_page(entry); > @@ -1310,11 +1311,14 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, > #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION > else if (is_swap_pmd(pmd)) { > swp_entry_t entry = pmd_to_swp_entry(pmd); > - unsigned long offset = swp_offset(entry); > + unsigned long offset; > > - offset += (addr & ~PMD_MASK) >> PAGE_SHIFT; > - frame = swp_type(entry) | > - (offset << MAX_SWAPFILES_SHIFT); > + if (pm->show_pfn) { > + offset = swp_offset(entry) + > + ((addr & ~PMD_MASK) >> PAGE_SHIFT); > + frame = swp_type(entry) | > + (offset << MAX_SWAPFILES_SHIFT); > + } > flags |= PM_SWAP; > if (pmd_swp_soft_dirty(pmd)) > flags |= PM_SOFT_DIRTY; > @@ -1332,10 +1336,12 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, > err = add_to_pagemap(addr, &pme, pm); > if (err) > break; > - if (pm->show_pfn && (flags & PM_PRESENT)) > - frame++; > - else if (flags & PM_SWAP) > - frame += (1 << MAX_SWAPFILES_SHIFT); > + if (pm->show_pfn) { > + if (flags & PM_PRESENT) > + frame++; > + else if (flags & PM_SWAP) > + frame += (1 << MAX_SWAPFILES_SHIFT); > + } > } > spin_unlock(ptl); > return err; > -- > 2.17.0 > -- Michal Hocko SUSE Labs