aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/base.c22
-rw-r--r--fs/proc/task_mmu.c50
2 files changed, 56 insertions, 16 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 770de444eba0..81d7d145292a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1036,6 +1036,26 @@ static const struct file_operations proc_loginuid_operations = {
1036 .read = proc_loginuid_read, 1036 .read = proc_loginuid_read,
1037 .write = proc_loginuid_write, 1037 .write = proc_loginuid_write,
1038}; 1038};
1039
1040static ssize_t proc_sessionid_read(struct file * file, char __user * buf,
1041 size_t count, loff_t *ppos)
1042{
1043 struct inode * inode = file->f_path.dentry->d_inode;
1044 struct task_struct *task = get_proc_task(inode);
1045 ssize_t length;
1046 char tmpbuf[TMPBUFLEN];
1047
1048 if (!task)
1049 return -ESRCH;
1050 length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
1051 audit_get_sessionid(task));
1052 put_task_struct(task);
1053 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
1054}
1055
1056static const struct file_operations proc_sessionid_operations = {
1057 .read = proc_sessionid_read,
1058};
1039#endif 1059#endif
1040 1060
1041#ifdef CONFIG_FAULT_INJECTION 1061#ifdef CONFIG_FAULT_INJECTION
@@ -2319,6 +2339,7 @@ static const struct pid_entry tgid_base_stuff[] = {
2319 REG("oom_adj", S_IRUGO|S_IWUSR, oom_adjust), 2339 REG("oom_adj", S_IRUGO|S_IWUSR, oom_adjust),
2320#ifdef CONFIG_AUDITSYSCALL 2340#ifdef CONFIG_AUDITSYSCALL
2321 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 2341 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
2342 REG("sessionid", S_IRUSR, sessionid),
2322#endif 2343#endif
2323#ifdef CONFIG_FAULT_INJECTION 2344#ifdef CONFIG_FAULT_INJECTION
2324 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject), 2345 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
@@ -2649,6 +2670,7 @@ static const struct pid_entry tid_base_stuff[] = {
2649 REG("oom_adj", S_IRUGO|S_IWUSR, oom_adjust), 2670 REG("oom_adj", S_IRUGO|S_IWUSR, oom_adjust),
2650#ifdef CONFIG_AUDITSYSCALL 2671#ifdef CONFIG_AUDITSYSCALL
2651 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 2672 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
2673 REG("sessionid", S_IRUSR, sessionid),
2652#endif 2674#endif
2653#ifdef CONFIG_FAULT_INJECTION 2675#ifdef CONFIG_FAULT_INJECTION
2654 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject), 2676 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 4206454734e0..9dfb5ff24209 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -527,13 +527,21 @@ struct pagemapread {
527 char __user *out, *end; 527 char __user *out, *end;
528}; 528};
529 529
530#define PM_ENTRY_BYTES sizeof(u64) 530#define PM_ENTRY_BYTES sizeof(u64)
531#define PM_RESERVED_BITS 3 531#define PM_STATUS_BITS 3
532#define PM_RESERVED_OFFSET (64 - PM_RESERVED_BITS) 532#define PM_STATUS_OFFSET (64 - PM_STATUS_BITS)
533#define PM_RESERVED_MASK (((1LL<<PM_RESERVED_BITS)-1) << PM_RESERVED_OFFSET) 533#define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET)
534#define PM_SPECIAL(nr) (((nr) << PM_RESERVED_OFFSET) & PM_RESERVED_MASK) 534#define PM_STATUS(nr) (((nr) << PM_STATUS_OFFSET) & PM_STATUS_MASK)
535#define PM_NOT_PRESENT PM_SPECIAL(1LL) 535#define PM_PSHIFT_BITS 6
536#define PM_SWAP PM_SPECIAL(2LL) 536#define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS)
537#define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET)
538#define PM_PSHIFT(x) (((u64) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK)
539#define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1)
540#define PM_PFRAME(x) ((x) & PM_PFRAME_MASK)
541
542#define PM_PRESENT PM_STATUS(4LL)
543#define PM_SWAP PM_STATUS(2LL)
544#define PM_NOT_PRESENT PM_PSHIFT(PAGE_SHIFT)
537#define PM_END_OF_BUFFER 1 545#define PM_END_OF_BUFFER 1
538 546
539static int add_to_pagemap(unsigned long addr, u64 pfn, 547static int add_to_pagemap(unsigned long addr, u64 pfn,
@@ -574,7 +582,7 @@ static int pagemap_pte_hole(unsigned long start, unsigned long end,
574u64 swap_pte_to_pagemap_entry(pte_t pte) 582u64 swap_pte_to_pagemap_entry(pte_t pte)
575{ 583{
576 swp_entry_t e = pte_to_swp_entry(pte); 584 swp_entry_t e = pte_to_swp_entry(pte);
577 return PM_SWAP | swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT); 585 return swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT);
578} 586}
579 587
580static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, 588static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
@@ -588,9 +596,11 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
588 u64 pfn = PM_NOT_PRESENT; 596 u64 pfn = PM_NOT_PRESENT;
589 pte = pte_offset_map(pmd, addr); 597 pte = pte_offset_map(pmd, addr);
590 if (is_swap_pte(*pte)) 598 if (is_swap_pte(*pte))
591 pfn = swap_pte_to_pagemap_entry(*pte); 599 pfn = PM_PFRAME(swap_pte_to_pagemap_entry(*pte))
600 | PM_PSHIFT(PAGE_SHIFT) | PM_SWAP;
592 else if (pte_present(*pte)) 601 else if (pte_present(*pte))
593 pfn = pte_pfn(*pte); 602 pfn = PM_PFRAME(pte_pfn(*pte))
603 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT;
594 /* unmap so we're not in atomic when we copy to userspace */ 604 /* unmap so we're not in atomic when we copy to userspace */
595 pte_unmap(pte); 605 pte_unmap(pte);
596 err = add_to_pagemap(addr, pfn, pm); 606 err = add_to_pagemap(addr, pfn, pm);
@@ -611,12 +621,20 @@ static struct mm_walk pagemap_walk = {
611/* 621/*
612 * /proc/pid/pagemap - an array mapping virtual pages to pfns 622 * /proc/pid/pagemap - an array mapping virtual pages to pfns
613 * 623 *
614 * For each page in the address space, this file contains one 64-bit 624 * For each page in the address space, this file contains one 64-bit entry
615 * entry representing the corresponding physical page frame number 625 * consisting of the following:
616 * (PFN) if the page is present. If there is a swap entry for the 626 *
617 * physical page, then an encoding of the swap file number and the 627 * Bits 0-55 page frame number (PFN) if present
618 * page's offset into the swap file are returned. If no page is 628 * Bits 0-4 swap type if swapped
619 * present at all, PM_NOT_PRESENT is returned. This allows determining 629 * Bits 5-55 swap offset if swapped
630 * Bits 55-60 page shift (page size = 1<<page shift)
631 * Bit 61 reserved for future use
632 * Bit 62 page swapped
633 * Bit 63 page present
634 *
635 * If the page is not present but in swap, then the PFN contains an
636 * encoding of the swap file number and the page's offset into the
637 * swap. Unmapped pages return a null PFN. This allows determining
620 * precisely which pages are mapped (or in swap) and comparing mapped 638 * precisely which pages are mapped (or in swap) and comparing mapped
621 * pages between processes. 639 * pages between processes.
622 * 640 *