Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1150454imm; Wed, 1 Aug 2018 11:01:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcf8EGRWGFhLEPvr637iHp0BoRHtc4OyV3HksXZtILnolCWhoGIfYP26SmuruaXdYQwyLe4 X-Received: by 2002:a62:404e:: with SMTP id n75-v6mr27749400pfa.232.1533146506736; Wed, 01 Aug 2018 11:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533146506; cv=none; d=google.com; s=arc-20160816; b=K9zFEWEeUkJhjljE1jmZ/VyjNlx+ORlXVq+szXK9aczJwKm8AFJj8FXgFDh2Ri4l/3 LlrJ7TEKtg3gfwYvAMpx/4AV2pgD28ux9jD5BsGD2Q8kNQRcV+Nm6NKPwmEv6CGJF5F1 EIOjk6gb8yNIPslFbLx/ck4EebAKx9WCS0mrbYO+nKImJgEWaW8FyTmdc8Ce6eD3YnCG 40pmO+kQM44iz3NTt+hr/585kro47hr7JeVv9cFpYHhas9S8PJVWCi2+EtQ8z99z7T+2 Z7lSew6j1TZBVYAB0B16l+fwWmLDS8w6gwrk7IX9N8WomcyP+5lXMhYLhGVgyoUrwnrI P3GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Qd53JsfPBOfYbSrKVw0ew12z2ceAWOuiV3PSMY9rdEE=; b=wSC21zjhOGD7tYsDfzZIEUKD/Fd34O22eZdQhlSPbwqLnn9/Xy/nUg0D6r3YcpK81C GGHukVn80j2ubfcnIxw73HIYJLaqno+wGUBatslDVIumQ9/g9rLdDoDAV8M+E89ZEFpB 4HEolrsrfsyZp7P902qfqxup+JKQZa/UmTKnpLwRxgedbQ+2zzDPGbjzXDNGmwJc4pT3 sN/lGdKDhb9wIz1xt1Edi0e2YnRGm7HPwhEcN079Fzy9jeEDASAvmGGinHTkYvex4H9D naNaGv9o+R306F8IWqZXYbfiJFOee7QJn8ZXjMN1w6xiFjbsSIlT9JZh4JHp+iFAHGgP K4lg== 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 t8-v6si15796752pgl.620.2018.08.01.11.01.31; Wed, 01 Aug 2018 11:01:46 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732669AbeHATpj (ORCPT + 99 others); Wed, 1 Aug 2018 15:45:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49806 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405721AbeHATIj (ORCPT ); Wed, 1 Aug 2018 15:08:39 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F11731356; Wed, 1 Aug 2018 17:13:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Huang, Ying" , "Kirill A. Shutemov" , Naoya Horiguchi , Konstantin Khlebnikov , Michal Hocko , Andrei Vagin , Jerome Glisse , Daniel Colascione , Zi Yan , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 032/246] mm: /proc/pid/pagemap: hide swap entries from unprivileged users Date: Wed, 1 Aug 2018 18:49:02 +0200 Message-Id: <20180801165013.229069817@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huang Ying [ Upstream commit ab6ecf247a9321e3180e021a6a60164dee53ab2e ] In commit 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 commit 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. Link: http://lkml.kernel.org/r/20180508012745.7238-1-ying.huang@intel.com Fixes: 1c90308e7a77 ("pagemap: hide physical addresses from non-privileged users") Signed-off-by: "Huang, Ying" Suggested-by: Kirill A. Shutemov Reviewed-by: Naoya Horiguchi Reviewed-by: Konstantin Khlebnikov Acked-by: Michal Hocko Cc: Konstantin Khlebnikov Cc: Andrei Vagin Cc: Jerome Glisse Cc: Daniel Colascione Cc: Zi Yan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/proc/task_mmu.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1275,8 +1275,9 @@ static pagemap_entry_t pte_to_pagemap_en 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); @@ -1327,11 +1328,14 @@ static int pagemap_pmd_range(pmd_t *pmdp #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; @@ -1349,10 +1353,12 @@ static int pagemap_pmd_range(pmd_t *pmdp 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;