random: use unlocked_ioctl
[safe/jmp/linux-2.6] / kernel / sys.c
index 7de9c98..e423d0d 100644 (file)
 #ifndef SET_ENDIAN
 # define SET_ENDIAN(a,b)       (-EINVAL)
 #endif
+#ifndef GET_TSC_CTL
+# define GET_TSC_CTL(a)                (-EINVAL)
+#endif
+#ifndef SET_TSC_CTL
+# define SET_TSC_CTL(a)                (-EINVAL)
+#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -991,17 +997,14 @@ asmlinkage long sys_getpgid(pid_t pid)
        else {
                int retval;
                struct task_struct *p;
-               struct pid_namespace *ns;
-
-               ns = current->nsproxy->pid_ns;
 
                read_lock(&tasklist_lock);
-               p = find_task_by_pid_ns(pid, ns);
+               p = find_task_by_vpid(pid);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getpgid(p);
                        if (!retval)
-                               retval = task_pgrp_nr_ns(p, ns);
+                               retval = task_pgrp_vnr(p);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1025,19 +1028,16 @@ asmlinkage long sys_getsid(pid_t pid)
        else {
                int retval;
                struct task_struct *p;
-               struct pid_namespace *ns;
 
-               ns = current->nsproxy->pid_ns;
-
-               read_lock(&tasklist_lock);
-               p = find_task_by_pid_ns(pid, ns);
+               rcu_read_lock();
+               p = find_task_by_vpid(pid);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getsid(p);
                        if (!retval)
-                               retval = task_session_nr_ns(p, ns);
+                               retval = task_session_vnr(p);
                }
-               read_unlock(&tasklist_lock);
+               rcu_read_unlock();
                return retval;
        }
 }
@@ -1056,11 +1056,8 @@ asmlinkage long sys_setsid(void)
 
        /* Fail if a process group id already exists that equals the
         * proposed session id.
-        *
-        * Don't check if session == 1, clone(CLONE_NEWPID) creates
-        * this group/session beforehand.
         */
-       if (session != 1 && pid_task(sid, PIDTYPE_PGID))
+       if (pid_task(sid, PIDTYPE_PGID))
                goto out;
 
        group_leader->signal->leader = 1;
@@ -1548,6 +1545,19 @@ out:
  *
  */
 
+static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r,
+                                    cputime_t *utimep, cputime_t *stimep)
+{
+       *utimep = cputime_add(*utimep, t->utime);
+       *stimep = cputime_add(*stimep, t->stime);
+       r->ru_nvcsw += t->nvcsw;
+       r->ru_nivcsw += t->nivcsw;
+       r->ru_minflt += t->min_flt;
+       r->ru_majflt += t->maj_flt;
+       r->ru_inblock += task_io_get_inblock(t);
+       r->ru_oublock += task_io_get_oublock(t);
+}
+
 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
 {
        struct task_struct *t;
@@ -1557,6 +1567,11 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
        memset((char *) r, 0, sizeof *r);
        utime = stime = cputime_zero;
 
+       if (who == RUSAGE_THREAD) {
+               accumulate_thread_rusage(p, r, &utime, &stime);
+               goto out;
+       }
+
        rcu_read_lock();
        if (!lock_task_sighand(p, &flags)) {
                rcu_read_unlock();
@@ -1589,14 +1604,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
                        r->ru_oublock += p->signal->oublock;
                        t = p;
                        do {
-                               utime = cputime_add(utime, t->utime);
-                               stime = cputime_add(stime, t->stime);
-                               r->ru_nvcsw += t->nvcsw;
-                               r->ru_nivcsw += t->nivcsw;
-                               r->ru_minflt += t->min_flt;
-                               r->ru_majflt += t->maj_flt;
-                               r->ru_inblock += task_io_get_inblock(t);
-                               r->ru_oublock += task_io_get_oublock(t);
+                               accumulate_thread_rusage(t, r, &utime, &stime);
                                t = next_thread(t);
                        } while (t != p);
                        break;
@@ -1608,6 +1616,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
        unlock_task_sighand(p, &flags);
        rcu_read_unlock();
 
+out:
        cputime_to_timeval(utime, &r->ru_utime);
        cputime_to_timeval(stime, &r->ru_stime);
 }
@@ -1621,7 +1630,8 @@ int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
 
 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
 {
-       if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
+       if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
+           who != RUSAGE_THREAD)
                return -EINVAL;
        return getrusage(current, who, ru);
 }
@@ -1635,10 +1645,9 @@ asmlinkage long sys_umask(int mask)
 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                          unsigned long arg4, unsigned long arg5)
 {
-       long error;
+       long uninitialized_var(error);
 
-       error = security_task_prctl(option, arg2, arg3, arg4, arg5);
-       if (error)
+       if (security_task_prctl(option, arg2, arg3, arg4, arg5, &error))
                return error;
 
        switch (option) {
@@ -1691,17 +1700,6 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                                error = -EINVAL;
                        break;
 
-               case PR_GET_KEEPCAPS:
-                       if (current->keep_capabilities)
-                               error = 1;
-                       break;
-               case PR_SET_KEEPCAPS:
-                       if (arg2 != 0 && arg2 != 1) {
-                               error = -EINVAL;
-                               break;
-                       }
-                       current->keep_capabilities = arg2;
-                       break;
                case PR_SET_NAME: {
                        struct task_struct *me = current;
                        unsigned char ncomm[sizeof(me->comm)];
@@ -1735,18 +1733,12 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                case PR_SET_SECCOMP:
                        error = prctl_set_seccomp(arg2);
                        break;
-
-               case PR_CAPBSET_READ:
-                       if (!cap_valid(arg2))
-                               return -EINVAL;
-                       return !!cap_raised(current->cap_bset, arg2);
-               case PR_CAPBSET_DROP:
-#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
-                       return cap_prctl_drop(arg2);
-#else
-                       return -EINVAL;
-#endif
-
+               case PR_GET_TSC:
+                       error = GET_TSC_CTL(arg2);
+                       break;
+               case PR_SET_TSC:
+                       error = SET_TSC_CTL(arg2);
+                       break;
                default:
                        error = -EINVAL;
                        break;