Commit ab6ecf24 authored by Huang Ying's avatar Huang Ying Committed by Linus Torvalds

mm: /proc/pid/pagemap: hide swap entries from unprivileged users

In commit ab676b7d ("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 1c90308e ("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: 1c90308e ("pagemap: hide physical addresses from non-privileged users")
Signed-off-by: default avatar"Huang, Ying" <ying.huang@intel.com>
Suggested-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: default avatarNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Reviewed-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Andrei Vagin <avagin@openvz.org>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Daniel Colascione <dancol@google.com>
Cc: Zi Yan <zi.yan@cs.rutgers.edu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 25cf23d7
...@@ -1259,6 +1259,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, ...@@ -1259,6 +1259,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,
if (pte_swp_soft_dirty(pte)) if (pte_swp_soft_dirty(pte))
flags |= PM_SOFT_DIRTY; flags |= PM_SOFT_DIRTY;
entry = pte_to_swp_entry(pte); entry = pte_to_swp_entry(pte);
if (pm->show_pfn)
frame = swp_type(entry) | frame = swp_type(entry) |
(swp_offset(entry) << MAX_SWAPFILES_SHIFT); (swp_offset(entry) << MAX_SWAPFILES_SHIFT);
flags |= PM_SWAP; flags |= PM_SWAP;
...@@ -1311,11 +1312,14 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, ...@@ -1311,11 +1312,14 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
else if (is_swap_pmd(pmd)) { else if (is_swap_pmd(pmd)) {
swp_entry_t entry = pmd_to_swp_entry(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; if (pm->show_pfn) {
offset = swp_offset(entry) +
((addr & ~PMD_MASK) >> PAGE_SHIFT);
frame = swp_type(entry) | frame = swp_type(entry) |
(offset << MAX_SWAPFILES_SHIFT); (offset << MAX_SWAPFILES_SHIFT);
}
flags |= PM_SWAP; flags |= PM_SWAP;
if (pmd_swp_soft_dirty(pmd)) if (pmd_swp_soft_dirty(pmd))
flags |= PM_SOFT_DIRTY; flags |= PM_SOFT_DIRTY;
...@@ -1333,11 +1337,13 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, ...@@ -1333,11 +1337,13 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
err = add_to_pagemap(addr, &pme, pm); err = add_to_pagemap(addr, &pme, pm);
if (err) if (err)
break; break;
if (pm->show_pfn && (flags & PM_PRESENT)) if (pm->show_pfn) {
if (flags & PM_PRESENT)
frame++; frame++;
else if (flags & PM_SWAP) else if (flags & PM_SWAP)
frame += (1 << MAX_SWAPFILES_SHIFT); frame += (1 << MAX_SWAPFILES_SHIFT);
} }
}
spin_unlock(ptl); spin_unlock(ptl);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment