Received: by 10.192.165.148 with SMTP id m20csp3731591imm; Mon, 7 May 2018 18:28:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpx0m78Np/kmkqygy2Qy9d7C7R3NZYS4L+SPcg0f33m+6hrzFZ+qLXHYTNOqj8umq7w8Khz X-Received: by 2002:a17:902:a5c7:: with SMTP id t7-v6mr31463279plq.360.1525742923770; Mon, 07 May 2018 18:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525742923; cv=none; d=google.com; s=arc-20160816; b=GoZqxPpQAo181dJB4QJ5J9DEVLk03j9nmv9iXdNQj2+kiNS+lO9rL6MqR1/Sz/mLdO 7+7QMvTMZKj/Zk4/Nwo3wo5D8tJRj8oCyVBCV12IUvMV5Dwdv6q5BDRYxVeCXL21Y5/R jUoeN1kTJxhqMHKziuSOdk13Inx7rU2eomPBNJofYjPbC6J4OAdETFFAzCJnX75HeaW2 wA/y0A+3hHwbCDbp/2xAL3HV2qNZRw+vR8OSCYr5Eq62usjXwjYeyjCiYAjml/26HhmT dmZJOe8Im15+tKnn6dE3vW38wILTTJOO5hRVQDPCRMiHlCqz44vi4w3yC+29gUYh9CPZ PY4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2CZJwxS1MUIvnly2+6zA+pIzjLV7kDHFm1aJfZawb1c=; b=hKMqhkFLDUz7hPHzF0ET/J6Tc6zeKjnZnGhBnzc5SavXJwvMb5Eve5zA6OBE4/Wk52 JlgV41oec0wED7FpvHFIAy+0BRCQiPNe1u6PKj7E0xs7HTuGc9SAWzPlzBOmHn0c+QFY O3XIFPA62l29d4F/v+YXVHLKYFtAkATaVKBB44K4+QxWjgvN1Ag5obcExmZPcLInpBD/ rpnr+waj33bVsQNZZPUofRNGXk8DYVrXP+dyLBS3xNLt+iR0/whGOFhD0lIp1uA7IyKy avt4KBp23x13uV+C67FfW1MbLIiCylPpwIp0xLEYYfym8Rfo+KNUBot2gyPoCB4Y87aV HkvA== 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 u78-v6si18841055pgb.136.2018.05.07.18.28.28; Mon, 07 May 2018 18:28:43 -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 S1753602AbeEHB2N (ORCPT + 99 others); Mon, 7 May 2018 21:28:13 -0400 Received: from mga18.intel.com ([134.134.136.126]:40866 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753108AbeEHB2M (ORCPT ); Mon, 7 May 2018 21:28:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 May 2018 18:28:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,376,1520924400"; d="scan'208";a="37590221" Received: from yhuang-dev.sh.intel.com ([10.239.13.118]) by fmsmga007.fm.intel.com with ESMTP; 07 May 2018 18:28:09 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Konstantin Khlebnikov , Andrei Vagin , Michal Hocko , Jerome Glisse , Daniel Colascione , Zi Yan , Naoya Horiguchi , "Kirill A. Shutemov" Subject: [PATCH -mm] mm, pagemap: Hide swap entry for unprivileged users Date: Tue, 8 May 2018 09:27:45 +0800 Message-Id: <20180508012745.7238-1-ying.huang@intel.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 --- 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