LCOV - code coverage report
Current view: top level - kernel - sys.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 457 728 62.8 %
Date: 2014-02-18 Functions: 48 56 85.7 %
Branches: 404 741 54.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *  linux/kernel/sys.c
       3                 :            :  *
       4                 :            :  *  Copyright (C) 1991, 1992  Linus Torvalds
       5                 :            :  */
       6                 :            : 
       7                 :            : #include <linux/export.h>
       8                 :            : #include <linux/mm.h>
       9                 :            : #include <linux/utsname.h>
      10                 :            : #include <linux/mman.h>
      11                 :            : #include <linux/reboot.h>
      12                 :            : #include <linux/prctl.h>
      13                 :            : #include <linux/highuid.h>
      14                 :            : #include <linux/fs.h>
      15                 :            : #include <linux/kmod.h>
      16                 :            : #include <linux/perf_event.h>
      17                 :            : #include <linux/resource.h>
      18                 :            : #include <linux/kernel.h>
      19                 :            : #include <linux/workqueue.h>
      20                 :            : #include <linux/capability.h>
      21                 :            : #include <linux/device.h>
      22                 :            : #include <linux/key.h>
      23                 :            : #include <linux/times.h>
      24                 :            : #include <linux/posix-timers.h>
      25                 :            : #include <linux/security.h>
      26                 :            : #include <linux/dcookies.h>
      27                 :            : #include <linux/suspend.h>
      28                 :            : #include <linux/tty.h>
      29                 :            : #include <linux/signal.h>
      30                 :            : #include <linux/cn_proc.h>
      31                 :            : #include <linux/getcpu.h>
      32                 :            : #include <linux/task_io_accounting_ops.h>
      33                 :            : #include <linux/seccomp.h>
      34                 :            : #include <linux/cpu.h>
      35                 :            : #include <linux/personality.h>
      36                 :            : #include <linux/ptrace.h>
      37                 :            : #include <linux/fs_struct.h>
      38                 :            : #include <linux/file.h>
      39                 :            : #include <linux/mount.h>
      40                 :            : #include <linux/gfp.h>
      41                 :            : #include <linux/syscore_ops.h>
      42                 :            : #include <linux/version.h>
      43                 :            : #include <linux/ctype.h>
      44                 :            : #include <linux/mm.h>
      45                 :            : #include <linux/mempolicy.h>
      46                 :            : 
      47                 :            : #include <linux/compat.h>
      48                 :            : #include <linux/syscalls.h>
      49                 :            : #include <linux/kprobes.h>
      50                 :            : #include <linux/user_namespace.h>
      51                 :            : #include <linux/binfmts.h>
      52                 :            : 
      53                 :            : #include <linux/sched.h>
      54                 :            : #include <linux/rcupdate.h>
      55                 :            : #include <linux/uidgid.h>
      56                 :            : #include <linux/cred.h>
      57                 :            : 
      58                 :            : #include <linux/kmsg_dump.h>
      59                 :            : /* Move somewhere else to avoid recompiling? */
      60                 :            : #include <generated/utsrelease.h>
      61                 :            : 
      62                 :            : #include <asm/uaccess.h>
      63                 :            : #include <asm/io.h>
      64                 :            : #include <asm/unistd.h>
      65                 :            : 
      66                 :            : #ifndef SET_UNALIGN_CTL
      67                 :            : # define SET_UNALIGN_CTL(a,b)   (-EINVAL)
      68                 :            : #endif
      69                 :            : #ifndef GET_UNALIGN_CTL
      70                 :            : # define GET_UNALIGN_CTL(a,b)   (-EINVAL)
      71                 :            : #endif
      72                 :            : #ifndef SET_FPEMU_CTL
      73                 :            : # define SET_FPEMU_CTL(a,b)     (-EINVAL)
      74                 :            : #endif
      75                 :            : #ifndef GET_FPEMU_CTL
      76                 :            : # define GET_FPEMU_CTL(a,b)     (-EINVAL)
      77                 :            : #endif
      78                 :            : #ifndef SET_FPEXC_CTL
      79                 :            : # define SET_FPEXC_CTL(a,b)     (-EINVAL)
      80                 :            : #endif
      81                 :            : #ifndef GET_FPEXC_CTL
      82                 :            : # define GET_FPEXC_CTL(a,b)     (-EINVAL)
      83                 :            : #endif
      84                 :            : #ifndef GET_ENDIAN
      85                 :            : # define GET_ENDIAN(a,b)        (-EINVAL)
      86                 :            : #endif
      87                 :            : #ifndef SET_ENDIAN
      88                 :            : # define SET_ENDIAN(a,b)        (-EINVAL)
      89                 :            : #endif
      90                 :            : #ifndef GET_TSC_CTL
      91                 :            : # define GET_TSC_CTL(a)         (-EINVAL)
      92                 :            : #endif
      93                 :            : #ifndef SET_TSC_CTL
      94                 :            : # define SET_TSC_CTL(a)         (-EINVAL)
      95                 :            : #endif
      96                 :            : 
      97                 :            : /*
      98                 :            :  * this is where the system-wide overflow UID and GID are defined, for
      99                 :            :  * architectures that now have 32-bit UID/GID but didn't in the past
     100                 :            :  */
     101                 :            : 
     102                 :            : int overflowuid = DEFAULT_OVERFLOWUID;
     103                 :            : int overflowgid = DEFAULT_OVERFLOWGID;
     104                 :            : 
     105                 :            : EXPORT_SYMBOL(overflowuid);
     106                 :            : EXPORT_SYMBOL(overflowgid);
     107                 :            : 
     108                 :            : /*
     109                 :            :  * the same as above, but for filesystems which can only store a 16-bit
     110                 :            :  * UID and GID. as such, this is needed on all architectures
     111                 :            :  */
     112                 :            : 
     113                 :            : int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
     114                 :            : int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
     115                 :            : 
     116                 :            : EXPORT_SYMBOL(fs_overflowuid);
     117                 :            : EXPORT_SYMBOL(fs_overflowgid);
     118                 :            : 
     119                 :            : /*
     120                 :            :  * Returns true if current's euid is same as p's uid or euid,
     121                 :            :  * or has CAP_SYS_NICE to p's user_ns.
     122                 :            :  *
     123                 :            :  * Called with rcu_read_lock, creds are safe
     124                 :            :  */
     125                 :          0 : static bool set_one_prio_perm(struct task_struct *p)
     126                 :            : {
     127                 :       1543 :         const struct cred *cred = current_cred(), *pcred = __task_cred(p);
     128                 :            : 
     129 [ +  + ][ +  + ]:       1543 :         if (uid_eq(pcred->uid,  cred->euid) ||
     130                 :          2 :             uid_eq(pcred->euid, cred->euid))
     131                 :            :                 return true;
     132         [ +  - ]:          1 :         if (ns_capable(pcred->user_ns, CAP_SYS_NICE))
     133                 :            :                 return true;
     134                 :          1 :         return false;
     135                 :            : }
     136                 :            : 
     137                 :            : /*
     138                 :            :  * set the priority of a task
     139                 :            :  * - the caller must hold the RCU read lock
     140                 :            :  */
     141                 :          0 : static int set_one_prio(struct task_struct *p, int niceval, int error)
     142                 :            : {
     143                 :            :         int no_nice;
     144                 :            : 
     145         [ +  + ]:       1543 :         if (!set_one_prio_perm(p)) {
     146                 :            :                 error = -EPERM;
     147                 :            :                 goto out;
     148                 :            :         }
     149 [ +  + ][ +  + ]:       1542 :         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
     150                 :            :                 error = -EACCES;
     151                 :            :                 goto out;
     152                 :            :         }
     153                 :       1540 :         no_nice = security_task_setnice(p, niceval);
     154         [ +  - ]:       1540 :         if (no_nice) {
     155                 :            :                 error = no_nice;
     156                 :            :                 goto out;
     157                 :            :         }
     158         [ +  - ]:       1540 :         if (error == -ESRCH)
     159                 :            :                 error = 0;
     160                 :       1540 :         set_user_nice(p, niceval);
     161                 :            : out:
     162                 :       1543 :         return error;
     163                 :            : }
     164                 :            : 
     165                 :          0 : SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
     166                 :            : {
     167                 :            :         struct task_struct *g, *p;
     168                 :            :         struct user_struct *user;
     169                 :       1545 :         const struct cred *cred = current_cred();
     170                 :            :         int error = -EINVAL;
     171                 :            :         struct pid *pgrp;
     172                 :            :         kuid_t uid;
     173                 :            : 
     174         [ +  + ]:       1545 :         if (which > PRIO_USER || which < PRIO_PROCESS)
     175                 :            :                 goto out;
     176                 :            : 
     177                 :            :         /* normalize: avoid signed division (rounding problems) */
     178                 :            :         error = -ESRCH;
     179         [ -  + ]:       1544 :         if (niceval < -20)
     180                 :            :                 niceval = -20;
     181         [ +  + ]:       1544 :         if (niceval > 19)
     182                 :            :                 niceval = 19;
     183                 :            : 
     184                 :            :         rcu_read_lock();
     185                 :       1544 :         read_lock(&tasklist_lock);
     186   [ +  -  -  - ]:       1544 :         switch (which) {
     187                 :            :                 case PRIO_PROCESS:
     188         [ +  + ]:       1544 :                         if (who)
     189                 :          2 :                                 p = find_task_by_vpid(who);
     190                 :            :                         else
     191                 :       1542 :                                 p = current;
     192         [ +  + ]:       1544 :                         if (p)
     193                 :       1543 :                                 error = set_one_prio(p, niceval, error);
     194                 :            :                         break;
     195                 :            :                 case PRIO_PGRP:
     196         [ #  # ]:          0 :                         if (who)
     197                 :          0 :                                 pgrp = find_vpid(who);
     198                 :            :                         else
     199                 :          0 :                                 pgrp = task_pgrp(current);
     200 [ #  # ][ #  # ]:          0 :                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
         [ #  # ][ #  # ]
     201                 :          0 :                                 error = set_one_prio(p, niceval, error);
     202         [ #  # ]:          0 :                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
     203                 :            :                         break;
     204                 :            :                 case PRIO_USER:
     205                 :          0 :                         uid = make_kuid(cred->user_ns, who);
     206                 :          0 :                         user = cred->user;
     207         [ #  # ]:          0 :                         if (!who)
     208                 :          0 :                                 uid = cred->uid;
     209 [ #  # ][ #  # ]:          0 :                         else if (!uid_eq(uid, cred->uid) &&
     210                 :            :                                  !(user = find_user(uid)))
     211                 :            :                                 goto out_unlock;        /* No processes for this user */
     212                 :            : 
     213         [ #  # ]:          0 :                         do_each_thread(g, p) {
     214         [ #  # ]:          0 :                                 if (uid_eq(task_uid(p), uid))
     215                 :          0 :                                         error = set_one_prio(p, niceval, error);
     216         [ #  # ]:          0 :                         } while_each_thread(g, p);
     217         [ #  # ]:          0 :                         if (!uid_eq(uid, cred->uid))
     218                 :          0 :                                 free_uid(user);         /* For find_user() */
     219                 :            :                         break;
     220                 :            :         }
     221                 :            : out_unlock:
     222                 :            :         read_unlock(&tasklist_lock);
     223                 :            :         rcu_read_unlock();
     224                 :            : out:
     225                 :            :         return error;
     226                 :            : }
     227                 :            : 
     228                 :            : /*
     229                 :            :  * Ugh. To avoid negative return values, "getpriority()" will
     230                 :            :  * not return the normal nice-value, but a negated value that
     231                 :            :  * has been offset by 20 (ie it returns 40..1 instead of -20..19)
     232                 :            :  * to stay compatible.
     233                 :            :  */
     234                 :          0 : SYSCALL_DEFINE2(getpriority, int, which, int, who)
     235                 :            : {
     236                 :            :         struct task_struct *g, *p;
     237                 :            :         struct user_struct *user;
     238                 :       2238 :         const struct cred *cred = current_cred();
     239                 :            :         long niceval, retval = -ESRCH;
     240                 :            :         struct pid *pgrp;
     241                 :            :         kuid_t uid;
     242                 :            : 
     243         [ +  + ]:       2238 :         if (which > PRIO_USER || which < PRIO_PROCESS)
     244                 :            :                 return -EINVAL;
     245                 :            : 
     246                 :            :         rcu_read_lock();
     247                 :       2237 :         read_lock(&tasklist_lock);
     248   [ +  +  +  - ]:       2237 :         switch (which) {
     249                 :            :                 case PRIO_PROCESS:
     250         [ +  + ]:       2233 :                         if (who)
     251                 :          1 :                                 p = find_task_by_vpid(who);
     252                 :            :                         else
     253                 :       2232 :                                 p = current;
     254         [ +  + ]:       2233 :                         if (p) {
     255                 :       2232 :                                 niceval = 20 - task_nice(p);
     256         [ +  - ]:       2232 :                                 if (niceval > retval)
     257                 :            :                                         retval = niceval;
     258                 :            :                         }
     259                 :            :                         break;
     260                 :            :                 case PRIO_PGRP:
     261         [ +  + ]:          2 :                         if (who)
     262                 :          1 :                                 pgrp = find_vpid(who);
     263                 :            :                         else
     264                 :          1 :                                 pgrp = task_pgrp(current);
     265 [ +  + ][ +  - ]:          3 :                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
         [ -  + ][ +  + ]
     266                 :          1 :                                 niceval = 20 - task_nice(p);
     267         [ +  - ]:       2239 :                                 if (niceval > retval)
     268                 :            :                                         retval = niceval;
     269         [ -  + ]:          1 :                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
     270                 :            :                         break;
     271                 :            :                 case PRIO_USER:
     272                 :          2 :                         uid = make_kuid(cred->user_ns, who);
     273                 :          2 :                         user = cred->user;
     274         [ +  + ]:          2 :                         if (!who)
     275                 :          1 :                                 uid = cred->uid;
     276 [ +  - ][ -  + ]:         89 :                         else if (!uid_eq(uid, cred->uid) &&
     277                 :            :                                  !(user = find_user(uid)))
     278                 :            :                                 goto out_unlock;        /* No processes for this user */
     279                 :            : 
     280         [ +  + ]:         88 :                         do_each_thread(g, p) {
     281         [ +  + ]:         90 :                                 if (uid_eq(task_uid(p), uid)) {
     282                 :         86 :                                         niceval = 20 - task_nice(p);
     283         [ +  + ]:         86 :                                         if (niceval > retval)
     284                 :            :                                                 retval = niceval;
     285                 :            :                                 }
     286         [ +  + ]:         90 :                         } while_each_thread(g, p);
     287         [ -  + ]:          1 :                         if (!uid_eq(uid, cred->uid))
     288                 :          0 :                                 free_uid(user);         /* for find_user() */
     289                 :            :                         break;
     290                 :            :         }
     291                 :            : out_unlock:
     292                 :            :         read_unlock(&tasklist_lock);
     293                 :            :         rcu_read_unlock();
     294                 :            : 
     295                 :            :         return retval;
     296                 :            : }
     297                 :            : 
     298                 :            : /*
     299                 :            :  * Unprivileged users may change the real gid to the effective gid
     300                 :            :  * or vice versa.  (BSD-style)
     301                 :            :  *
     302                 :            :  * If you set the real gid at all, or set the effective gid to a value not
     303                 :            :  * equal to the real gid, then the saved gid is set to the new effective gid.
     304                 :            :  *
     305                 :            :  * This makes it possible for a setgid program to completely drop its
     306                 :            :  * privileges, which is often a useful assertion to make when you are doing
     307                 :            :  * a security audit over a program.
     308                 :            :  *
     309                 :            :  * The general idea is that a program which uses just setregid() will be
     310                 :            :  * 100% compatible with BSD.  A program which uses just setgid() will be
     311                 :            :  * 100% compatible with POSIX with saved IDs. 
     312                 :            :  *
     313                 :            :  * SMP: There are not races, the GIDs are checked only by filesystem
     314                 :            :  *      operations (as far as semantic preservation is concerned).
     315                 :            :  */
     316                 :          0 : SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
     317                 :            : {
     318                 :            :         struct user_namespace *ns = current_user_ns();
     319                 :            :         const struct cred *old;
     320                 :            :         struct cred *new;
     321                 :            :         int retval;
     322                 :            :         kgid_t krgid, kegid;
     323                 :            : 
     324                 :            :         krgid = make_kgid(ns, rgid);
     325                 :            :         kegid = make_kgid(ns, egid);
     326                 :            : 
     327 [ +  + ][ +  - ]:         57 :         if ((rgid != (gid_t) -1) && !gid_valid(krgid))
     328                 :            :                 return -EINVAL;
     329 [ +  + ][ +  - ]:         57 :         if ((egid != (gid_t) -1) && !gid_valid(kegid))
     330                 :            :                 return -EINVAL;
     331                 :            : 
     332                 :         57 :         new = prepare_creds();
     333         [ +  - ]:         57 :         if (!new)
     334                 :            :                 return -ENOMEM;
     335                 :         57 :         old = current_cred();
     336                 :            : 
     337                 :            :         retval = -EPERM;
     338         [ +  + ]:         57 :         if (rgid != (gid_t) -1) {
     339 [ +  + ][ +  + ]:         30 :                 if (gid_eq(old->gid, krgid) ||
     340         [ +  + ]:         12 :                     gid_eq(old->egid, krgid) ||
     341                 :         12 :                     ns_capable(old->user_ns, CAP_SETGID))
     342                 :         26 :                         new->gid = krgid;
     343                 :            :                 else
     344                 :            :                         goto error;
     345                 :            :         }
     346         [ +  + ]:         53 :         if (egid != (gid_t) -1) {
     347 [ +  + ][ +  + ]:         33 :                 if (gid_eq(old->gid, kegid) ||
     348         [ +  + ]:         11 :                     gid_eq(old->egid, kegid) ||
     349         [ +  + ]:          9 :                     gid_eq(old->sgid, kegid) ||
     350                 :          9 :                     ns_capable(old->user_ns, CAP_SETGID))
     351                 :         31 :                         new->egid = kegid;
     352                 :            :                 else
     353                 :            :                         goto error;
     354                 :            :         }
     355                 :            : 
     356 [ +  + ][ +  + ]:         51 :         if (rgid != (gid_t) -1 ||
     357         [ +  + ]:         17 :             (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
     358                 :         31 :                 new->sgid = new->egid;
     359                 :          0 :         new->fsgid = new->egid;
     360                 :            : 
     361                 :         51 :         return commit_creds(new);
     362                 :            : 
     363                 :            : error:
     364                 :          6 :         abort_creds(new);
     365                 :            :         return retval;
     366                 :            : }
     367                 :            : 
     368                 :            : /*
     369                 :            :  * setgid() is implemented like SysV w/ SAVED_IDS 
     370                 :            :  *
     371                 :            :  * SMP: Same implicit races as above.
     372                 :            :  */
     373                 :          0 : SYSCALL_DEFINE1(setgid, gid_t, gid)
     374                 :            : {
     375                 :            :         struct user_namespace *ns = current_user_ns();
     376                 :            :         const struct cred *old;
     377                 :            :         struct cred *new;
     378                 :            :         int retval;
     379                 :            :         kgid_t kgid;
     380                 :            : 
     381                 :            :         kgid = make_kgid(ns, gid);
     382         [ +  - ]:        669 :         if (!gid_valid(kgid))
     383                 :            :                 return -EINVAL;
     384                 :            : 
     385                 :        669 :         new = prepare_creds();
     386         [ +  - ]:        669 :         if (!new)
     387                 :            :                 return -ENOMEM;
     388                 :        669 :         old = current_cred();
     389                 :            : 
     390                 :            :         retval = -EPERM;
     391         [ +  + ]:        669 :         if (ns_capable(old->user_ns, CAP_SETGID))
     392                 :        666 :                 new->gid = new->egid = new->sgid = new->fsgid = kgid;
     393 [ +  - ][ -  + ]:          3 :         else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
     394                 :          0 :                 new->egid = new->fsgid = kgid;
     395                 :            :         else
     396                 :            :                 goto error;
     397                 :            : 
     398                 :        666 :         return commit_creds(new);
     399                 :            : 
     400                 :            : error:
     401                 :          3 :         abort_creds(new);
     402                 :            :         return retval;
     403                 :            : }
     404                 :            : 
     405                 :            : /*
     406                 :            :  * change the user struct in a credentials set to match the new UID
     407                 :            :  */
     408                 :        331 : static int set_user(struct cred *new)
     409                 :            : {
     410                 :            :         struct user_struct *new_user;
     411                 :            : 
     412                 :        331 :         new_user = alloc_uid(new->uid);
     413         [ +  - ]:        331 :         if (!new_user)
     414                 :            :                 return -EAGAIN;
     415                 :            : 
     416                 :            :         /*
     417                 :            :          * We don't fail in case of NPROC limit excess here because too many
     418                 :            :          * poorly written programs don't check set*uid() return code, assuming
     419                 :            :          * it never fails if called by root.  We may still enforce NPROC limit
     420                 :            :          * for programs doing set*uid()+execve() by harmlessly deferring the
     421                 :            :          * failure to the execve() stage.
     422                 :            :          */
     423 [ -  + ][ #  # ]:        331 :         if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) &&
     424                 :            :                         new_user != INIT_USER)
     425                 :          0 :                 current->flags |= PF_NPROC_EXCEEDED;
     426                 :            :         else
     427                 :        331 :                 current->flags &= ~PF_NPROC_EXCEEDED;
     428                 :            : 
     429                 :        331 :         free_uid(new->user);
     430                 :        331 :         new->user = new_user;
     431                 :            :         return 0;
     432                 :            : }
     433                 :            : 
     434                 :            : /*
     435                 :            :  * Unprivileged users may change the real uid to the effective uid
     436                 :            :  * or vice versa.  (BSD-style)
     437                 :            :  *
     438                 :            :  * If you set the real uid at all, or set the effective uid to a value not
     439                 :            :  * equal to the real uid, then the saved uid is set to the new effective uid.
     440                 :            :  *
     441                 :            :  * This makes it possible for a setuid program to completely drop its
     442                 :            :  * privileges, which is often a useful assertion to make when you are doing
     443                 :            :  * a security audit over a program.
     444                 :            :  *
     445                 :            :  * The general idea is that a program which uses just setreuid() will be
     446                 :            :  * 100% compatible with BSD.  A program which uses just setuid() will be
     447                 :            :  * 100% compatible with POSIX with saved IDs. 
     448                 :            :  */
     449                 :          0 : SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
     450                 :            : {
     451                 :            :         struct user_namespace *ns = current_user_ns();
     452                 :            :         const struct cred *old;
     453                 :            :         struct cred *new;
     454                 :            :         int retval;
     455                 :            :         kuid_t kruid, keuid;
     456                 :            : 
     457                 :            :         kruid = make_kuid(ns, ruid);
     458                 :            :         keuid = make_kuid(ns, euid);
     459                 :            : 
     460 [ +  + ][ +  - ]:        116 :         if ((ruid != (uid_t) -1) && !uid_valid(kruid))
     461                 :            :                 return -EINVAL;
     462 [ +  + ][ +  - ]:        116 :         if ((euid != (uid_t) -1) && !uid_valid(keuid))
     463                 :            :                 return -EINVAL;
     464                 :            : 
     465                 :        116 :         new = prepare_creds();
     466         [ +  - ]:        116 :         if (!new)
     467                 :            :                 return -ENOMEM;
     468                 :        116 :         old = current_cred();
     469                 :            : 
     470                 :            :         retval = -EPERM;
     471         [ +  + ]:        116 :         if (ruid != (uid_t) -1) {
     472                 :         57 :                 new->uid = kruid;
     473 [ +  + ][ +  + ]:         57 :                 if (!uid_eq(old->uid, kruid) &&
     474            [ + ]:         35 :                     !uid_eq(old->euid, kruid) &&
     475                 :         35 :                     !ns_capable(old->user_ns, CAP_SETUID))
     476                 :            :                         goto error;
     477                 :            :         }
     478                 :            : 
     479         [ +  + ]:        216 :         if (euid != (uid_t) -1) {
     480                 :         76 :                 new->euid = keuid;
     481 [ +  + ][ +  - ]:         76 :                 if (!uid_eq(old->uid, keuid) &&
     482         [ +  + ]:         44 :                     !uid_eq(old->euid, keuid) &&
     483         [ +  + ]:         38 :                     !uid_eq(old->suid, keuid) &&
     484                 :         38 :                     !ns_capable(old->user_ns, CAP_SETUID))
     485                 :            :                         goto error;
     486                 :            :         }
     487                 :            : 
     488         [ +  + ]:         88 :         if (!uid_eq(new->uid, old->uid)) {
     489                 :         27 :                 retval = set_user(new);
     490         [ +  - ]:         27 :                 if (retval < 0)
     491                 :            :                         goto error;
     492                 :            :         }
     493 [ +  + ][ +  + ]:         88 :         if (ruid != (uid_t) -1 ||
     494         [ +  + ]:         41 :             (euid != (uid_t) -1 && !uid_eq(keuid, old->uid)))
     495                 :         58 :                 new->suid = new->euid;
     496                 :         88 :         new->fsuid = new->euid;
     497                 :            : 
     498                 :         88 :         retval = security_task_fix_setuid(new, old, LSM_SETID_RE);
     499         [ +  - ]:         88 :         if (retval < 0)
     500                 :            :                 goto error;
     501                 :            : 
     502                 :         88 :         return commit_creds(new);
     503                 :            : 
     504                 :            : error:
     505                 :          0 :         abort_creds(new);
     506                 :            :         return retval;
     507                 :            : }
     508                 :            :                 
     509                 :            : /*
     510                 :            :  * setuid() is implemented like SysV with SAVED_IDS 
     511                 :            :  * 
     512                 :            :  * Note that SAVED_ID's is deficient in that a setuid root program
     513                 :            :  * like sendmail, for example, cannot set its uid to be a normal 
     514                 :            :  * user and then switch back, because if you're root, setuid() sets
     515                 :            :  * the saved uid too.  If you don't like this, blame the bright people
     516                 :            :  * in the POSIX committee and/or USG.  Note that the BSD-style setreuid()
     517                 :            :  * will allow a root program to temporarily drop privileges and be able to
     518                 :            :  * regain them by swapping the real and effective uid.  
     519                 :            :  */
     520                 :          0 : SYSCALL_DEFINE1(setuid, uid_t, uid)
     521                 :            : {
     522                 :            :         struct user_namespace *ns = current_user_ns();
     523                 :            :         const struct cred *old;
     524                 :            :         struct cred *new;
     525                 :            :         int retval;
     526                 :            :         kuid_t kuid;
     527                 :            : 
     528                 :            :         kuid = make_kuid(ns, uid);
     529         [ +  - ]:        729 :         if (!uid_valid(kuid))
     530                 :            :                 return -EINVAL;
     531                 :            : 
     532                 :        729 :         new = prepare_creds();
     533         [ +  - ]:        729 :         if (!new)
     534                 :            :                 return -ENOMEM;
     535                 :        729 :         old = current_cred();
     536                 :            : 
     537                 :            :         retval = -EPERM;
     538         [ +  + ]:        729 :         if (ns_capable(old->user_ns, CAP_SETUID)) {
     539                 :        722 :                 new->suid = new->uid = kuid;
     540         [ +  + ]:        722 :                 if (!uid_eq(kuid, old->uid)) {
     541                 :        133 :                         retval = set_user(new);
     542         [ +  - ]:        133 :                         if (retval < 0)
     543                 :            :                                 goto error;
     544                 :            :                 }
     545 [ +  + ][ -  + ]:          7 :         } else if (!uid_eq(kuid, old->uid) && !uid_eq(kuid, new->suid)) {
     546                 :            :                 goto error;
     547                 :            :         }
     548                 :            : 
     549                 :        726 :         new->fsuid = new->euid = kuid;
     550                 :            : 
     551                 :        726 :         retval = security_task_fix_setuid(new, old, LSM_SETID_ID);
     552         [ +  - ]:        726 :         if (retval < 0)
     553                 :            :                 goto error;
     554                 :            : 
     555                 :        726 :         return commit_creds(new);
     556                 :            : 
     557                 :            : error:
     558                 :          3 :         abort_creds(new);
     559                 :            :         return retval;
     560                 :            : }
     561                 :            : 
     562                 :            : 
     563                 :            : /*
     564                 :            :  * This function implements a generic ability to update ruid, euid,
     565                 :            :  * and suid.  This allows you to implement the 4.4 compatible seteuid().
     566                 :            :  */
     567                 :          0 : SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
     568                 :            : {
     569                 :            :         struct user_namespace *ns = current_user_ns();
     570                 :            :         const struct cred *old;
     571                 :            :         struct cred *new;
     572                 :            :         int retval;
     573                 :            :         kuid_t kruid, keuid, ksuid;
     574                 :            : 
     575                 :            :         kruid = make_kuid(ns, ruid);
     576                 :            :         keuid = make_kuid(ns, euid);
     577                 :            :         ksuid = make_kuid(ns, suid);
     578                 :            : 
     579 [ +  + ][ +  - ]:       7538 :         if ((ruid != (uid_t) -1) && !uid_valid(kruid))
     580                 :            :                 return -EINVAL;
     581                 :            : 
     582 [ +  + ][ +  - ]:       7538 :         if ((euid != (uid_t) -1) && !uid_valid(keuid))
     583                 :            :                 return -EINVAL;
     584                 :            : 
     585 [ +  + ][ +  - ]:       7538 :         if ((suid != (uid_t) -1) && !uid_valid(ksuid))
     586                 :            :                 return -EINVAL;
     587                 :            : 
     588                 :       7538 :         new = prepare_creds();
     589         [ +  - ]:       7538 :         if (!new)
     590                 :            :                 return -ENOMEM;
     591                 :            : 
     592                 :       7538 :         old = current_cred();
     593                 :            : 
     594                 :            :         retval = -EPERM;
     595         [ +  + ]:       7538 :         if (!ns_capable(old->user_ns, CAP_SETUID)) {
     596 [ +  + ][ +  + ]:       1780 :                 if (ruid != (uid_t) -1        && !uid_eq(kruid, old->uid) &&
                 [ +  - ]
     597            [ + ]:          4 :                     !uid_eq(kruid, old->euid) && !uid_eq(kruid, old->suid))
     598                 :            :                         goto error;
     599 [ +  + ][ +  + ]:       9316 :                 if (euid != (uid_t) -1        && !uid_eq(keuid, old->uid) &&
                 [ +  + ]
     600         [ -  + ]:          5 :                     !uid_eq(keuid, old->euid) && !uid_eq(keuid, old->suid))
     601                 :            :                         goto error;
     602 [ +  + ][ +  + ]:       9311 :                 if (suid != (uid_t) -1        && !uid_eq(ksuid, old->uid) &&
                 [ +  + ]
     603         [ -  + ]:          4 :                     !uid_eq(ksuid, old->euid) && !uid_eq(ksuid, old->suid))
     604                 :            :                         goto error;
     605                 :            :         }
     606                 :            : 
     607         [ +  + ]:       7527 :         if (ruid != (uid_t) -1) {
     608                 :        651 :                 new->uid = kruid;
     609         [ +  + ]:        651 :                 if (!uid_eq(kruid, old->uid)) {
     610                 :        171 :                         retval = set_user(new);
     611         [ +  - ]:        171 :                         if (retval < 0)
     612                 :            :                                 goto error;
     613                 :            :                 }
     614                 :            :         }
     615         [ +  + ]:       7527 :         if (euid != (uid_t) -1)
     616                 :       5623 :                 new->euid = keuid;
     617         [ +  + ]:       7527 :         if (suid != (uid_t) -1)
     618                 :        655 :                 new->suid = ksuid;
     619                 :       7527 :         new->fsuid = new->euid;
     620                 :            : 
     621                 :       7527 :         retval = security_task_fix_setuid(new, old, LSM_SETID_RES);
     622         [ +  - ]:       7527 :         if (retval < 0)
     623                 :            :                 goto error;
     624                 :            : 
     625                 :       7527 :         return commit_creds(new);
     626                 :            : 
     627                 :            : error:
     628                 :          0 :         abort_creds(new);
     629                 :            :         return retval;
     630                 :            : }
     631                 :            : 
     632                 :          0 : SYSCALL_DEFINE3(getresuid, uid_t __user *, ruidp, uid_t __user *, euidp, uid_t __user *, suidp)
     633                 :            : {
     634                 :       1145 :         const struct cred *cred = current_cred();
     635                 :            :         int retval;
     636                 :            :         uid_t ruid, euid, suid;
     637                 :            : 
     638                 :       1145 :         ruid = from_kuid_munged(cred->user_ns, cred->uid);
     639                 :       1145 :         euid = from_kuid_munged(cred->user_ns, cred->euid);
     640                 :       1145 :         suid = from_kuid_munged(cred->user_ns, cred->suid);
     641                 :            : 
     642   [ +  -  +  - ]:       2290 :         if (!(retval   = put_user(ruid, ruidp)) &&
     643                 :       1145 :             !(retval   = put_user(euid, euidp)))
     644                 :       1145 :                 retval = put_user(suid, suidp);
     645                 :            : 
     646                 :            :         return retval;
     647                 :            : }
     648                 :            : 
     649                 :            : /*
     650                 :            :  * Same as above, but for rgid, egid, sgid.
     651                 :            :  */
     652                 :          0 : SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
     653                 :            : {
     654                 :            :         struct user_namespace *ns = current_user_ns();
     655                 :            :         const struct cred *old;
     656                 :            :         struct cred *new;
     657                 :            :         int retval;
     658                 :            :         kgid_t krgid, kegid, ksgid;
     659                 :            : 
     660                 :            :         krgid = make_kgid(ns, rgid);
     661                 :            :         kegid = make_kgid(ns, egid);
     662                 :            :         ksgid = make_kgid(ns, sgid);
     663                 :            : 
     664 [ +  + ][ +  - ]:       4256 :         if ((rgid != (gid_t) -1) && !gid_valid(krgid))
     665                 :            :                 return -EINVAL;
     666 [ +  + ][ +  - ]:       4256 :         if ((egid != (gid_t) -1) && !gid_valid(kegid))
     667                 :            :                 return -EINVAL;
     668 [ +  + ][ +  - ]:       4256 :         if ((sgid != (gid_t) -1) && !gid_valid(ksgid))
     669                 :            :                 return -EINVAL;
     670                 :            : 
     671                 :       4256 :         new = prepare_creds();
     672         [ +  - ]:       4256 :         if (!new)
     673                 :            :                 return -ENOMEM;
     674                 :       4256 :         old = current_cred();
     675                 :            : 
     676                 :            :         retval = -EPERM;
     677         [ +  + ]:       4256 :         if (!ns_capable(old->user_ns, CAP_SETGID)) {
     678 [ +  + ][ +  - ]:        292 :                 if (rgid != (gid_t) -1        && !gid_eq(krgid, old->gid) &&
                 [ +  - ]
     679            [ + ]:          4 :                     !gid_eq(krgid, old->egid) && !gid_eq(krgid, old->sgid))
     680                 :            :                         goto error;
     681 [ +  + ][ +  + ]:       4544 :                 if (egid != (gid_t) -1        && !gid_eq(kegid, old->gid) &&
                 [ +  + ]
     682         [ +  + ]:          5 :                     !gid_eq(kegid, old->egid) && !gid_eq(kegid, old->sgid))
     683                 :            :                         goto error;
     684 [ +  + ][ +  - ]:       4541 :                 if (sgid != (gid_t) -1        && !gid_eq(ksgid, old->gid) &&
                 [ +  - ]
     685         [ -  + ]:          2 :                     !gid_eq(ksgid, old->egid) && !gid_eq(ksgid, old->sgid))
     686                 :            :                         goto error;
     687                 :            :         }
     688                 :            : 
     689         [ +  + ]:       4247 :         if (rgid != (gid_t) -1)
     690                 :         14 :                 new->gid = krgid;
     691         [ +  + ]:       4247 :         if (egid != (gid_t) -1)
     692                 :       1241 :                 new->egid = kegid;
     693         [ +  + ]:       4247 :         if (sgid != (gid_t) -1)
     694                 :         16 :                 new->sgid = ksgid;
     695                 :       4247 :         new->fsgid = new->egid;
     696                 :            : 
     697                 :       4247 :         return commit_creds(new);
     698                 :            : 
     699                 :            : error:
     700                 :          0 :         abort_creds(new);
     701                 :            :         return retval;
     702                 :            : }
     703                 :            : 
     704                 :          0 : SYSCALL_DEFINE3(getresgid, gid_t __user *, rgidp, gid_t __user *, egidp, gid_t __user *, sgidp)
     705                 :            : {
     706                 :       1143 :         const struct cred *cred = current_cred();
     707                 :            :         int retval;
     708                 :            :         gid_t rgid, egid, sgid;
     709                 :            : 
     710                 :       1143 :         rgid = from_kgid_munged(cred->user_ns, cred->gid);
     711                 :       1143 :         egid = from_kgid_munged(cred->user_ns, cred->egid);
     712                 :       1143 :         sgid = from_kgid_munged(cred->user_ns, cred->sgid);
     713                 :            : 
     714   [ +  -  +  - ]:       2286 :         if (!(retval   = put_user(rgid, rgidp)) &&
     715                 :       1143 :             !(retval   = put_user(egid, egidp)))
     716                 :       1143 :                 retval = put_user(sgid, sgidp);
     717                 :            : 
     718                 :            :         return retval;
     719                 :            : }
     720                 :            : 
     721                 :            : 
     722                 :            : /*
     723                 :            :  * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
     724                 :            :  * is used for "access()" and for the NFS daemon (letting nfsd stay at
     725                 :            :  * whatever uid it wants to). It normally shadows "euid", except when
     726                 :            :  * explicitly set by setfsuid() or for access..
     727                 :            :  */
     728                 :          0 : SYSCALL_DEFINE1(setfsuid, uid_t, uid)
     729                 :            : {
     730                 :            :         const struct cred *old;
     731                 :            :         struct cred *new;
     732                 :            :         uid_t old_fsuid;
     733                 :            :         kuid_t kuid;
     734                 :            : 
     735                 :         12 :         old = current_cred();
     736                 :         12 :         old_fsuid = from_kuid_munged(old->user_ns, old->fsuid);
     737                 :            : 
     738                 :            :         kuid = make_kuid(old->user_ns, uid);
     739         [ -  + ]:         12 :         if (!uid_valid(kuid))
     740                 :          0 :                 return old_fsuid;
     741                 :            : 
     742                 :         12 :         new = prepare_creds();
     743         [ -  + ]:         12 :         if (!new)
     744                 :          0 :                 return old_fsuid;
     745                 :            : 
     746 [ +  + ][ +  - ]:         12 :         if (uid_eq(kuid, old->uid)  || uid_eq(kuid, old->euid)  ||
                 [ +  - ]
     747   [ +  -  +  + ]:         12 :             uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
     748                 :          6 :             ns_capable(old->user_ns, CAP_SETUID)) {
     749         [ +  + ]:         10 :                 if (!uid_eq(kuid, old->fsuid)) {
     750                 :          8 :                         new->fsuid = kuid;
     751         [ -  + ]:          8 :                         if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
     752                 :            :                                 goto change_okay;
     753                 :            :                 }
     754                 :            :         }
     755                 :            : 
     756                 :          4 :         abort_creds(new);
     757                 :          4 :         return old_fsuid;
     758                 :            : 
     759                 :            : change_okay:
     760                 :          8 :         commit_creds(new);
     761                 :          8 :         return old_fsuid;
     762                 :            : }
     763                 :            : 
     764                 :            : /*
     765                 :            :  * Samma på svenska..
     766                 :            :  */
     767                 :          0 : SYSCALL_DEFINE1(setfsgid, gid_t, gid)
     768                 :            : {
     769                 :            :         const struct cred *old;
     770                 :            :         struct cred *new;
     771                 :            :         gid_t old_fsgid;
     772                 :            :         kgid_t kgid;
     773                 :            : 
     774                 :          6 :         old = current_cred();
     775                 :          6 :         old_fsgid = from_kgid_munged(old->user_ns, old->fsgid);
     776                 :            : 
     777                 :            :         kgid = make_kgid(old->user_ns, gid);
     778         [ -  + ]:          6 :         if (!gid_valid(kgid))
     779                 :          0 :                 return old_fsgid;
     780                 :            : 
     781                 :          6 :         new = prepare_creds();
     782         [ -  + ]:          6 :         if (!new)
     783                 :          0 :                 return old_fsgid;
     784                 :            : 
     785 [ +  + ][ +  - ]:          6 :         if (gid_eq(kgid, old->gid)  || gid_eq(kgid, old->egid)  ||
                 [ +  - ]
     786   [ +  -  +  + ]:          8 :             gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
     787                 :          4 :             ns_capable(old->user_ns, CAP_SETGID)) {
     788         [ +  + ]:          4 :                 if (!gid_eq(kgid, old->fsgid)) {
     789                 :          2 :                         new->fsgid = kgid;
     790                 :            :                         goto change_okay;
     791                 :            :                 }
     792                 :            :         }
     793                 :            : 
     794                 :          4 :         abort_creds(new);
     795                 :          4 :         return old_fsgid;
     796                 :            : 
     797                 :            : change_okay:
     798                 :          2 :         commit_creds(new);
     799                 :          2 :         return old_fsgid;
     800                 :            : }
     801                 :            : 
     802                 :            : /**
     803                 :            :  * sys_getpid - return the thread group id of the current process
     804                 :            :  *
     805                 :            :  * Note, despite the name, this returns the tgid not the pid.  The tgid and
     806                 :            :  * the pid are identical unless CLONE_THREAD was specified on clone() in
     807                 :            :  * which case the tgid is the same in all threads of the same group.
     808                 :            :  *
     809                 :            :  * This is SMP safe as current->tgid does not change.
     810                 :            :  */
     811                 :          0 : SYSCALL_DEFINE0(getpid)
     812                 :            : {
     813                 :      36738 :         return task_tgid_vnr(current);
     814                 :            : }
     815                 :            : 
     816                 :            : /* Thread ID - the internal kernel "pid" */
     817                 :          0 : SYSCALL_DEFINE0(gettid)
     818                 :            : {
     819                 :        156 :         return task_pid_vnr(current);
     820                 :            : }
     821                 :            : 
     822                 :            : /*
     823                 :            :  * Accessing ->real_parent is not SMP-safe, it could
     824                 :            :  * change from under us. However, we can use a stale
     825                 :            :  * value of ->real_parent under rcu_read_lock(), see
     826                 :            :  * release_task()->call_rcu(delayed_put_task_struct).
     827                 :            :  */
     828                 :          0 : SYSCALL_DEFINE0(getppid)
     829                 :            : {
     830                 :            :         int pid;
     831                 :            : 
     832                 :            :         rcu_read_lock();
     833                 :      83715 :         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
     834                 :            :         rcu_read_unlock();
     835                 :            : 
     836                 :      83715 :         return pid;
     837                 :            : }
     838                 :            : 
     839                 :          0 : SYSCALL_DEFINE0(getuid)
     840                 :            : {
     841                 :            :         /* Only we change this so SMP safe */
     842                 :     233012 :         return from_kuid_munged(current_user_ns(), current_uid());
     843                 :            : }
     844                 :            : 
     845                 :          0 : SYSCALL_DEFINE0(geteuid)
     846                 :            : {
     847                 :            :         /* Only we change this so SMP safe */
     848                 :      63910 :         return from_kuid_munged(current_user_ns(), current_euid());
     849                 :            : }
     850                 :            : 
     851                 :          0 : SYSCALL_DEFINE0(getgid)
     852                 :            : {
     853                 :            :         /* Only we change this so SMP safe */
     854                 :      44136 :         return from_kgid_munged(current_user_ns(), current_gid());
     855                 :            : }
     856                 :            : 
     857                 :          0 : SYSCALL_DEFINE0(getegid)
     858                 :            : {
     859                 :            :         /* Only we change this so SMP safe */
     860                 :      42962 :         return from_kgid_munged(current_user_ns(), current_egid());
     861                 :            : }
     862                 :            : 
     863                 :          0 : void do_sys_times(struct tms *tms)
     864                 :            : {
     865                 :            :         cputime_t tgutime, tgstime, cutime, cstime;
     866                 :            : 
     867                 :    5265981 :         spin_lock_irq(&current->sighand->siglock);
     868                 :    5265981 :         thread_group_cputime_adjusted(current, &tgutime, &tgstime);
     869                 :    5265981 :         cutime = current->signal->cutime;
     870                 :    5265981 :         cstime = current->signal->cstime;
     871                 :    5265981 :         spin_unlock_irq(&current->sighand->siglock);
     872                 :    5265981 :         tms->tms_utime = cputime_to_clock_t(tgutime);
     873                 :    5265981 :         tms->tms_stime = cputime_to_clock_t(tgstime);
     874                 :    5265981 :         tms->tms_cutime = cputime_to_clock_t(cutime);
     875                 :    5265981 :         tms->tms_cstime = cputime_to_clock_t(cstime);
     876                 :    5265981 : }
     877                 :            : 
     878                 :          0 : SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
     879                 :            : {
     880         [ +  - ]:    5265981 :         if (tbuf) {
     881                 :            :                 struct tms tmp;
     882                 :            : 
     883                 :    5265981 :                 do_sys_times(&tmp);
     884         [ -  + ]:   10531962 :                 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
     885                 :    5265981 :                         return -EFAULT;
     886                 :            :         }
     887                 :            :         force_successful_syscall_return();
     888                 :    5265981 :         return (long) jiffies_64_to_clock_t(get_jiffies_64());
     889                 :            : }
     890                 :            : 
     891                 :            : /*
     892                 :            :  * This needs some heavy checking ...
     893                 :            :  * I just haven't the stomach for it. I also don't fully
     894                 :            :  * understand sessions/pgrp etc. Let somebody who does explain it.
     895                 :            :  *
     896                 :            :  * OK, I think I have the protection semantics right.... this is really
     897                 :            :  * only important on a multi-user system anyway, to make sure one user
     898                 :            :  * can't send a signal to a process owned by another.  -TYT, 12/12/91
     899                 :            :  *
     900                 :            :  * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
     901                 :            :  * LBT 04.03.94
     902                 :            :  */
     903                 :          0 : SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
     904                 :            : {
     905                 :            :         struct task_struct *p;
     906                 :       1481 :         struct task_struct *group_leader = current->group_leader;
     907                 :            :         struct pid *pgrp;
     908                 :            :         int err;
     909                 :            : 
     910         [ +  + ]:       1481 :         if (!pid)
     911                 :            :                 pid = task_pid_vnr(group_leader);
     912         [ +  + ]:       1481 :         if (!pgid)
     913                 :            :                 pgid = pid;
     914         [ +  + ]:       1481 :         if (pgid < 0)
     915                 :            :                 return -EINVAL;
     916                 :            :         rcu_read_lock();
     917                 :            : 
     918                 :            :         /* From this point forward we keep holding onto the tasklist lock
     919                 :            :          * so that our parent does not change from under us. -DaveM
     920                 :            :          */
     921                 :       1480 :         write_lock_irq(&tasklist_lock);
     922                 :            : 
     923                 :            :         err = -ESRCH;
     924                 :       1480 :         p = find_task_by_vpid(pid);
     925         [ +  + ]:       1480 :         if (!p)
     926                 :            :                 goto out;
     927                 :            : 
     928                 :            :         err = -EINVAL;
     929         [ +  - ]:       1479 :         if (!thread_group_leader(p))
     930                 :            :                 goto out;
     931                 :            : 
     932         [ +  + ]:       1479 :         if (same_thread_group(p->real_parent, group_leader)) {
     933                 :            :                 err = -EPERM;
     934         [ +  + ]:         44 :                 if (task_session(p) != task_session(group_leader))
     935                 :            :                         goto out;
     936                 :            :                 err = -EACCES;
     937         [ +  + ]:         43 :                 if (p->did_exec)
     938                 :            :                         goto out;
     939                 :            :         } else {
     940                 :            :                 err = -ESRCH;
     941         [ +  - ]:       1435 :                 if (p != group_leader)
     942                 :            :                         goto out;
     943                 :            :         }
     944                 :            : 
     945                 :            :         err = -EPERM;
     946         [ +  - ]:       1477 :         if (p->signal->leader)
     947                 :            :                 goto out;
     948                 :            : 
     949                 :            :         pgrp = task_pid(p);
     950         [ +  + ]:       1477 :         if (pgid != pid) {
     951                 :            :                 struct task_struct *g;
     952                 :            : 
     953                 :          5 :                 pgrp = find_vpid(pgid);
     954                 :          5 :                 g = pid_task(pgrp, PIDTYPE_PGID);
     955 [ +  + ][ +  - ]:          5 :                 if (!g || task_session(g) != task_session(group_leader))
     956                 :            :                         goto out;
     957                 :            :         }
     958                 :            : 
     959                 :       1476 :         err = security_task_setpgid(p, pgid);
     960         [ +  - ]:       1476 :         if (err)
     961                 :            :                 goto out;
     962                 :            : 
     963         [ +  + ]:       1476 :         if (task_pgrp(p) != pgrp)
     964                 :       1432 :                 change_pid(p, PIDTYPE_PGID, pgrp);
     965                 :            : 
     966                 :            :         err = 0;
     967                 :            : out:
     968                 :            :         /* All paths lead to here, thus we are safe. -DaveM */
     969                 :            :         write_unlock_irq(&tasklist_lock);
     970                 :            :         rcu_read_unlock();
     971                 :            :         return err;
     972                 :            : }
     973                 :            : 
     974                 :          0 : SYSCALL_DEFINE1(getpgid, pid_t, pid)
     975                 :            : {
     976                 :            :         struct task_struct *p;
     977                 :            :         struct pid *grp;
     978                 :            :         int retval;
     979                 :            : 
     980                 :            :         rcu_read_lock();
     981         [ +  + ]:       2130 :         if (!pid)
     982                 :       2092 :                 grp = task_pgrp(current);
     983                 :            :         else {
     984                 :            :                 retval = -ESRCH;
     985                 :         38 :                 p = find_task_by_vpid(pid);
     986         [ +  + ]:         38 :                 if (!p)
     987                 :            :                         goto out;
     988                 :            :                 grp = task_pgrp(p);
     989         [ +  - ]:         36 :                 if (!grp)
     990                 :            :                         goto out;
     991                 :            : 
     992                 :         36 :                 retval = security_task_getpgid(p);
     993         [ +  - ]:         36 :                 if (retval)
     994                 :            :                         goto out;
     995                 :            :         }
     996                 :       2128 :         retval = pid_vnr(grp);
     997                 :            : out:
     998                 :            :         rcu_read_unlock();
     999                 :            :         return retval;
    1000                 :            : }
    1001                 :            : 
    1002                 :            : #ifdef __ARCH_WANT_SYS_GETPGRP
    1003                 :            : 
    1004                 :          0 : SYSCALL_DEFINE0(getpgrp)
    1005                 :            : {
    1006                 :       1536 :         return sys_getpgid(0);
    1007                 :            : }
    1008                 :            : 
    1009                 :            : #endif
    1010                 :            : 
    1011                 :          0 : SYSCALL_DEFINE1(getsid, pid_t, pid)
    1012                 :            : {
    1013                 :            :         struct task_struct *p;
    1014                 :            :         struct pid *sid;
    1015                 :            :         int retval;
    1016                 :            : 
    1017                 :            :         rcu_read_lock();
    1018         [ +  + ]:        557 :         if (!pid)
    1019                 :        556 :                 sid = task_session(current);
    1020                 :            :         else {
    1021                 :            :                 retval = -ESRCH;
    1022                 :          1 :                 p = find_task_by_vpid(pid);
    1023         [ -  + ]:          1 :                 if (!p)
    1024                 :            :                         goto out;
    1025                 :            :                 sid = task_session(p);
    1026         [ #  # ]:          0 :                 if (!sid)
    1027                 :            :                         goto out;
    1028                 :            : 
    1029                 :          0 :                 retval = security_task_getsid(p);
    1030         [ #  # ]:          0 :                 if (retval)
    1031                 :            :                         goto out;
    1032                 :            :         }
    1033                 :        556 :         retval = pid_vnr(sid);
    1034                 :            : out:
    1035                 :            :         rcu_read_unlock();
    1036                 :            :         return retval;
    1037                 :            : }
    1038                 :            : 
    1039                 :          0 : static void set_special_pids(struct pid *pid)
    1040                 :            : {
    1041                 :        117 :         struct task_struct *curr = current->group_leader;
    1042                 :            : 
    1043         [ +  - ]:        117 :         if (task_session(curr) != pid)
    1044                 :        117 :                 change_pid(curr, PIDTYPE_SID, pid);
    1045                 :            : 
    1046         [ +  - ]:        117 :         if (task_pgrp(curr) != pid)
    1047                 :        117 :                 change_pid(curr, PIDTYPE_PGID, pid);
    1048                 :        117 : }
    1049                 :            : 
    1050                 :          0 : SYSCALL_DEFINE0(setsid)
    1051                 :            : {
    1052                 :        118 :         struct task_struct *group_leader = current->group_leader;
    1053                 :            :         struct pid *sid = task_pid(group_leader);
    1054                 :        118 :         pid_t session = pid_vnr(sid);
    1055                 :            :         int err = -EPERM;
    1056                 :            : 
    1057                 :        118 :         write_lock_irq(&tasklist_lock);
    1058                 :            :         /* Fail if I am already a session leader */
    1059         [ +  - ]:        118 :         if (group_leader->signal->leader)
    1060                 :            :                 goto out;
    1061                 :            : 
    1062                 :            :         /* Fail if a process group id already exists that equals the
    1063                 :            :          * proposed session id.
    1064                 :            :          */
    1065         [ +  + ]:        118 :         if (pid_task(sid, PIDTYPE_PGID))
    1066                 :            :                 goto out;
    1067                 :            : 
    1068                 :        117 :         group_leader->signal->leader = 1;
    1069                 :        117 :         set_special_pids(sid);
    1070                 :            : 
    1071                 :        117 :         proc_clear_tty(group_leader);
    1072                 :            : 
    1073                 :            :         err = session;
    1074                 :            : out:
    1075                 :            :         write_unlock_irq(&tasklist_lock);
    1076         [ +  + ]:        118 :         if (err > 0) {
    1077                 :        117 :                 proc_sid_connector(group_leader);
    1078                 :            :                 sched_autogroup_create_attach(group_leader);
    1079                 :            :         }
    1080                 :        118 :         return err;
    1081                 :            : }
    1082                 :            : 
    1083                 :            : DECLARE_RWSEM(uts_sem);
    1084                 :            : 
    1085                 :            : #ifdef COMPAT_UTS_MACHINE
    1086                 :            : #define override_architecture(name) \
    1087                 :            :         (personality(current->personality) == PER_LINUX32 && \
    1088                 :            :          copy_to_user(name->machine, COMPAT_UTS_MACHINE, \
    1089                 :            :                       sizeof(COMPAT_UTS_MACHINE)))
    1090                 :            : #else
    1091                 :            : #define override_architecture(name)     0
    1092                 :            : #endif
    1093                 :            : 
    1094                 :            : /*
    1095                 :            :  * Work around broken programs that cannot handle "Linux 3.0".
    1096                 :            :  * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
    1097                 :            :  */
    1098                 :          0 : static int override_release(char __user *release, size_t len)
    1099                 :            : {
    1100                 :            :         int ret = 0;
    1101                 :            : 
    1102         [ -  + ]:      62043 :         if (current->personality & UNAME26) {
    1103                 :            :                 const char *rest = UTS_RELEASE;
    1104                 :          0 :                 char buf[65] = { 0 };
    1105                 :            :                 int ndots = 0;
    1106                 :            :                 unsigned v;
    1107                 :            :                 size_t copy;
    1108                 :            : 
    1109         [ #  # ]:          0 :                 while (*rest) {
    1110 [ #  # ][ #  # ]:          0 :                         if (*rest == '.' && ++ndots >= 3)
    1111                 :            :                                 break;
    1112 [ #  # ][ #  # ]:          0 :                         if (!isdigit(*rest) && *rest != '.')
    1113                 :            :                                 break;
    1114                 :          0 :                         rest++;
    1115                 :            :                 }
    1116                 :            :                 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
    1117                 :          0 :                 copy = clamp_t(size_t, len, 1, sizeof(buf));
    1118                 :          0 :                 copy = scnprintf(buf, copy, "2.6.%u%s", v, rest);
    1119                 :          0 :                 ret = copy_to_user(release, buf, copy + 1);
    1120                 :            :         }
    1121                 :      62043 :         return ret;
    1122                 :            : }
    1123                 :            : 
    1124                 :          0 : SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
    1125                 :            : {
    1126                 :            :         int errno = 0;
    1127                 :            : 
    1128                 :      62043 :         down_read(&uts_sem);
    1129         [ +  + ]:      62044 :         if (copy_to_user(name, utsname(), sizeof *name))
    1130                 :            :                 errno = -EFAULT;
    1131                 :      62044 :         up_read(&uts_sem);
    1132                 :            : 
    1133 [ +  + ][ -  + ]:      62044 :         if (!errno && override_release(name->release, sizeof(name->release)))
    1134                 :            :                 errno = -EFAULT;
    1135                 :            :         if (!errno && override_architecture(name))
    1136                 :            :                 errno = -EFAULT;
    1137                 :            :         return errno;
    1138                 :            : }
    1139                 :            : 
    1140                 :            : #ifdef __ARCH_WANT_SYS_OLD_UNAME
    1141                 :            : /*
    1142                 :            :  * Old cruft
    1143                 :            :  */
    1144                 :            : SYSCALL_DEFINE1(uname, struct old_utsname __user *, name)
    1145                 :            : {
    1146                 :            :         int error = 0;
    1147                 :            : 
    1148                 :            :         if (!name)
    1149                 :            :                 return -EFAULT;
    1150                 :            : 
    1151                 :            :         down_read(&uts_sem);
    1152                 :            :         if (copy_to_user(name, utsname(), sizeof(*name)))
    1153                 :            :                 error = -EFAULT;
    1154                 :            :         up_read(&uts_sem);
    1155                 :            : 
    1156                 :            :         if (!error && override_release(name->release, sizeof(name->release)))
    1157                 :            :                 error = -EFAULT;
    1158                 :            :         if (!error && override_architecture(name))
    1159                 :            :                 error = -EFAULT;
    1160                 :            :         return error;
    1161                 :            : }
    1162                 :            : 
    1163                 :            : SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
    1164                 :            : {
    1165                 :            :         int error;
    1166                 :            : 
    1167                 :            :         if (!name)
    1168                 :            :                 return -EFAULT;
    1169                 :            :         if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
    1170                 :            :                 return -EFAULT;
    1171                 :            : 
    1172                 :            :         down_read(&uts_sem);
    1173                 :            :         error = __copy_to_user(&name->sysname, &utsname()->sysname,
    1174                 :            :                                __OLD_UTS_LEN);
    1175                 :            :         error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
    1176                 :            :         error |= __copy_to_user(&name->nodename, &utsname()->nodename,
    1177                 :            :                                 __OLD_UTS_LEN);
    1178                 :            :         error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
    1179                 :            :         error |= __copy_to_user(&name->release, &utsname()->release,
    1180                 :            :                                 __OLD_UTS_LEN);
    1181                 :            :         error |= __put_user(0, name->release + __OLD_UTS_LEN);
    1182                 :            :         error |= __copy_to_user(&name->version, &utsname()->version,
    1183                 :            :                                 __OLD_UTS_LEN);
    1184                 :            :         error |= __put_user(0, name->version + __OLD_UTS_LEN);
    1185                 :            :         error |= __copy_to_user(&name->machine, &utsname()->machine,
    1186                 :            :                                 __OLD_UTS_LEN);
    1187                 :            :         error |= __put_user(0, name->machine + __OLD_UTS_LEN);
    1188                 :            :         up_read(&uts_sem);
    1189                 :            : 
    1190                 :            :         if (!error && override_architecture(name))
    1191                 :            :                 error = -EFAULT;
    1192                 :            :         if (!error && override_release(name->release, sizeof(name->release)))
    1193                 :            :                 error = -EFAULT;
    1194                 :            :         return error ? -EFAULT : 0;
    1195                 :            : }
    1196                 :            : #endif
    1197                 :            : 
    1198                 :          0 : SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
    1199                 :            : {
    1200                 :            :         int errno;
    1201                 :            :         char tmp[__NEW_UTS_LEN];
    1202                 :            : 
    1203         [ +  + ]:          8 :         if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
    1204                 :            :                 return -EPERM;
    1205                 :            : 
    1206         [ +  + ]:          7 :         if (len < 0 || len > __NEW_UTS_LEN)
    1207                 :            :                 return -EINVAL;
    1208                 :          5 :         down_write(&uts_sem);
    1209                 :            :         errno = -EFAULT;
    1210         [ +  + ]:          5 :         if (!copy_from_user(tmp, name, len)) {
    1211                 :            :                 struct new_utsname *u = utsname();
    1212                 :            : 
    1213                 :          4 :                 memcpy(u->nodename, tmp, len);
    1214         [ +  - ]:          4 :                 memset(u->nodename + len, 0, sizeof(u->nodename) - len);
    1215                 :            :                 errno = 0;
    1216                 :          4 :                 uts_proc_notify(UTS_PROC_HOSTNAME);
    1217                 :            :         }
    1218                 :          5 :         up_write(&uts_sem);
    1219                 :            :         return errno;
    1220                 :            : }
    1221                 :            : 
    1222                 :            : #ifdef __ARCH_WANT_SYS_GETHOSTNAME
    1223                 :            : 
    1224                 :          0 : SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
    1225                 :            : {
    1226                 :            :         int i, errno;
    1227                 :            :         struct new_utsname *u;
    1228                 :            : 
    1229         [ #  # ]:          0 :         if (len < 0)
    1230                 :            :                 return -EINVAL;
    1231                 :          0 :         down_read(&uts_sem);
    1232                 :            :         u = utsname();
    1233                 :          0 :         i = 1 + strlen(u->nodename);
    1234         [ #  # ]:          0 :         if (i > len)
    1235                 :            :                 i = len;
    1236                 :            :         errno = 0;
    1237         [ #  # ]:          0 :         if (copy_to_user(name, u->nodename, i))
    1238                 :            :                 errno = -EFAULT;
    1239                 :          0 :         up_read(&uts_sem);
    1240                 :            :         return errno;
    1241                 :            : }
    1242                 :            : 
    1243                 :            : #endif
    1244                 :            : 
    1245                 :            : /*
    1246                 :            :  * Only setdomainname; getdomainname can be implemented by calling
    1247                 :            :  * uname()
    1248                 :            :  */
    1249                 :          0 : SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
    1250                 :            : {
    1251                 :            :         int errno;
    1252                 :            :         char tmp[__NEW_UTS_LEN];
    1253                 :            : 
    1254         [ +  + ]:          8 :         if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
    1255                 :            :                 return -EPERM;
    1256         [ +  + ]:          7 :         if (len < 0 || len > __NEW_UTS_LEN)
    1257                 :            :                 return -EINVAL;
    1258                 :            : 
    1259                 :          5 :         down_write(&uts_sem);
    1260                 :            :         errno = -EFAULT;
    1261         [ +  + ]:          5 :         if (!copy_from_user(tmp, name, len)) {
    1262                 :            :                 struct new_utsname *u = utsname();
    1263                 :            : 
    1264                 :          4 :                 memcpy(u->domainname, tmp, len);
    1265         [ +  - ]:          4 :                 memset(u->domainname + len, 0, sizeof(u->domainname) - len);
    1266                 :            :                 errno = 0;
    1267                 :          4 :                 uts_proc_notify(UTS_PROC_DOMAINNAME);
    1268                 :            :         }
    1269                 :          5 :         up_write(&uts_sem);
    1270                 :            :         return errno;
    1271                 :            : }
    1272                 :            : 
    1273                 :          0 : SYSCALL_DEFINE2(getrlimit, unsigned int, resource, struct rlimit __user *, rlim)
    1274                 :            : {
    1275                 :            :         struct rlimit value;
    1276                 :            :         int ret;
    1277                 :            : 
    1278                 :      12080 :         ret = do_prlimit(current, resource, NULL, &value);
    1279         [ +  + ]:      12080 :         if (!ret)
    1280         [ +  + ]:      24159 :                 ret = copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
    1281                 :            : 
    1282                 :            :         return ret;
    1283                 :            : }
    1284                 :            : 
    1285                 :            : #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
    1286                 :            : 
    1287                 :            : /*
    1288                 :            :  *      Back compatibility for getrlimit. Needed for some apps.
    1289                 :            :  */
    1290                 :            :  
    1291                 :            : SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
    1292                 :            :                 struct rlimit __user *, rlim)
    1293                 :            : {
    1294                 :            :         struct rlimit x;
    1295                 :            :         if (resource >= RLIM_NLIMITS)
    1296                 :            :                 return -EINVAL;
    1297                 :            : 
    1298                 :            :         task_lock(current->group_leader);
    1299                 :            :         x = current->signal->rlim[resource];
    1300                 :            :         task_unlock(current->group_leader);
    1301                 :            :         if (x.rlim_cur > 0x7FFFFFFF)
    1302                 :            :                 x.rlim_cur = 0x7FFFFFFF;
    1303                 :            :         if (x.rlim_max > 0x7FFFFFFF)
    1304                 :            :                 x.rlim_max = 0x7FFFFFFF;
    1305                 :            :         return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
    1306                 :            : }
    1307                 :            : 
    1308                 :            : #endif
    1309                 :            : 
    1310                 :            : static inline bool rlim64_is_infinity(__u64 rlim64)
    1311                 :            : {
    1312                 :            : #if BITS_PER_LONG < 64
    1313                 :            :         return rlim64 >= ULONG_MAX;
    1314                 :            : #else
    1315                 :            :         return rlim64 == RLIM64_INFINITY;
    1316                 :            : #endif
    1317                 :            : }
    1318                 :            : 
    1319                 :          0 : static void rlim_to_rlim64(const struct rlimit *rlim, struct rlimit64 *rlim64)
    1320                 :            : {
    1321         [ +  + ]:      18039 :         if (rlim->rlim_cur == RLIM_INFINITY)
    1322                 :      16209 :                 rlim64->rlim_cur = RLIM64_INFINITY;
    1323                 :            :         else
    1324                 :       1830 :                 rlim64->rlim_cur = rlim->rlim_cur;
    1325         [ +  + ]:      18039 :         if (rlim->rlim_max == RLIM_INFINITY)
    1326                 :      17215 :                 rlim64->rlim_max = RLIM64_INFINITY;
    1327                 :            :         else
    1328                 :        824 :                 rlim64->rlim_max = rlim->rlim_max;
    1329                 :      18039 : }
    1330                 :            : 
    1331                 :          0 : static void rlim64_to_rlim(const struct rlimit64 *rlim64, struct rlimit *rlim)
    1332                 :            : {
    1333         [ +  + ]:       4285 :         if (rlim64_is_infinity(rlim64->rlim_cur))
    1334                 :       2128 :                 rlim->rlim_cur = RLIM_INFINITY;
    1335                 :            :         else
    1336                 :       2157 :                 rlim->rlim_cur = (unsigned long)rlim64->rlim_cur;
    1337         [ +  + ]:       4285 :         if (rlim64_is_infinity(rlim64->rlim_max))
    1338                 :       3466 :                 rlim->rlim_max = RLIM_INFINITY;
    1339                 :            :         else
    1340                 :        819 :                 rlim->rlim_max = (unsigned long)rlim64->rlim_max;
    1341                 :       4285 : }
    1342                 :            : 
    1343                 :            : /* make sure you are allowed to change @tsk limits before calling this */
    1344                 :          0 : int do_prlimit(struct task_struct *tsk, unsigned int resource,
    1345                 :            :                 struct rlimit *new_rlim, struct rlimit *old_rlim)
    1346                 :            : {
    1347                 :            :         struct rlimit *rlim;
    1348                 :            :         int retval = 0;
    1349                 :            : 
    1350         [ +  + ]:      34663 :         if (resource >= RLIM_NLIMITS)
    1351                 :            :                 return -EINVAL;
    1352         [ +  + ]:      34661 :         if (new_rlim) {
    1353         [ +  - ]:       4543 :                 if (new_rlim->rlim_cur > new_rlim->rlim_max)
    1354                 :            :                         return -EINVAL;
    1355 [ +  + ][ +  + ]:       4543 :                 if (resource == RLIMIT_NOFILE &&
    1356                 :         41 :                                 new_rlim->rlim_max > sysctl_nr_open)
    1357                 :            :                         return -EPERM;
    1358                 :            :         }
    1359                 :            : 
    1360                 :            :         /* protect tsk->signal and tsk->sighand from disappearing */
    1361                 :      34660 :         read_lock(&tasklist_lock);
    1362         [ +  - ]:      34660 :         if (!tsk->sighand) {
    1363                 :            :                 retval = -ESRCH;
    1364                 :            :                 goto out;
    1365                 :            :         }
    1366                 :            : 
    1367                 :      34660 :         rlim = tsk->signal->rlim + resource;
    1368                 :      34660 :         task_lock(tsk->group_leader);
    1369         [ +  + ]:      34660 :         if (new_rlim) {
    1370                 :            :                 /* Keep the capable check against init_user_ns until
    1371                 :            :                    cgroups can contain all limits */
    1372   [ +  +  +  + ]:       5101 :                 if (new_rlim->rlim_max > rlim->rlim_max &&
    1373                 :        559 :                                 !capable(CAP_SYS_RESOURCE))
    1374                 :            :                         retval = -EPERM;
    1375         [ +  + ]:       4542 :                 if (!retval)
    1376                 :       4541 :                         retval = security_task_setrlimit(tsk->group_leader,
    1377                 :            :                                         resource, new_rlim);
    1378 [ +  + ][ -  + ]:       4542 :                 if (resource == RLIMIT_CPU && new_rlim->rlim_cur == 0) {
    1379                 :            :                         /*
    1380                 :            :                          * The caller is asking for an immediate RLIMIT_CPU
    1381                 :            :                          * expiry.  But we use the zero value to mean "it was
    1382                 :            :                          * never set".  So let's cheat and make it one second
    1383                 :            :                          * instead
    1384                 :            :                          */
    1385                 :          0 :                         new_rlim->rlim_cur = 1;
    1386                 :            :                 }
    1387                 :            :         }
    1388         [ +  + ]:      34660 :         if (!retval) {
    1389         [ +  + ]:      34659 :                 if (old_rlim)
    1390                 :      30118 :                         *old_rlim = *rlim;
    1391         [ +  + ]:      34659 :                 if (new_rlim)
    1392                 :       4541 :                         *rlim = *new_rlim;
    1393                 :            :         }
    1394                 :          0 :         task_unlock(tsk->group_leader);
    1395                 :            : 
    1396                 :            :         /*
    1397                 :            :          * RLIMIT_CPU handling.   Note that the kernel fails to return an error
    1398                 :            :          * code if it rejected the user's attempt to set RLIMIT_CPU.  This is a
    1399                 :            :          * very long-standing error, and fixing it now risks breakage of
    1400                 :            :          * applications, so we live with it
    1401                 :            :          */
    1402 [ +  + ][ +  + ]:      34660 :          if (!retval && new_rlim && resource == RLIMIT_CPU &&
                 [ -  + ]
    1403                 :         38 :                          new_rlim->rlim_cur != RLIM_INFINITY)
    1404                 :          0 :                 update_rlimit_cpu(tsk, new_rlim->rlim_cur);
    1405                 :            : out:
    1406                 :            :         read_unlock(&tasklist_lock);
    1407                 :      34660 :         return retval;
    1408                 :            : }
    1409                 :            : 
    1410                 :            : /* rcu lock must be held */
    1411                 :          0 : static int check_prlimit_permission(struct task_struct *task)
    1412                 :            : {
    1413                 :      22324 :         const struct cred *cred = current_cred(), *tcred;
    1414                 :            : 
    1415         [ -  + ]:      22324 :         if (current == task)
    1416                 :            :                 return 0;
    1417                 :            : 
    1418                 :          0 :         tcred = __task_cred(task);
    1419 [ #  # ][ #  # ]:          0 :         if (uid_eq(cred->uid, tcred->euid) &&
    1420         [ #  # ]:          0 :             uid_eq(cred->uid, tcred->suid) &&
    1421         [ #  # ]:          0 :             uid_eq(cred->uid, tcred->uid)  &&
    1422         [ #  # ]:          0 :             gid_eq(cred->gid, tcred->egid) &&
    1423         [ #  # ]:          0 :             gid_eq(cred->gid, tcred->sgid) &&
    1424                 :          0 :             gid_eq(cred->gid, tcred->gid))
    1425                 :            :                 return 0;
    1426         [ #  # ]:          0 :         if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
    1427                 :            :                 return 0;
    1428                 :            : 
    1429                 :          0 :         return -EPERM;
    1430                 :            : }
    1431                 :            : 
    1432                 :          0 : SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
    1433                 :            :                 const struct rlimit64 __user *, new_rlim,
    1434                 :            :                 struct rlimit64 __user *, old_rlim)
    1435                 :            : {
    1436                 :            :         struct rlimit64 old64, new64;
    1437                 :            :         struct rlimit old, new;
    1438                 :            :         struct task_struct *tsk;
    1439                 :            :         int ret;
    1440                 :            : 
    1441         [ +  + ]:      22324 :         if (new_rlim) {
    1442         [ +  - ]:       4285 :                 if (copy_from_user(&new64, new_rlim, sizeof(new64)))
    1443                 :            :                         return -EFAULT;
    1444                 :       4285 :                 rlim64_to_rlim(&new64, &new);
    1445                 :            :         }
    1446                 :            : 
    1447                 :            :         rcu_read_lock();
    1448         [ -  + ]:      22324 :         tsk = pid ? find_task_by_vpid(pid) : current;
    1449         [ -  + ]:      22324 :         if (!tsk) {
    1450                 :            :                 rcu_read_unlock();
    1451                 :            :                 return -ESRCH;
    1452                 :            :         }
    1453                 :      22324 :         ret = check_prlimit_permission(tsk);
    1454         [ -  + ]:      22324 :         if (ret) {
    1455                 :            :                 rcu_read_unlock();
    1456                 :            :                 return ret;
    1457                 :            :         }
    1458                 :      22324 :         get_task_struct(tsk);
    1459                 :            :         rcu_read_unlock();
    1460                 :            : 
    1461 [ +  + ][ +  + ]:      22324 :         ret = do_prlimit(tsk, resource, new_rlim ? &new : NULL,
    1462                 :            :                         old_rlim ? &old : NULL);
    1463                 :            : 
    1464         [ +  + ]:      22324 :         if (!ret && old_rlim) {
    1465                 :      18039 :                 rlim_to_rlim64(&old, &old64);
    1466         [ -  + ]:      18039 :                 if (copy_to_user(old_rlim, &old64, sizeof(old64)))
    1467                 :            :                         ret = -EFAULT;
    1468                 :            :         }
    1469                 :            : 
    1470                 :            :         put_task_struct(tsk);
    1471                 :            :         return ret;
    1472                 :            : }
    1473                 :            : 
    1474                 :          0 : SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
    1475                 :            : {
    1476                 :            :         struct rlimit new_rlim;
    1477                 :            : 
    1478         [ +  + ]:        260 :         if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
    1479                 :            :                 return -EFAULT;
    1480                 :        259 :         return do_prlimit(current, resource, &new_rlim, NULL);
    1481                 :            : }
    1482                 :            : 
    1483                 :            : /*
    1484                 :            :  * It would make sense to put struct rusage in the task_struct,
    1485                 :            :  * except that would make the task_struct be *really big*.  After
    1486                 :            :  * task_struct gets moved into malloc'ed memory, it would
    1487                 :            :  * make sense to do this.  It will make moving the rest of the information
    1488                 :            :  * a lot simpler!  (Which we're not doing right now because we're not
    1489                 :            :  * measuring them yet).
    1490                 :            :  *
    1491                 :            :  * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
    1492                 :            :  * races with threads incrementing their own counters.  But since word
    1493                 :            :  * reads are atomic, we either get new values or old values and we don't
    1494                 :            :  * care which for the sums.  We always take the siglock to protect reading
    1495                 :            :  * the c* fields from p->signal from races with exit.c updating those
    1496                 :            :  * fields when reaping, so a sample either gets all the additions of a
    1497                 :            :  * given child after it's reaped, or none so this sample is before reaping.
    1498                 :            :  *
    1499                 :            :  * Locking:
    1500                 :            :  * We need to take the siglock for CHILDEREN, SELF and BOTH
    1501                 :            :  * for  the cases current multithreaded, non-current single threaded
    1502                 :            :  * non-current multithreaded.  Thread traversal is now safe with
    1503                 :            :  * the siglock held.
    1504                 :            :  * Strictly speaking, we donot need to take the siglock if we are current and
    1505                 :            :  * single threaded,  as no one else can take our signal_struct away, no one
    1506                 :            :  * else can  reap the  children to update signal->c* counters, and no one else
    1507                 :            :  * can race with the signal-> fields. If we do not take any lock, the
    1508                 :            :  * signal-> fields could be read out of order while another thread was just
    1509                 :            :  * exiting. So we should  place a read memory barrier when we avoid the lock.
    1510                 :            :  * On the writer side,  write memory barrier is implied in  __exit_signal
    1511                 :            :  * as __exit_signal releases  the siglock spinlock after updating the signal->
    1512                 :            :  * fields. But we don't do this yet to keep things simple.
    1513                 :            :  *
    1514                 :            :  */
    1515                 :            : 
    1516                 :            : static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r)
    1517                 :            : {
    1518                 :      55153 :         r->ru_nvcsw += t->nvcsw;
    1519                 :      55153 :         r->ru_nivcsw += t->nivcsw;
    1520                 :      55153 :         r->ru_minflt += t->min_flt;
    1521                 :      55153 :         r->ru_majflt += t->maj_flt;
    1522                 :            :         r->ru_inblock += task_io_get_inblock(t);
    1523                 :            :         r->ru_oublock += task_io_get_oublock(t);
    1524                 :            : }
    1525                 :            : 
    1526                 :          0 : static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
    1527                 :            : {
    1528                 :            :         struct task_struct *t;
    1529                 :            :         unsigned long flags;
    1530                 :            :         cputime_t tgutime, tgstime, utime, stime;
    1531                 :            :         unsigned long maxrss = 0;
    1532                 :            : 
    1533                 :      55165 :         memset((char *) r, 0, sizeof *r);
    1534                 :      55165 :         utime = stime = 0;
    1535                 :            : 
    1536         [ +  + ]:      55165 :         if (who == RUSAGE_THREAD) {
    1537                 :      51835 :                 task_cputime_adjusted(current, &utime, &stime);
    1538                 :            :                 accumulate_thread_rusage(p, r);
    1539                 :      51835 :                 maxrss = p->signal->maxrss;
    1540                 :      51835 :                 goto out;
    1541                 :            :         }
    1542                 :            : 
    1543         [ +  - ]:       3330 :         if (!lock_task_sighand(p, &flags))
    1544                 :          0 :                 return;
    1545                 :            : 
    1546      [ +  +  - ]:       3330 :         switch (who) {
    1547                 :            :                 case RUSAGE_BOTH:
    1548                 :            :                 case RUSAGE_CHILDREN:
    1549                 :         13 :                         utime = p->signal->cutime;
    1550                 :         13 :                         stime = p->signal->cstime;
    1551                 :         13 :                         r->ru_nvcsw = p->signal->cnvcsw;
    1552                 :         13 :                         r->ru_nivcsw = p->signal->cnivcsw;
    1553                 :         13 :                         r->ru_minflt = p->signal->cmin_flt;
    1554                 :         13 :                         r->ru_majflt = p->signal->cmaj_flt;
    1555                 :         13 :                         r->ru_inblock = p->signal->cinblock;
    1556                 :         13 :                         r->ru_oublock = p->signal->coublock;
    1557                 :         13 :                         maxrss = p->signal->cmaxrss;
    1558                 :            : 
    1559         [ +  + ]:         13 :                         if (who == RUSAGE_CHILDREN)
    1560                 :            :                                 break;
    1561                 :            : 
    1562                 :            :                 case RUSAGE_SELF:
    1563                 :       3318 :                         thread_group_cputime_adjusted(p, &tgutime, &tgstime);
    1564                 :       3318 :                         utime += tgutime;
    1565                 :       3318 :                         stime += tgstime;
    1566                 :       3318 :                         r->ru_nvcsw += p->signal->nvcsw;
    1567                 :       3318 :                         r->ru_nivcsw += p->signal->nivcsw;
    1568                 :       3318 :                         r->ru_minflt += p->signal->min_flt;
    1569                 :       3318 :                         r->ru_majflt += p->signal->maj_flt;
    1570                 :       3318 :                         r->ru_inblock += p->signal->inblock;
    1571                 :       3318 :                         r->ru_oublock += p->signal->oublock;
    1572         [ +  + ]:       3318 :                         if (maxrss < p->signal->maxrss)
    1573                 :            :                                 maxrss = p->signal->maxrss;
    1574                 :            :                         t = p;
    1575                 :            :                         do {
    1576                 :            :                                 accumulate_thread_rusage(t, r);
    1577                 :       3318 :                                 t = next_thread(t);
    1578         [ -  + ]:       3318 :                         } while (t != p);
    1579                 :            :                         break;
    1580                 :            : 
    1581                 :            :                 default:
    1582                 :          0 :                         BUG();
    1583                 :            :         }
    1584                 :       3330 :         unlock_task_sighand(p, &flags);
    1585                 :            : 
    1586                 :            : out:
    1587                 :      55165 :         cputime_to_timeval(utime, &r->ru_utime);
    1588                 :      55165 :         cputime_to_timeval(stime, &r->ru_stime);
    1589                 :            : 
    1590         [ +  + ]:      55165 :         if (who != RUSAGE_CHILDREN) {
    1591                 :      55153 :                 struct mm_struct *mm = get_task_mm(p);
    1592         [ +  + ]:      55153 :                 if (mm) {
    1593                 :            :                         setmax_mm_hiwater_rss(&maxrss, mm);
    1594                 :      55152 :                         mmput(mm);
    1595                 :            :                 }
    1596                 :            :         }
    1597                 :      55165 :         r->ru_maxrss = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */
    1598                 :            : }
    1599                 :            : 
    1600                 :          0 : int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
    1601                 :            : {
    1602                 :            :         struct rusage r;
    1603                 :      55165 :         k_getrusage(p, who, &r);
    1604         [ +  + ]:     110330 :         return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
    1605                 :            : }
    1606                 :            : 
    1607                 :          0 : SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)
    1608                 :            : {
    1609 [ +  + ][ +  + ]:      55165 :         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
    1610                 :            :             who != RUSAGE_THREAD)
    1611                 :            :                 return -EINVAL;
    1612                 :      55164 :         return getrusage(current, who, ru);
    1613                 :            : }
    1614                 :            : 
    1615                 :            : #ifdef CONFIG_COMPAT
    1616                 :            : COMPAT_SYSCALL_DEFINE2(getrusage, int, who, struct compat_rusage __user *, ru)
    1617                 :            : {
    1618                 :            :         struct rusage r;
    1619                 :            : 
    1620                 :            :         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
    1621                 :            :             who != RUSAGE_THREAD)
    1622                 :            :                 return -EINVAL;
    1623                 :            : 
    1624                 :            :         k_getrusage(current, who, &r);
    1625                 :            :         return put_compat_rusage(&r, ru);
    1626                 :            : }
    1627                 :            : #endif
    1628                 :            : 
    1629                 :          0 : SYSCALL_DEFINE1(umask, int, mask)
    1630                 :            : {
    1631                 :      75836 :         mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
    1632                 :            :         return mask;
    1633                 :            : }
    1634                 :            : 
    1635                 :          0 : static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
    1636                 :            : {
    1637                 :            :         struct fd exe;
    1638                 :            :         struct inode *inode;
    1639                 :            :         int err;
    1640                 :            : 
    1641                 :            :         exe = fdget(fd);
    1642         [ #  # ]:          0 :         if (!exe.file)
    1643                 :            :                 return -EBADF;
    1644                 :            : 
    1645                 :            :         inode = file_inode(exe.file);
    1646                 :            : 
    1647                 :            :         /*
    1648                 :            :          * Because the original mm->exe_file points to executable file, make
    1649                 :            :          * sure that this one is executable as well, to avoid breaking an
    1650                 :            :          * overall picture.
    1651                 :            :          */
    1652                 :            :         err = -EACCES;
    1653 [ #  # ][ #  # ]:          0 :         if (!S_ISREG(inode->i_mode)  ||
    1654                 :          0 :             exe.file->f_path.mnt->mnt_flags & MNT_NOEXEC)
    1655                 :            :                 goto exit;
    1656                 :            : 
    1657                 :          0 :         err = inode_permission(inode, MAY_EXEC);
    1658         [ #  # ]:          0 :         if (err)
    1659                 :            :                 goto exit;
    1660                 :            : 
    1661                 :          0 :         down_write(&mm->mmap_sem);
    1662                 :            : 
    1663                 :            :         /*
    1664                 :            :          * Forbid mm->exe_file change if old file still mapped.
    1665                 :            :          */
    1666                 :            :         err = -EBUSY;
    1667         [ #  # ]:          0 :         if (mm->exe_file) {
    1668                 :            :                 struct vm_area_struct *vma;
    1669                 :            : 
    1670         [ #  # ]:          0 :                 for (vma = mm->mmap; vma; vma = vma->vm_next)
    1671 [ #  # ][ #  # ]:          0 :                         if (vma->vm_file &&
    1672                 :            :                             path_equal(&vma->vm_file->f_path,
    1673                 :            :                                        &mm->exe_file->f_path))
    1674                 :            :                                 goto exit_unlock;
    1675                 :            :         }
    1676                 :            : 
    1677                 :            :         /*
    1678                 :            :          * The symlink can be changed only once, just to disallow arbitrary
    1679                 :            :          * transitions malicious software might bring in. This means one
    1680                 :            :          * could make a snapshot over all processes running and monitor
    1681                 :            :          * /proc/pid/exe changes to notice unusual activity if needed.
    1682                 :            :          */
    1683                 :            :         err = -EPERM;
    1684         [ #  # ]:          0 :         if (test_and_set_bit(MMF_EXE_FILE_CHANGED, &mm->flags))
    1685                 :            :                 goto exit_unlock;
    1686                 :            : 
    1687                 :            :         err = 0;
    1688                 :          0 :         set_mm_exe_file(mm, exe.file);  /* this grabs a reference to exe.file */
    1689                 :            : exit_unlock:
    1690                 :          0 :         up_write(&mm->mmap_sem);
    1691                 :            : 
    1692                 :            : exit:
    1693                 :            :         fdput(exe);
    1694                 :          0 :         return err;
    1695                 :            : }
    1696                 :            : 
    1697                 :          0 : static int prctl_set_mm(int opt, unsigned long addr,
    1698                 :            :                         unsigned long arg4, unsigned long arg5)
    1699                 :            : {
    1700                 :            :         unsigned long rlim = rlimit(RLIMIT_DATA);
    1701                 :          0 :         struct mm_struct *mm = current->mm;
    1702                 :            :         struct vm_area_struct *vma;
    1703                 :            :         int error;
    1704                 :            : 
    1705 [ #  # ][ #  # ]:          0 :         if (arg5 || (arg4 && opt != PR_SET_MM_AUXV))
    1706                 :            :                 return -EINVAL;
    1707                 :            : 
    1708         [ #  # ]:          0 :         if (!capable(CAP_SYS_RESOURCE))
    1709                 :            :                 return -EPERM;
    1710                 :            : 
    1711         [ #  # ]:          0 :         if (opt == PR_SET_MM_EXE_FILE)
    1712                 :          0 :                 return prctl_set_mm_exe_file(mm, (unsigned int)addr);
    1713                 :            : 
    1714 [ #  # ][ #  # ]:          0 :         if (addr >= TASK_SIZE || addr < mmap_min_addr)
    1715                 :            :                 return -EINVAL;
    1716                 :            : 
    1717                 :            :         error = -EINVAL;
    1718                 :            : 
    1719                 :          0 :         down_read(&mm->mmap_sem);
    1720                 :          0 :         vma = find_vma(mm, addr);
    1721                 :            : 
    1722   [ #  #  #  #  :          0 :         switch (opt) {
             #  #  #  #  
                      # ]
    1723                 :            :         case PR_SET_MM_START_CODE:
    1724                 :          0 :                 mm->start_code = addr;
    1725                 :          0 :                 break;
    1726                 :            :         case PR_SET_MM_END_CODE:
    1727                 :          0 :                 mm->end_code = addr;
    1728                 :          0 :                 break;
    1729                 :            :         case PR_SET_MM_START_DATA:
    1730                 :          0 :                 mm->start_data = addr;
    1731                 :          0 :                 break;
    1732                 :            :         case PR_SET_MM_END_DATA:
    1733                 :          0 :                 mm->end_data = addr;
    1734                 :          0 :                 break;
    1735                 :            : 
    1736                 :            :         case PR_SET_MM_START_BRK:
    1737         [ #  # ]:          0 :                 if (addr <= mm->end_data)
    1738                 :            :                         goto out;
    1739                 :            : 
    1740 [ #  # ][ #  # ]:          0 :                 if (rlim < RLIM_INFINITY &&
    1741                 :          0 :                     (mm->brk - addr) +
    1742                 :          0 :                     (mm->end_data - mm->start_data) > rlim)
    1743                 :            :                         goto out;
    1744                 :            : 
    1745                 :          0 :                 mm->start_brk = addr;
    1746                 :          0 :                 break;
    1747                 :            : 
    1748                 :            :         case PR_SET_MM_BRK:
    1749         [ #  # ]:          0 :                 if (addr <= mm->end_data)
    1750                 :            :                         goto out;
    1751                 :            : 
    1752 [ #  # ][ #  # ]:          0 :                 if (rlim < RLIM_INFINITY &&
    1753                 :          0 :                     (addr - mm->start_brk) +
    1754                 :          0 :                     (mm->end_data - mm->start_data) > rlim)
    1755                 :            :                         goto out;
    1756                 :            : 
    1757                 :          0 :                 mm->brk = addr;
    1758                 :          0 :                 break;
    1759                 :            : 
    1760                 :            :         /*
    1761                 :            :          * If command line arguments and environment
    1762                 :            :          * are placed somewhere else on stack, we can
    1763                 :            :          * set them up here, ARG_START/END to setup
    1764                 :            :          * command line argumets and ENV_START/END
    1765                 :            :          * for environment.
    1766                 :            :          */
    1767                 :            :         case PR_SET_MM_START_STACK:
    1768                 :            :         case PR_SET_MM_ARG_START:
    1769                 :            :         case PR_SET_MM_ARG_END:
    1770                 :            :         case PR_SET_MM_ENV_START:
    1771                 :            :         case PR_SET_MM_ENV_END:
    1772         [ #  # ]:          0 :                 if (!vma) {
    1773                 :            :                         error = -EFAULT;
    1774                 :            :                         goto out;
    1775                 :            :                 }
    1776         [ #  # ]:          0 :                 if (opt == PR_SET_MM_START_STACK)
    1777                 :          0 :                         mm->start_stack = addr;
    1778         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ARG_START)
    1779                 :          0 :                         mm->arg_start = addr;
    1780         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ARG_END)
    1781                 :          0 :                         mm->arg_end = addr;
    1782         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ENV_START)
    1783                 :          0 :                         mm->env_start = addr;
    1784         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ENV_END)
    1785                 :          0 :                         mm->env_end = addr;
    1786                 :            :                 break;
    1787                 :            : 
    1788                 :            :         /*
    1789                 :            :          * This doesn't move auxiliary vector itself
    1790                 :            :          * since it's pinned to mm_struct, but allow
    1791                 :            :          * to fill vector with new values. It's up
    1792                 :            :          * to a caller to provide sane values here
    1793                 :            :          * otherwise user space tools which use this
    1794                 :            :          * vector might be unhappy.
    1795                 :            :          */
    1796                 :            :         case PR_SET_MM_AUXV: {
    1797                 :            :                 unsigned long user_auxv[AT_VECTOR_SIZE];
    1798                 :            : 
    1799         [ #  # ]:          0 :                 if (arg4 > sizeof(user_auxv))
    1800                 :            :                         goto out;
    1801                 :          0 :                 up_read(&mm->mmap_sem);
    1802                 :            : 
    1803         [ #  # ]:          0 :                 if (copy_from_user(user_auxv, (const void __user *)addr, arg4))
    1804                 :          0 :                         return -EFAULT;
    1805                 :            : 
    1806                 :            :                 /* Make sure the last entry is always AT_NULL */
    1807                 :          0 :                 user_auxv[AT_VECTOR_SIZE - 2] = 0;
    1808                 :          0 :                 user_auxv[AT_VECTOR_SIZE - 1] = 0;
    1809                 :            : 
    1810                 :            :                 BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
    1811                 :            : 
    1812                 :          0 :                 task_lock(current);
    1813                 :          0 :                 memcpy(mm->saved_auxv, user_auxv, arg4);
    1814                 :          0 :                 task_unlock(current);
    1815                 :            : 
    1816                 :          0 :                 return 0;
    1817                 :            :         }
    1818                 :            :         default:
    1819                 :            :                 goto out;
    1820                 :            :         }
    1821                 :            : 
    1822                 :            :         error = 0;
    1823                 :            : out:
    1824                 :          0 :         up_read(&mm->mmap_sem);
    1825                 :          0 :         return error;
    1826                 :            : }
    1827                 :            : 
    1828                 :            : #ifdef CONFIG_CHECKPOINT_RESTORE
    1829                 :            : static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
    1830                 :            : {
    1831                 :            :         return put_user(me->clear_child_tid, tid_addr);
    1832                 :            : }
    1833                 :            : #else
    1834                 :          0 : static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
    1835                 :            : {
    1836                 :          0 :         return -EINVAL;
    1837                 :            : }
    1838                 :            : #endif
    1839                 :            : 
    1840                 :            : #ifdef CONFIG_MMU
    1841                 :          0 : static int prctl_update_vma_anon_name(struct vm_area_struct *vma,
    1842                 :            :                 struct vm_area_struct **prev,
    1843                 :            :                 unsigned long start, unsigned long end,
    1844                 :            :                 const char __user *name_addr)
    1845                 :            : {
    1846                 :          0 :         struct mm_struct * mm = vma->vm_mm;
    1847                 :            :         int error = 0;
    1848                 :            :         pgoff_t pgoff;
    1849                 :            : 
    1850         [ #  # ]:          0 :         if (name_addr == vma_get_anon_name(vma)) {
    1851                 :          0 :                 *prev = vma;
    1852                 :          0 :                 goto out;
    1853                 :            :         }
    1854                 :            : 
    1855                 :          0 :         pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
    1856                 :          0 :         *prev = vma_merge(mm, *prev, start, end, vma->vm_flags, vma->anon_vma,
    1857                 :            :                                 vma->vm_file, pgoff, vma_policy(vma),
    1858                 :            :                                 name_addr);
    1859         [ #  # ]:          0 :         if (*prev) {
    1860                 :            :                 vma = *prev;
    1861                 :            :                 goto success;
    1862                 :            :         }
    1863                 :            : 
    1864                 :          0 :         *prev = vma;
    1865                 :            : 
    1866         [ #  # ]:          0 :         if (start != vma->vm_start) {
    1867                 :          0 :                 error = split_vma(mm, vma, start, 1);
    1868         [ #  # ]:          0 :                 if (error)
    1869                 :            :                         goto out;
    1870                 :            :         }
    1871                 :            : 
    1872         [ #  # ]:          0 :         if (end != vma->vm_end) {
    1873                 :          0 :                 error = split_vma(mm, vma, end, 0);
    1874         [ #  # ]:          0 :                 if (error)
    1875                 :            :                         goto out;
    1876                 :            :         }
    1877                 :            : 
    1878                 :            : success:
    1879         [ #  # ]:          0 :         if (!vma->vm_file)
    1880                 :          0 :                 vma->shared.anon_name = name_addr;
    1881                 :            : 
    1882                 :            : out:
    1883         [ #  # ]:          0 :         if (error == -ENOMEM)
    1884                 :            :                 error = -EAGAIN;
    1885                 :          0 :         return error;
    1886                 :            : }
    1887                 :            : 
    1888                 :          0 : static int prctl_set_vma_anon_name(unsigned long start, unsigned long end,
    1889                 :            :                         unsigned long arg)
    1890                 :            : {
    1891                 :            :         unsigned long tmp;
    1892                 :            :         struct vm_area_struct * vma, *prev;
    1893                 :            :         int unmapped_error = 0;
    1894                 :            :         int error = -EINVAL;
    1895                 :            : 
    1896                 :            :         /*
    1897                 :            :          * If the interval [start,end) covers some unmapped address
    1898                 :            :          * ranges, just ignore them, but return -ENOMEM at the end.
    1899                 :            :          * - this matches the handling in madvise.
    1900                 :            :          */
    1901                 :          0 :         vma = find_vma_prev(current->mm, start, &prev);
    1902 [ #  # ][ #  # ]:          0 :         if (vma && start > vma->vm_start)
    1903                 :          0 :                 prev = vma;
    1904                 :            : 
    1905                 :            :         for (;;) {
    1906                 :            :                 /* Still start < end. */
    1907                 :            :                 error = -ENOMEM;
    1908         [ #  # ]:          0 :                 if (!vma)
    1909                 :            :                         return error;
    1910                 :            : 
    1911                 :            :                 /* Here start < (end|vma->vm_end). */
    1912         [ #  # ]:          0 :                 if (start < vma->vm_start) {
    1913                 :            :                         unmapped_error = -ENOMEM;
    1914                 :            :                         start = vma->vm_start;
    1915         [ #  # ]:          0 :                         if (start >= end)
    1916                 :            :                                 return error;
    1917                 :            :                 }
    1918                 :            : 
    1919                 :            :                 /* Here vma->vm_start <= start < (end|vma->vm_end) */
    1920                 :          0 :                 tmp = vma->vm_end;
    1921         [ #  # ]:          0 :                 if (end < tmp)
    1922                 :            :                         tmp = end;
    1923                 :            : 
    1924                 :            :                 /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */
    1925                 :          0 :                 error = prctl_update_vma_anon_name(vma, &prev, start, end,
    1926                 :            :                                 (const char __user *)arg);
    1927         [ #  # ]:          0 :                 if (error)
    1928                 :            :                         return error;
    1929                 :            :                 start = tmp;
    1930 [ #  # ][ #  # ]:          0 :                 if (prev && start < prev->vm_end)
    1931                 :            :                         start = prev->vm_end;
    1932                 :            :                 error = unmapped_error;
    1933         [ #  # ]:          0 :                 if (start >= end)
    1934                 :            :                         return error;
    1935         [ #  # ]:          0 :                 if (prev)
    1936                 :          0 :                         vma = prev->vm_next;
    1937                 :            :                 else    /* madvise_remove dropped mmap_sem */
    1938                 :          0 :                         vma = find_vma(current->mm, start);
    1939                 :            :         }
    1940                 :            : }
    1941                 :            : 
    1942                 :          0 : static int prctl_set_vma(unsigned long opt, unsigned long start,
    1943                 :            :                 unsigned long len_in, unsigned long arg)
    1944                 :            : {
    1945                 :          0 :         struct mm_struct *mm = current->mm;
    1946                 :            :         int error;
    1947                 :            :         unsigned long len;
    1948                 :            :         unsigned long end;
    1949                 :            : 
    1950         [ #  # ]:          0 :         if (start & ~PAGE_MASK)
    1951                 :            :                 return -EINVAL;
    1952                 :          0 :         len = (len_in + ~PAGE_MASK) & PAGE_MASK;
    1953                 :            : 
    1954                 :            :         /* Check to see whether len was rounded up from small -ve to zero */
    1955         [ #  # ]:          0 :         if (len_in && !len)
    1956                 :            :                 return -EINVAL;
    1957                 :            : 
    1958                 :          0 :         end = start + len;
    1959         [ #  # ]:          0 :         if (end < start)
    1960                 :            :                 return -EINVAL;
    1961                 :            : 
    1962         [ #  # ]:          0 :         if (end == start)
    1963                 :            :                 return 0;
    1964                 :            : 
    1965                 :          0 :         down_write(&mm->mmap_sem);
    1966                 :            : 
    1967         [ #  # ]:          0 :         switch (opt) {
    1968                 :            :         case PR_SET_VMA_ANON_NAME:
    1969                 :          0 :                 error = prctl_set_vma_anon_name(start, end, arg);
    1970                 :          0 :                 break;
    1971                 :            :         default:
    1972                 :            :                 error = -EINVAL;
    1973                 :            :         }
    1974                 :            : 
    1975                 :          0 :         up_write(&mm->mmap_sem);
    1976                 :            : 
    1977                 :          0 :         return error;
    1978                 :            : }
    1979                 :            : #else /* CONFIG_MMU */
    1980                 :            : static int prctl_set_vma(unsigned long opt, unsigned long start,
    1981                 :            :                 unsigned long len_in, unsigned long arg)
    1982                 :            : {
    1983                 :            :         return -EINVAL;
    1984                 :            : }
    1985                 :            : #endif
    1986                 :            : 
    1987                 :          0 : SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
    1988                 :            :                 unsigned long, arg4, unsigned long, arg5)
    1989                 :            : {
    1990                 :      18517 :         struct task_struct *me = current;
    1991                 :            :         unsigned char comm[sizeof(me->comm)];
    1992                 :            :         long error;
    1993                 :            : 
    1994                 :      18517 :         error = security_task_prctl(option, arg2, arg3, arg4, arg5);
    1995         [ +  - ]:      18516 :         if (error != -ENOSYS)
    1996                 :            :                 return error;
    1997                 :            : 
    1998                 :            :         error = 0;
    1999   [ +  +  +  -  :      18516 :         switch (option) {
          -  -  +  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
             -  -  -  -  
                      + ]
    2000                 :            :         case PR_SET_PDEATHSIG:
    2001         [ +  + ]:          2 :                 if (!valid_signal(arg2)) {
    2002                 :            :                         error = -EINVAL;
    2003                 :            :                         break;
    2004                 :            :                 }
    2005                 :          1 :                 me->pdeath_signal = arg2;
    2006                 :            :                 break;
    2007                 :            :         case PR_GET_PDEATHSIG:
    2008                 :          1 :                 error = put_user(me->pdeath_signal, (int __user *)arg2);
    2009                 :            :                 break;
    2010                 :            :         case PR_GET_DUMPABLE:
    2011                 :      18462 :                 error = get_dumpable(me->mm);
    2012                 :            :                 break;
    2013                 :            :         case PR_SET_DUMPABLE:
    2014         [ #  # ]:          0 :                 if (arg2 != SUID_DUMP_DISABLE && arg2 != SUID_DUMP_USER) {
    2015                 :            :                         error = -EINVAL;
    2016                 :            :                         break;
    2017                 :            :                 }
    2018                 :          0 :                 set_dumpable(me->mm, arg2);
    2019                 :            :                 break;
    2020                 :            : 
    2021                 :            :         case PR_SET_UNALIGN:
    2022                 :            :                 error = SET_UNALIGN_CTL(me, arg2);
    2023                 :            :                 break;
    2024                 :            :         case PR_GET_UNALIGN:
    2025                 :            :                 error = GET_UNALIGN_CTL(me, arg2);
    2026                 :            :                 break;
    2027                 :            :         case PR_SET_FPEMU:
    2028                 :            :                 error = SET_FPEMU_CTL(me, arg2);
    2029                 :            :                 break;
    2030                 :            :         case PR_GET_FPEMU:
    2031                 :            :                 error = GET_FPEMU_CTL(me, arg2);
    2032                 :            :                 break;
    2033                 :            :         case PR_SET_FPEXC:
    2034                 :            :                 error = SET_FPEXC_CTL(me, arg2);
    2035                 :            :                 break;
    2036                 :            :         case PR_GET_FPEXC:
    2037                 :            :                 error = GET_FPEXC_CTL(me, arg2);
    2038                 :            :                 break;
    2039                 :            :         case PR_GET_TIMING:
    2040                 :            :                 error = PR_TIMING_STATISTICAL;
    2041                 :            :                 break;
    2042                 :            :         case PR_SET_TIMING:
    2043         [ #  # ]:          0 :                 if (arg2 != PR_TIMING_STATISTICAL)
    2044                 :            :                         error = -EINVAL;
    2045                 :            :                 break;
    2046                 :            :         case PR_SET_NAME:
    2047                 :         31 :                 comm[sizeof(me->comm) - 1] = 0;
    2048         [ +  - ]:         31 :                 if (strncpy_from_user(comm, (char __user *)arg2,
    2049                 :            :                                       sizeof(me->comm) - 1) < 0)
    2050                 :            :                         return -EFAULT;
    2051                 :         31 :                 set_task_comm(me, comm);
    2052                 :         31 :                 proc_comm_connector(me);
    2053                 :            :                 break;
    2054                 :            :         case PR_GET_NAME:
    2055                 :          0 :                 get_task_comm(comm, me);
    2056         [ #  # ]:          0 :                 if (copy_to_user((char __user *)arg2, comm, sizeof(comm)))
    2057                 :            :                         return -EFAULT;
    2058                 :            :                 break;
    2059                 :            :         case PR_GET_ENDIAN:
    2060                 :            :                 error = GET_ENDIAN(me, arg2);
    2061                 :            :                 break;
    2062                 :            :         case PR_SET_ENDIAN:
    2063                 :            :                 error = SET_ENDIAN(me, arg2);
    2064                 :            :                 break;
    2065                 :            :         case PR_GET_SECCOMP:
    2066                 :          0 :                 error = prctl_get_seccomp();
    2067                 :            :                 break;
    2068                 :            :         case PR_SET_SECCOMP:
    2069                 :          0 :                 error = prctl_set_seccomp(arg2, (char __user *)arg3);
    2070                 :            :                 break;
    2071                 :            :         case PR_GET_TSC:
    2072                 :            :                 error = GET_TSC_CTL(arg2);
    2073                 :            :                 break;
    2074                 :            :         case PR_SET_TSC:
    2075                 :            :                 error = SET_TSC_CTL(arg2);
    2076                 :            :                 break;
    2077                 :            :         case PR_TASK_PERF_EVENTS_DISABLE:
    2078                 :          0 :                 error = perf_event_task_disable();
    2079                 :            :                 break;
    2080                 :            :         case PR_TASK_PERF_EVENTS_ENABLE:
    2081                 :          0 :                 error = perf_event_task_enable();
    2082                 :            :                 break;
    2083                 :            :         case PR_GET_TIMERSLACK:
    2084                 :          0 :                 error = current->timer_slack_ns;
    2085                 :            :                 break;
    2086                 :            :         case PR_SET_TIMERSLACK:
    2087         [ #  # ]:          0 :                 if (arg2 <= 0)
    2088                 :          0 :                         current->timer_slack_ns =
    2089                 :          0 :                                         current->default_timer_slack_ns;
    2090                 :            :                 else
    2091                 :          0 :                         current->timer_slack_ns = arg2;
    2092                 :            :                 break;
    2093                 :            :         case PR_MCE_KILL:
    2094         [ #  # ]:          0 :                 if (arg4 | arg5)
    2095                 :            :                         return -EINVAL;
    2096      [ #  #  # ]:          0 :                 switch (arg2) {
    2097                 :            :                 case PR_MCE_KILL_CLEAR:
    2098         [ #  # ]:          0 :                         if (arg3 != 0)
    2099                 :            :                                 return -EINVAL;
    2100                 :          0 :                         current->flags &= ~PF_MCE_PROCESS;
    2101                 :            :                         break;
    2102                 :            :                 case PR_MCE_KILL_SET:
    2103                 :          0 :                         current->flags |= PF_MCE_PROCESS;
    2104         [ #  # ]:          0 :                         if (arg3 == PR_MCE_KILL_EARLY)
    2105                 :          0 :                                 current->flags |= PF_MCE_EARLY;
    2106         [ #  # ]:          0 :                         else if (arg3 == PR_MCE_KILL_LATE)
    2107                 :          0 :                                 current->flags &= ~PF_MCE_EARLY;
    2108         [ #  # ]:          0 :                         else if (arg3 == PR_MCE_KILL_DEFAULT)
    2109                 :          0 :                                 current->flags &=
    2110                 :            :                                                 ~(PF_MCE_EARLY|PF_MCE_PROCESS);
    2111                 :            :                         else
    2112                 :            :                                 return -EINVAL;
    2113                 :            :                         break;
    2114                 :            :                 default:
    2115                 :            :                         return -EINVAL;
    2116                 :            :                 }
    2117                 :            :                 break;
    2118                 :            :         case PR_MCE_KILL_GET:
    2119         [ #  # ]:          0 :                 if (arg2 | arg3 | arg4 | arg5)
    2120                 :            :                         return -EINVAL;
    2121         [ #  # ]:          0 :                 if (current->flags & PF_MCE_PROCESS)
    2122                 :          0 :                         error = (current->flags & PF_MCE_EARLY) ?
    2123                 :          0 :                                 PR_MCE_KILL_EARLY : PR_MCE_KILL_LATE;
    2124                 :            :                 else
    2125                 :            :                         error = PR_MCE_KILL_DEFAULT;
    2126                 :            :                 break;
    2127                 :            :         case PR_SET_MM:
    2128                 :          0 :                 error = prctl_set_mm(arg2, arg3, arg4, arg5);
    2129                 :            :                 break;
    2130                 :            :         case PR_GET_TID_ADDRESS:
    2131                 :          0 :                 error = prctl_get_tid_address(me, (int __user **)arg2);
    2132                 :            :                 break;
    2133                 :            :         case PR_SET_CHILD_SUBREAPER:
    2134                 :          0 :                 me->signal->is_child_subreaper = !!arg2;
    2135                 :            :                 break;
    2136                 :            :         case PR_GET_CHILD_SUBREAPER:
    2137                 :          0 :                 error = put_user(me->signal->is_child_subreaper,
    2138                 :            :                                  (int __user *)arg2);
    2139                 :            :                 break;
    2140                 :            :         case PR_SET_NO_NEW_PRIVS:
    2141 [ #  # ][ #  # ]:          0 :                 if (arg2 != 1 || arg3 || arg4 || arg5)
    2142                 :            :                         return -EINVAL;
    2143                 :            : 
    2144                 :          0 :                 current->no_new_privs = 1;
    2145                 :            :                 break;
    2146                 :            :         case PR_GET_NO_NEW_PRIVS:
    2147         [ #  # ]:          0 :                 if (arg2 || arg3 || arg4 || arg5)
    2148                 :            :                         return -EINVAL;
    2149                 :          0 :                 return current->no_new_privs ? 1 : 0;
    2150                 :            :         case PR_SET_VMA:
    2151                 :          0 :                 error = prctl_set_vma(arg2, arg3, arg4, arg5);
    2152                 :            :                 break;
    2153                 :            :         default:
    2154                 :            :                 error = -EINVAL;
    2155                 :            :                 break;
    2156                 :            :         }
    2157                 :            :         return error;
    2158                 :            : }
    2159                 :            : 
    2160                 :          0 : SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,
    2161                 :            :                 struct getcpu_cache __user *, unused)
    2162                 :            : {
    2163                 :            :         int err = 0;
    2164                 :          0 :         int cpu = raw_smp_processor_id();
    2165         [ #  # ]:          0 :         if (cpup)
    2166                 :          0 :                 err |= put_user(cpu, cpup);
    2167         [ #  # ]:          0 :         if (nodep)
    2168                 :          0 :                 err |= put_user(cpu_to_node(cpu), nodep);
    2169         [ #  # ]:          0 :         return err ? -EFAULT : 0;
    2170                 :            : }
    2171                 :            : 
    2172                 :            : /**
    2173                 :            :  * do_sysinfo - fill in sysinfo struct
    2174                 :            :  * @info: pointer to buffer to fill
    2175                 :            :  */
    2176                 :          0 : static int do_sysinfo(struct sysinfo *info)
    2177                 :            : {
    2178                 :            :         unsigned long mem_total, sav_total;
    2179                 :            :         unsigned int mem_unit, bitcount;
    2180                 :            :         struct timespec tp;
    2181                 :            : 
    2182                 :         28 :         memset(info, 0, sizeof(struct sysinfo));
    2183                 :            : 
    2184                 :         28 :         get_monotonic_boottime(&tp);
    2185         [ -  + ]:         28 :         info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
    2186                 :            : 
    2187                 :         28 :         get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
    2188                 :            : 
    2189                 :         28 :         info->procs = nr_threads;
    2190                 :            : 
    2191                 :         28 :         si_meminfo(info);
    2192                 :         28 :         si_swapinfo(info);
    2193                 :            : 
    2194                 :            :         /*
    2195                 :            :          * If the sum of all the available memory (i.e. ram + swap)
    2196                 :            :          * is less than can be stored in a 32 bit unsigned long then
    2197                 :            :          * we can be binary compatible with 2.2.x kernels.  If not,
    2198                 :            :          * well, in that case 2.2.x was broken anyways...
    2199                 :            :          *
    2200                 :            :          *  -Erik Andersen <andersee@debian.org>
    2201                 :            :          */
    2202                 :            : 
    2203                 :         28 :         mem_total = info->totalram + info->totalswap;
    2204    [ +  - ][ + ]:         28 :         if (mem_total < info->totalram || mem_total < info->totalswap)
    2205                 :            :                 goto out;
    2206                 :            :         bitcount = 0;
    2207                 :         28 :         mem_unit = info->mem_unit;
    2208         [ +  + ]:        392 :         while (mem_unit > 1) {
    2209                 :        336 :                 bitcount++;
    2210                 :        336 :                 mem_unit >>= 1;
    2211                 :            :                 sav_total = mem_total;
    2212                 :        336 :                 mem_total <<= 1;
    2213         [ +  - ]:        336 :                 if (mem_total < sav_total)
    2214                 :            :                         goto out;
    2215                 :            :         }
    2216                 :            : 
    2217                 :            :         /*
    2218                 :            :          * If mem_total did not overflow, multiply all memory values by
    2219                 :            :          * info->mem_unit and set it to 1.  This leaves things compatible
    2220                 :            :          * with 2.2.x, and also retains compatibility with earlier 2.4.x
    2221                 :            :          * kernels...
    2222                 :            :          */
    2223                 :            : 
    2224                 :         28 :         info->mem_unit = 1;
    2225                 :         28 :         info->totalram <<= bitcount;
    2226                 :         28 :         info->freeram <<= bitcount;
    2227                 :         28 :         info->sharedram <<= bitcount;
    2228                 :         28 :         info->bufferram <<= bitcount;
    2229                 :         28 :         info->totalswap <<= bitcount;
    2230                 :         28 :         info->freeswap <<= bitcount;
    2231                 :         28 :         info->totalhigh <<= bitcount;
    2232                 :         28 :         info->freehigh <<= bitcount;
    2233                 :            : 
    2234                 :            : out:
    2235                 :          0 :         return 0;
    2236                 :            : }
    2237                 :            : 
    2238                 :          0 : SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info)
    2239                 :            : {
    2240                 :            :         struct sysinfo val;
    2241                 :            : 
    2242                 :         28 :         do_sysinfo(&val);
    2243                 :            : 
    2244         [ +  + ]:         56 :         if (copy_to_user(info, &val, sizeof(struct sysinfo)))
    2245                 :            :                 return -EFAULT;
    2246                 :            : 
    2247                 :            :         return 0;
    2248                 :            : }
    2249                 :            : 
    2250                 :            : #ifdef CONFIG_COMPAT
    2251                 :            : struct compat_sysinfo {
    2252                 :            :         s32 uptime;
    2253                 :            :         u32 loads[3];
    2254                 :            :         u32 totalram;
    2255                 :            :         u32 freeram;
    2256                 :            :         u32 sharedram;
    2257                 :            :         u32 bufferram;
    2258                 :            :         u32 totalswap;
    2259                 :            :         u32 freeswap;
    2260                 :            :         u16 procs;
    2261                 :            :         u16 pad;
    2262                 :            :         u32 totalhigh;
    2263                 :            :         u32 freehigh;
    2264                 :            :         u32 mem_unit;
    2265                 :            :         char _f[20-2*sizeof(u32)-sizeof(int)];
    2266                 :            : };
    2267                 :            : 
    2268                 :            : COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
    2269                 :            : {
    2270                 :            :         struct sysinfo s;
    2271                 :            : 
    2272                 :            :         do_sysinfo(&s);
    2273                 :            : 
    2274                 :            :         /* Check to see if any memory value is too large for 32-bit and scale
    2275                 :            :          *  down if needed
    2276                 :            :          */
    2277                 :            :         if ((s.totalram >> 32) || (s.totalswap >> 32)) {
    2278                 :            :                 int bitcount = 0;
    2279                 :            : 
    2280                 :            :                 while (s.mem_unit < PAGE_SIZE) {
    2281                 :            :                         s.mem_unit <<= 1;
    2282                 :            :                         bitcount++;
    2283                 :            :                 }
    2284                 :            : 
    2285                 :            :                 s.totalram >>= bitcount;
    2286                 :            :                 s.freeram >>= bitcount;
    2287                 :            :                 s.sharedram >>= bitcount;
    2288                 :            :                 s.bufferram >>= bitcount;
    2289                 :            :                 s.totalswap >>= bitcount;
    2290                 :            :                 s.freeswap >>= bitcount;
    2291                 :            :                 s.totalhigh >>= bitcount;
    2292                 :            :                 s.freehigh >>= bitcount;
    2293                 :            :         }
    2294                 :            : 
    2295                 :            :         if (!access_ok(VERIFY_WRITE, info, sizeof(struct compat_sysinfo)) ||
    2296                 :            :             __put_user(s.uptime, &info->uptime) ||
    2297                 :            :             __put_user(s.loads[0], &info->loads[0]) ||
    2298                 :            :             __put_user(s.loads[1], &info->loads[1]) ||
    2299                 :            :             __put_user(s.loads[2], &info->loads[2]) ||
    2300                 :            :             __put_user(s.totalram, &info->totalram) ||
    2301                 :            :             __put_user(s.freeram, &info->freeram) ||
    2302                 :            :             __put_user(s.sharedram, &info->sharedram) ||
    2303                 :            :             __put_user(s.bufferram, &info->bufferram) ||
    2304                 :            :             __put_user(s.totalswap, &info->totalswap) ||
    2305                 :            :             __put_user(s.freeswap, &info->freeswap) ||
    2306                 :            :             __put_user(s.procs, &info->procs) ||
    2307                 :            :             __put_user(s.totalhigh, &info->totalhigh) ||
    2308                 :            :             __put_user(s.freehigh, &info->freehigh) ||
    2309                 :            :             __put_user(s.mem_unit, &info->mem_unit))
    2310                 :            :                 return -EFAULT;
    2311                 :            : 
    2312                 :            :         return 0;
    2313                 :            : }
    2314                 :            : #endif /* CONFIG_COMPAT */

Generated by: LCOV version 1.9