Merge branch 'genirq-v28-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[safe/jmp/linux-2.6] / fs / proc / base.c
index a891fe4..b5918ae 100644 (file)
@@ -53,6 +53,7 @@
 #include <linux/time.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
+#include <linux/task_io_accounting_ops.h>
 #include <linux/init.h>
 #include <linux/capability.h>
 #include <linux/file.h>
@@ -69,6 +70,7 @@
 #include <linux/mount.h>
 #include <linux/security.h>
 #include <linux/ptrace.h>
+#include <linux/tracehook.h>
 #include <linux/cgroup.h>
 #include <linux/cpuset.h>
 #include <linux/audit.h>
@@ -146,9 +148,6 @@ static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
        return count;
 }
 
-int maps_protect;
-EXPORT_SYMBOL(maps_protect);
-
 static struct fs_struct *get_fs_struct(struct task_struct *task)
 {
        struct fs_struct *fs;
@@ -162,7 +161,6 @@ static struct fs_struct *get_fs_struct(struct task_struct *task)
 
 static int get_nr_threads(struct task_struct *tsk)
 {
-       /* Must be called with the rcu_read_lock held */
        unsigned long flags;
        int count = 0;
 
@@ -231,10 +229,14 @@ static int check_mem_permission(struct task_struct *task)
         * If current is actively ptrace'ing, and would also be
         * permitted to freshly attach with ptrace now, permit it.
         */
-       if (task->parent == current && (task->ptrace & PT_PTRACED) &&
-           task_is_stopped_or_traced(task) &&
-           ptrace_may_access(task, PTRACE_MODE_ATTACH))
-               return 0;
+       if (task_is_stopped_or_traced(task)) {
+               int match;
+               rcu_read_lock();
+               match = (tracehook_tracer_task(task) == current);
+               rcu_read_unlock();
+               if (match && ptrace_may_access(task, PTRACE_MODE_ATTACH))
+                       return 0;
+       }
 
        /*
         * Noone else is allowed.
@@ -465,14 +467,10 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
 
        struct rlimit rlim[RLIM_NLIMITS];
 
-       rcu_read_lock();
-       if (!lock_task_sighand(task,&flags)) {
-               rcu_read_unlock();
+       if (!lock_task_sighand(task, &flags))
                return 0;
-       }
        memcpy(rlim, task->signal->rlim, sizeof(struct rlimit) * RLIM_NLIMITS);
        unlock_task_sighand(task, &flags);
-       rcu_read_unlock();
 
        /*
         * print the file header
@@ -504,6 +502,26 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
        return count;
 }
 
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+static int proc_pid_syscall(struct task_struct *task, char *buffer)
+{
+       long nr;
+       unsigned long args[6], sp, pc;
+
+       if (task_current_syscall(task, &nr, args, 6, &sp, &pc))
+               return sprintf(buffer, "running\n");
+
+       if (nr < 0)
+               return sprintf(buffer, "%ld 0x%lx 0x%lx\n", nr, sp, pc);
+
+       return sprintf(buffer,
+                      "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
+                      nr,
+                      args[0], args[1], args[2], args[3], args[4], args[5],
+                      sp, pc);
+}
+#endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
+
 /************************************************************************/
 /*                       Here the fs part begins                        */
 /************************************************************************/
@@ -1834,8 +1852,7 @@ static const struct file_operations proc_fd_operations = {
  * /proc/pid/fd needs a special permission handler so that a process can still
  * access /proc/self/fd after it has executed a setuid().
  */
-static int proc_fd_permission(struct inode *inode, int mask,
-                               struct nameidata *nd)
+static int proc_fd_permission(struct inode *inode, int mask)
 {
        int rv;
 
@@ -2378,53 +2395,18 @@ static int proc_base_fill_cache(struct file *filp, void *dirent,
 #ifdef CONFIG_TASK_IO_ACCOUNTING
 static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
 {
-       u64 rchar, wchar, syscr, syscw;
-       struct task_io_accounting ioac;
-
-       if (!whole) {
-               rchar = task->rchar;
-               wchar = task->wchar;
-               syscr = task->syscr;
-               syscw = task->syscw;
-               memcpy(&ioac, &task->ioac, sizeof(ioac));
-       } else {
-               unsigned long flags;
-               struct task_struct *t = task;
-               rchar = wchar = syscr = syscw = 0;
-               memset(&ioac, 0, sizeof(ioac));
-
-               rcu_read_lock();
-               do {
-                       rchar += t->rchar;
-                       wchar += t->wchar;
-                       syscr += t->syscr;
-                       syscw += t->syscw;
-
-                       ioac.read_bytes += t->ioac.read_bytes;
-                       ioac.write_bytes += t->ioac.write_bytes;
-                       ioac.cancelled_write_bytes +=
-                                       t->ioac.cancelled_write_bytes;
-                       t = next_thread(t);
-               } while (t != task);
-               rcu_read_unlock();
-
-               if (lock_task_sighand(task, &flags)) {
-                       struct signal_struct *sig = task->signal;
+       struct task_io_accounting acct = task->ioac;
+       unsigned long flags;
 
-                       rchar += sig->rchar;
-                       wchar += sig->wchar;
-                       syscr += sig->syscr;
-                       syscw += sig->syscw;
+       if (whole && lock_task_sighand(task, &flags)) {
+               struct task_struct *t = task;
 
-                       ioac.read_bytes += sig->ioac.read_bytes;
-                       ioac.write_bytes += sig->ioac.write_bytes;
-                       ioac.cancelled_write_bytes +=
-                                       sig->ioac.cancelled_write_bytes;
+               task_io_accounting_add(&acct, &task->signal->ioac);
+               while_each_thread(task, t)
+                       task_io_accounting_add(&acct, &t->ioac);
 
-                       unlock_task_sighand(task, &flags);
-               }
+               unlock_task_sighand(task, &flags);
        }
-
        return sprintf(buffer,
                        "rchar: %llu\n"
                        "wchar: %llu\n"
@@ -2433,13 +2415,13 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
                        "read_bytes: %llu\n"
                        "write_bytes: %llu\n"
                        "cancelled_write_bytes: %llu\n",
-                       (unsigned long long)rchar,
-                       (unsigned long long)wchar,
-                       (unsigned long long)syscr,
-                       (unsigned long long)syscw,
-                       (unsigned long long)ioac.read_bytes,
-                       (unsigned long long)ioac.write_bytes,
-                       (unsigned long long)ioac.cancelled_write_bytes);
+                       (unsigned long long)acct.rchar,
+                       (unsigned long long)acct.wchar,
+                       (unsigned long long)acct.syscr,
+                       (unsigned long long)acct.syscw,
+                       (unsigned long long)acct.read_bytes,
+                       (unsigned long long)acct.write_bytes,
+                       (unsigned long long)acct.cancelled_write_bytes);
 }
 
 static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
@@ -2453,6 +2435,13 @@ static int proc_tgid_io_accounting(struct task_struct *task, char *buffer)
 }
 #endif /* CONFIG_TASK_IO_ACCOUNTING */
 
+static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *task)
+{
+       seq_printf(m, "%08x\n", task->personality);
+       return 0;
+}
+
 /*
  * Thread groups
  */
@@ -2469,10 +2458,14 @@ static const struct pid_entry tgid_base_stuff[] = {
        REG("environ",    S_IRUSR, environ),
        INF("auxv",       S_IRUSR, pid_auxv),
        ONE("status",     S_IRUGO, pid_status),
+       ONE("personality", S_IRUSR, pid_personality),
        INF("limits",     S_IRUSR, pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
        REG("sched",      S_IRUGO|S_IWUSR, pid_sched),
 #endif
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+       INF("syscall",    S_IRUSR, pid_syscall),
+#endif
        INF("cmdline",    S_IRUGO, pid_cmdline),
        ONE("stat",       S_IRUGO, tgid_stat),
        ONE("statm",      S_IRUGO, pid_statm),
@@ -2801,10 +2794,14 @@ static const struct pid_entry tid_base_stuff[] = {
        REG("environ",   S_IRUSR, environ),
        INF("auxv",      S_IRUSR, pid_auxv),
        ONE("status",    S_IRUGO, pid_status),
+       ONE("personality", S_IRUSR, pid_personality),
        INF("limits",    S_IRUSR, pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
        REG("sched",     S_IRUGO|S_IWUSR, pid_sched),
 #endif
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+       INF("syscall",   S_IRUSR, pid_syscall),
+#endif
        INF("cmdline",   S_IRUGO, pid_cmdline),
        ONE("stat",      S_IRUGO, tid_stat),
        ONE("statm",     S_IRUGO, pid_statm),
@@ -3092,9 +3089,7 @@ static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
        generic_fillattr(inode, stat);
 
        if (p) {
-               rcu_read_lock();
                stat->nlink += get_nr_threads(p);
-               rcu_read_unlock();
                put_task_struct(p);
        }