~ubuntu-branches/ubuntu/quantal/linux-linaro-mx51/quantal

« back to all changes in this revision

Viewing changes to fs/proc/base.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-3o58a3c1bj7x00rs
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
#include <linux/security.h>
74
74
#include <linux/ptrace.h>
75
75
#include <linux/tracehook.h>
 
76
#include <linux/seccomp.h>
76
77
#include <linux/cgroup.h>
77
78
#include <linux/cpuset.h>
78
79
#include <linux/audit.h>
83
84
#include <linux/pid_namespace.h>
84
85
#include <linux/fs_struct.h>
85
86
#include <linux/slab.h>
 
87
#ifdef CONFIG_HARDWALL
 
88
#include <asm/hardwall.h>
 
89
#endif
86
90
#include "internal.h"
87
91
 
88
92
/* NOTE:
579
583
}
580
584
#endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
581
585
 
 
586
/*
 
587
 * Print out the current seccomp filter set for the task.
 
588
 */
 
589
#ifdef CONFIG_SECCOMP_FILTER
 
590
int proc_pid_seccomp_filter_show(struct seq_file *m, struct pid_namespace *ns,
 
591
                                 struct pid *pid, struct task_struct *task)
 
592
{
 
593
        struct seccomp_filters *filters;
 
594
 
 
595
        seq_printf(m, "Mode: %d\n", task->seccomp.mode);
 
596
        /* Avoid allowing other processes to incur too much added contention by
 
597
         * only acquiring a reference under the task-wide mutex.
 
598
         */
 
599
        if (mutex_lock_killable(&task->seccomp.filters_guard))
 
600
                return -1;
 
601
        filters = get_seccomp_filters(task->seccomp.filters);
 
602
        mutex_unlock(&task->seccomp.filters_guard);
 
603
 
 
604
        seccomp_show_filters(filters, m);
 
605
        put_seccomp_filters(filters);
 
606
        return 0;
 
607
}
 
608
#endif /* CONFIG_SECCOMP_FILTER */
 
609
 
582
610
/************************************************************************/
583
611
/*                       Here the fs part begins                        */
584
612
/************************************************************************/
600
628
        return allowed;
601
629
}
602
630
 
603
 
static int proc_setattr(struct dentry *dentry, struct iattr *attr)
 
631
int proc_setattr(struct dentry *dentry, struct iattr *attr)
604
632
{
605
633
        int error;
606
634
        struct inode *inode = dentry->d_inode;
894
922
        if (!task)
895
923
                goto out_no_task;
896
924
 
 
925
        copied = -ENOMEM;
 
926
        page = (char *)__get_free_page(GFP_TEMPORARY);
 
927
        if (!page)
 
928
                goto out_task;
 
929
 
897
930
        mm = check_mem_permission(task);
898
931
        copied = PTR_ERR(mm);
899
932
        if (IS_ERR(mm))
900
 
                goto out_task;
 
933
                goto out_free;
901
934
 
902
935
        copied = -EIO;
903
936
        if (file->private_data != (void *)((long)current->self_exec_id))
904
937
                goto out_mm;
905
938
 
906
 
        copied = -ENOMEM;
907
 
        page = (char *)__get_free_page(GFP_TEMPORARY);
908
 
        if (!page)
909
 
                goto out_mm;
910
 
 
911
939
        copied = 0;
912
940
        while (count > 0) {
913
941
                int this_len, retval;
929
957
                count -= retval;                        
930
958
        }
931
959
        *ppos = dst;
932
 
        free_page((unsigned long) page);
 
960
 
933
961
out_mm:
934
962
        mmput(mm);
 
963
out_free:
 
964
        free_page((unsigned long) page);
935
965
out_task:
936
966
        put_task_struct(task);
937
967
out_no_task:
1059
1089
{
1060
1090
        struct task_struct *task;
1061
1091
        char buffer[PROC_NUMBUF];
1062
 
        long oom_adjust;
 
1092
        int oom_adjust;
1063
1093
        unsigned long flags;
1064
1094
        int err;
1065
1095
 
1071
1101
                goto out;
1072
1102
        }
1073
1103
 
1074
 
        err = strict_strtol(strstrip(buffer), 0, &oom_adjust);
 
1104
        err = kstrtoint(strstrip(buffer), 0, &oom_adjust);
1075
1105
        if (err)
1076
1106
                goto out;
1077
1107
        if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) &&
1168
1198
        struct task_struct *task;
1169
1199
        char buffer[PROC_NUMBUF];
1170
1200
        unsigned long flags;
1171
 
        long oom_score_adj;
 
1201
        int oom_score_adj;
1172
1202
        int err;
1173
1203
 
1174
1204
        memset(buffer, 0, sizeof(buffer));
1179
1209
                goto out;
1180
1210
        }
1181
1211
 
1182
 
        err = strict_strtol(strstrip(buffer), 0, &oom_score_adj);
 
1212
        err = kstrtoint(strstrip(buffer), 0, &oom_score_adj);
1183
1213
        if (err)
1184
1214
                goto out;
1185
1215
        if (oom_score_adj < OOM_SCORE_ADJ_MIN ||
1468
1498
        struct inode *inode = file->f_path.dentry->d_inode;
1469
1499
        struct task_struct *p;
1470
1500
        char buffer[PROC_NUMBUF];
1471
 
        long nice;
 
1501
        int nice;
1472
1502
        int err;
1473
1503
 
1474
1504
        memset(buffer, 0, sizeof(buffer));
1477
1507
        if (copy_from_user(buffer, buf, count))
1478
1508
                return -EFAULT;
1479
1509
 
1480
 
        err = strict_strtol(strstrip(buffer), 0, &nice);
1481
 
        if (err)
1482
 
                return -EINVAL;
 
1510
        err = kstrtoint(strstrip(buffer), 0, &nice);
 
1511
        if (err < 0)
 
1512
                return err;
1483
1513
 
1484
1514
        p = get_proc_task(inode);
1485
1515
        if (!p)
1576
1606
        .release        = single_release,
1577
1607
};
1578
1608
 
1579
 
/*
1580
 
 * We added or removed a vma mapping the executable. The vmas are only mapped
1581
 
 * during exec and are not mapped with the mmap system call.
1582
 
 * Callers must hold down_write() on the mm's mmap_sem for these
1583
 
 */
1584
 
void added_exe_file_vma(struct mm_struct *mm)
1585
 
{
1586
 
        mm->num_exe_file_vmas++;
1587
 
}
1588
 
 
1589
 
void removed_exe_file_vma(struct mm_struct *mm)
1590
 
{
1591
 
        mm->num_exe_file_vmas--;
1592
 
        if ((mm->num_exe_file_vmas == 0) && mm->exe_file){
1593
 
                fput(mm->exe_file);
1594
 
                mm->exe_file = NULL;
1595
 
        }
1596
 
 
1597
 
}
1598
 
 
1599
 
void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
1600
 
{
1601
 
        if (new_exe_file)
1602
 
                get_file(new_exe_file);
1603
 
        if (mm->exe_file)
1604
 
                fput(mm->exe_file);
1605
 
        mm->exe_file = new_exe_file;
1606
 
        mm->num_exe_file_vmas = 0;
1607
 
}
1608
 
 
1609
 
struct file *get_mm_exe_file(struct mm_struct *mm)
1610
 
{
1611
 
        struct file *exe_file;
1612
 
 
1613
 
        /* We need mmap_sem to protect against races with removal of
1614
 
         * VM_EXECUTABLE vmas */
1615
 
        down_read(&mm->mmap_sem);
1616
 
        exe_file = mm->exe_file;
1617
 
        if (exe_file)
1618
 
                get_file(exe_file);
1619
 
        up_read(&mm->mmap_sem);
1620
 
        return exe_file;
1621
 
}
1622
 
 
1623
 
void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm)
1624
 
{
1625
 
        /* It's safe to write the exe_file pointer without exe_file_lock because
1626
 
         * this is called during fork when the task is not yet in /proc */
1627
 
        newmm->exe_file = get_mm_exe_file(oldmm);
1628
 
}
1629
 
 
1630
1609
static int proc_exe_link(struct inode *inode, struct path *exe_path)
1631
1610
{
1632
1611
        struct task_struct *task;
1736
1715
        return 0;
1737
1716
}
1738
1717
 
1739
 
 
1740
 
static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task)
 
1718
struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task)
1741
1719
{
1742
1720
        struct inode * inode;
1743
1721
        struct proc_inode *ei;
1779
1757
        return NULL;
1780
1758
}
1781
1759
 
1782
 
static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 
1760
int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1783
1761
{
1784
1762
        struct inode *inode = dentry->d_inode;
1785
1763
        struct task_struct *task;
1820
1798
 * made this apply to all per process world readable and executable
1821
1799
 * directories.
1822
1800
 */
1823
 
static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
 
1801
int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
1824
1802
{
1825
1803
        struct inode *inode;
1826
1804
        struct task_struct *task;
1862
1840
        return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
1863
1841
}
1864
1842
 
1865
 
static const struct dentry_operations pid_dentry_operations =
 
1843
const struct dentry_operations pid_dentry_operations =
1866
1844
{
1867
1845
        .d_revalidate   = pid_revalidate,
1868
1846
        .d_delete       = pid_delete_dentry,
1870
1848
 
1871
1849
/* Lookups */
1872
1850
 
1873
 
typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
1874
 
                                struct task_struct *, const void *);
1875
 
 
1876
1851
/*
1877
1852
 * Fill a directory entry.
1878
1853
 *
1885
1860
 * reported by readdir in sync with the inode numbers reported
1886
1861
 * by stat.
1887
1862
 */
1888
 
static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
1889
 
        char *name, int len,
 
1863
int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
 
1864
        const char *name, int len,
1890
1865
        instantiate_t instantiate, struct task_struct *task, const void *ptr)
1891
1866
{
1892
1867
        struct dentry *child, *dir = filp->f_path.dentry;
2219
2194
 */
2220
2195
static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
2221
2196
{
2222
 
        int rv;
2223
 
 
2224
 
        if (flags & IPERM_FLAG_RCU)
2225
 
                return -ECHILD;
2226
 
        rv = generic_permission(inode, mask, flags, NULL);
 
2197
        int rv = generic_permission(inode, mask, flags, NULL);
2227
2198
        if (rv == 0)
2228
2199
                return 0;
2229
2200
        if (task_pid(current) == proc_pid(inode))
2761
2732
{
2762
2733
        struct task_io_accounting acct = task->ioac;
2763
2734
        unsigned long flags;
 
2735
        int result;
 
2736
 
 
2737
        result = mutex_lock_killable(&task->signal->cred_guard_mutex);
 
2738
        if (result)
 
2739
                return result;
 
2740
 
 
2741
        if (!ptrace_may_access(task, PTRACE_MODE_READ)) {
 
2742
                result = -EACCES;
 
2743
                goto out_unlock;
 
2744
        }
2764
2745
 
2765
2746
        if (whole && lock_task_sighand(task, &flags)) {
2766
2747
                struct task_struct *t = task;
2771
2752
 
2772
2753
                unlock_task_sighand(task, &flags);
2773
2754
        }
2774
 
        return sprintf(buffer,
 
2755
        result = sprintf(buffer,
2775
2756
                        "rchar: %llu\n"
2776
2757
                        "wchar: %llu\n"
2777
2758
                        "syscr: %llu\n"
2786
2767
                        (unsigned long long)acct.read_bytes,
2787
2768
                        (unsigned long long)acct.write_bytes,
2788
2769
                        (unsigned long long)acct.cancelled_write_bytes);
 
2770
out_unlock:
 
2771
        mutex_unlock(&task->signal->cred_guard_mutex);
 
2772
        return result;
2789
2773
}
2790
2774
 
2791
2775
static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
2820
2804
        DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
2821
2805
        DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
2822
2806
        DIR("fdinfo",     S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
 
2807
        DIR("ns",         S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
2823
2808
#ifdef CONFIG_NET
2824
2809
        DIR("net",        S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations),
2825
2810
#endif
2838
2823
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
2839
2824
        INF("syscall",    S_IRUGO, proc_pid_syscall),
2840
2825
#endif
 
2826
#ifdef CONFIG_SECCOMP_FILTER
 
2827
        ONE("seccomp_filter",     S_IRUGO, proc_pid_seccomp_filter_show),
 
2828
#endif
2841
2829
        INF("cmdline",    S_IRUGO, proc_pid_cmdline),
2842
2830
        ONE("stat",       S_IRUGO, proc_tgid_stat),
2843
2831
        ONE("statm",      S_IRUGO, proc_pid_statm),
2892
2880
        REG("coredump_filter", S_IRUGO|S_IWUSR, proc_coredump_filter_operations),
2893
2881
#endif
2894
2882
#ifdef CONFIG_TASK_IO_ACCOUNTING
2895
 
        INF("io",       S_IRUGO, proc_tgid_io_accounting),
 
2883
        INF("io",       S_IRUSR, proc_tgid_io_accounting),
 
2884
#endif
 
2885
#ifdef CONFIG_HARDWALL
 
2886
        INF("hardwall",   S_IRUGO, proc_pid_hardwall),
2896
2887
#endif
2897
2888
};
2898
2889
 
3168
3159
static const struct pid_entry tid_base_stuff[] = {
3169
3160
        DIR("fd",        S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
3170
3161
        DIR("fdinfo",    S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
 
3162
        DIR("ns",        S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
3171
3163
        REG("environ",   S_IRUSR, proc_environ_operations),
3172
3164
        INF("auxv",      S_IRUSR, proc_pid_auxv),
3173
3165
        ONE("status",    S_IRUGO, proc_pid_status),
3180
3172
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
3181
3173
        INF("syscall",   S_IRUGO, proc_pid_syscall),
3182
3174
#endif
 
3175
#ifdef CONFIG_SECCOMP_FILTER
 
3176
        ONE("seccomp_filter",     S_IRUGO, proc_pid_seccomp_filter_show),
 
3177
#endif
3183
3178
        INF("cmdline",   S_IRUGO, proc_pid_cmdline),
3184
3179
        ONE("stat",      S_IRUGO, proc_tid_stat),
3185
3180
        ONE("statm",     S_IRUGO, proc_pid_statm),
3230
3225
        REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
3231
3226
#endif
3232
3227
#ifdef CONFIG_TASK_IO_ACCOUNTING
3233
 
        INF("io",       S_IRUGO, proc_tid_io_accounting),
 
3228
        INF("io",       S_IRUSR, proc_tid_io_accounting),
 
3229
#endif
 
3230
#ifdef CONFIG_HARDWALL
 
3231
        INF("hardwall",   S_IRUGO, proc_pid_hardwall),
3234
3232
#endif
3235
3233
};
3236
3234