Commit ba5d0201 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov Committed by Willy Tarreau

pagemap: hide physical addresses from non-privileged users

commit 1c90308e upstream.

This patch makes pagemap readable for normal users and hides physical
addresses from them.  For some use-cases PFN isn't required at all.

See http://lkml.kernel.org/r/1425935472-17949-1-git-send-email-kirill@shutemov.name

Fixes: ab676b7d ("pagemap: do not leak physical addresses to non-privileged userspace")
Signed-off-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Reviewed-by: default avatarMark Williamson <mwilliamson@undo-software.com>
Tested-by: default avatarMark Williamson <mwilliamson@undo-software.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
[bwh: Backported to 3.2:
 - Add the same check in the places where we look up a PFN
 - Add struct pagemapread * parameters where necessary
 - Open-code file_ns_capable()
 - Delete pagemap_open() entirely, as it would always return 0]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
(cherry picked from commit b1fb185f)
[wt: adjusted context, no pagemap_hugetlb_range() in 2.6.32, needs
     cred argument to security_capable(), tested OK ]
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent ddf5836a
......@@ -8,6 +8,7 @@
#include <linux/mempolicy.h>
#include <linux/swap.h>
#include <linux/swapops.h>
#include <linux/security.h>
#include <asm/elf.h>
#include <asm/uaccess.h>
......@@ -539,6 +540,7 @@ const struct file_operations proc_clear_refs_operations = {
struct pagemapread {
u64 __user *out, *end;
bool show_pfn;
};
#define PM_ENTRY_BYTES sizeof(u64)
......@@ -589,14 +591,14 @@ static u64 swap_pte_to_pagemap_entry(pte_t pte)
return swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT);
}
static u64 pte_to_pagemap_entry(pte_t pte)
static u64 pte_to_pagemap_entry(struct pagemapread *pm, pte_t pte)
{
u64 pme = 0;
if (is_swap_pte(pte))
pme = PM_PFRAME(swap_pte_to_pagemap_entry(pte))
| PM_PSHIFT(PAGE_SHIFT) | PM_SWAP;
else if (pte_present(pte))
pme = PM_PFRAME(pte_pfn(pte))
pme = (pm->show_pfn ? PM_PFRAME(pte_pfn(pte)) : 0)
| PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT;
return pme;
}
......@@ -624,7 +626,7 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
if (vma && (vma->vm_start <= addr) &&
!is_vm_hugetlb_page(vma)) {
pte = pte_offset_map(pmd, addr);
pfn = pte_to_pagemap_entry(*pte);
pfn = pte_to_pagemap_entry(pm, *pte);
/* unmap before userspace copy */
pte_unmap(pte);
}
......@@ -695,6 +697,9 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
if (!count)
goto out_task;
/* do not disclose physical addresses: attack vector */
pm.show_pfn = !security_capable(file->f_cred, CAP_SYS_ADMIN);
mm = get_task_mm(task);
if (!mm)
goto out_task;
......@@ -773,19 +778,9 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
return ret;
}
static int pagemap_open(struct inode *inode, struct file *file)
{
/* do not disclose physical addresses to unprivileged
userspace (closes a rowhammer attack vector) */
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return 0;
}
const struct file_operations proc_pagemap_operations = {
.llseek = mem_lseek, /* borrow this */
.read = pagemap_read,
.open = pagemap_open,
};
#endif /* CONFIG_PROC_PAGE_MONITOR */
......
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