From patchwork Tue May 8 01:27:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10385039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 47E9960353 for ; Tue, 8 May 2018 01:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39BF92785D for ; Tue, 8 May 2018 01:28:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E66927C0B; Tue, 8 May 2018 01:28:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70A282785D for ; Tue, 8 May 2018 01:28:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 149F86B000A; Mon, 7 May 2018 21:28:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0F9246B000C; Mon, 7 May 2018 21:28:14 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F28B76B000D; Mon, 7 May 2018 21:28:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id B07EE6B000A for ; Mon, 7 May 2018 21:28:13 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id i1-v6so831437pld.11 for ; Mon, 07 May 2018 18:28:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=2CZJwxS1MUIvnly2+6zA+pIzjLV7kDHFm1aJfZawb1c=; b=UKIMpeYli0aqs6BRiH3KCLuZsdicPusD7loVbQ6MISbMSwwyio21CP/e7u9khHhdh2 tNvIRqueV1R9BBGt8l6MpzBWVEZE1sOVfQTPt0nl0mlMkOC6ac5w4+gxKzZRVFzlOB+O mxendi6d4vZAWPw/0IUe4aNcwa07xshzZBjCGRSyygucNzN2B7sZ4Ajk7v5zdrUEwVpu lV95RJxhB/wXyp1z/0CWTxu75rDCXxntruOWeyAkx0ZQbqIJeUuRZCKOmq/HKGJtFoIz LMgGU9jIUpHz1+/tyKL7QfO1xW3Kon8xlHWiXydJyca/3I5kX8cJ3P1creihv6M827pm 5qvw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com X-Gm-Message-State: ALQs6tBZ+P3oK+WNqH/ro5ZdZXipHmIu3xZ353wOOVGl8YAN2Xuf8IKp al/eAmd35FbCvbrPebz09iGhqpW7DZ980jgOONX5FrHo9zw4YWl3+yZmTceWqxNVBiTcg5p87RK 5XWB4Ahet5wBPQshykn7TKyeO60sgljzgLyYAK5Q7QKQfIMge6oizCageFfrozV8mEQ== X-Received: by 2002:a63:7058:: with SMTP id a24-v6mr31957916pgn.101.1525742893311; Mon, 07 May 2018 18:28:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqnr8CpkYhCatMPk6mTrhYTrIadP03pcjXM3kdvsVIDTy1rIXNrTuY/zr4gIhPArBYz1Gdg X-Received: by 2002:a63:7058:: with SMTP id a24-v6mr31957870pgn.101.1525742892177; Mon, 07 May 2018 18:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525742892; cv=none; d=google.com; s=arc-20160816; b=b4roW+HHuj2hubNuh8w8nEO2UkOMZd2dnAf/qFZMO7pX0IcJs20BsQMnnip5NBbAOq OITm2GdCthAtLEPRB98dwr4idn2VaWfIL11e0E70ImDLj+MagB3/5JC6ORLVOKdQjkFx jvGuLX2pTATabBoSLxaslf1Fqjg4FXM3VBUTuanYHlapbzZfYFQMbAcRm4sgF1zRl8m5 ZMq/QY0zL86O/1hDokwn/enhlmERywktt/FFNreqbAbQbfWG3OpBX0HZWlzP3zBMPNdy 2THNpd7kz7IuPI6f8KCd2SDWYZgP8cD+bi90HVbiED9zjLSKuwegVr/Vj9K0OTkyUy86 4jww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=2CZJwxS1MUIvnly2+6zA+pIzjLV7kDHFm1aJfZawb1c=; b=m08N2QEXN62Dxk1aLxRdtB2CP6C6D7BZWhDQTwCH3A8YIQh+tQRSSyoGI3zO8T3+2G dAFg9/BSqOyGa7WwZQPhu48tPydgUB169G9PrwsXKdgYSTfMncG0hUIr7PMETksiWGq7 0V3fgGMPHpsyXjKPRngzdKI1gdAb82ew3vtyQC7E6tgmAprp/4uqQlN02N+EhCcEAqNO a4ppYiDqAXd/sIjDzbEy1qrAcSnKMP0rEMdvEfioZ5ezabG15mHJBPCWA05LsICXI/s8 O9SR64/3Oz+zY4t/NhkBnrNJhI7s6tARTOC3ldNI1vg3LmWocu+4fwlO2HJdLpOM9VXz Mv2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id f5-v6si16878252plr.247.2018.05.07.18.28.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 18:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Naoya Horiguchi Reviewed-by: Konstantin Khlebnikov 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;