LCOV - code coverage report
Current view: top level - kernel - sys.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 447 717 62.3 %
Date: 2014-04-16 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                 :       2907 :         const struct cred *cred = current_cred(), *pcred = __task_cred(p);
     128                 :            : 
     129 [ +  + ][ +  + ]:       2907 :         if (uid_eq(pcred->uid,  cred->euid) ||
     130                 :            :             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         [ +  + ]:       2907 :         if (!set_one_prio_perm(p)) {
     146                 :            :                 error = -EPERM;
     147                 :            :                 goto out;
     148                 :            :         }
     149 [ +  + ][ +  + ]:       2906 :         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
     150                 :            :                 error = -EACCES;
     151                 :            :                 goto out;
     152                 :            :         }
     153                 :       2904 :         no_nice = security_task_setnice(p, niceval);
     154         [ +  - ]:       2904 :         if (no_nice) {
     155                 :            :                 error = no_nice;
     156                 :            :                 goto out;
     157                 :            :         }
     158         [ +  - ]:       2904 :         if (error == -ESRCH)
     159                 :            :                 error = 0;
     160                 :       2904 :         set_user_nice(p, niceval);
     161                 :            : out:
     162                 :       2907 :         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                 :       2909 :         const struct cred *cred = current_cred();
     170                 :            :         int error = -EINVAL;
     171                 :            :         struct pid *pgrp;
     172                 :            :         kuid_t uid;
     173                 :            : 
     174         [ +  + ]:       2909 :         if (which > PRIO_USER || which < PRIO_PROCESS)
     175                 :            :                 goto out;
     176                 :            : 
     177                 :            :         /* normalize: avoid signed division (rounding problems) */
     178                 :            :         error = -ESRCH;
     179         [ -  + ]:       2908 :         if (niceval < -20)
     180                 :            :                 niceval = -20;
     181         [ +  + ]:       2908 :         if (niceval > 19)
     182                 :            :                 niceval = 19;
     183                 :            : 
     184                 :            :         rcu_read_lock();
     185                 :       2908 :         read_lock(&tasklist_lock);
     186   [ +  -  -  - ]:       2908 :         switch (which) {
     187                 :            :                 case PRIO_PROCESS:
     188         [ +  + ]:       2908 :                         if (who)
     189                 :          2 :                                 p = find_task_by_vpid(who);
     190                 :            :                         else
     191                 :       2906 :                                 p = current;
     192         [ +  + ]:       2908 :                         if (p)
     193                 :       2907 :                                 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                 :       4223 :         const struct cred *cred = current_cred();
     239                 :            :         long niceval, retval = -ESRCH;
     240                 :            :         struct pid *pgrp;
     241                 :            :         kuid_t uid;
     242                 :            : 
     243         [ +  + ]:       4223 :         if (which > PRIO_USER || which < PRIO_PROCESS)
     244                 :            :                 return -EINVAL;
     245                 :            : 
     246                 :            :         rcu_read_lock();
     247                 :       4222 :         read_lock(&tasklist_lock);
     248   [ +  +  +  - ]:       4222 :         switch (which) {
     249                 :            :                 case PRIO_PROCESS:
     250         [ +  + ]:       4218 :                         if (who)
     251                 :          1 :                                 p = find_task_by_vpid(who);
     252                 :            :                         else
     253                 :       4217 :                                 p = current;
     254         [ +  + ]:       4218 :                         if (p) {
     255                 :       4217 :                                 niceval = 20 - task_nice(p);
     256         [ +  - ]:       4217 :                                 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         [ +  - ]:       4224 :                                 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 [ +  - ][ -  + ]:         88 :                         else if (!uid_eq(uid, cred->uid) &&
     277                 :            :                                  !(user = find_user(uid)))
     278                 :            :                                 goto out_unlock;        /* No processes for this user */
     279                 :            : 
     280         [ +  + ]:         87 :                         do_each_thread(g, p) {
     281         [ +  + ]:         89 :                                 if (uid_eq(task_uid(p), uid)) {
     282                 :         85 :                                         niceval = 20 - task_nice(p);
     283         [ +  + ]:         85 :                                         if (niceval > retval)
     284                 :            :                                                 retval = niceval;
     285                 :            :                                 }
     286         [ +  + ]:         89 :                         } 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         [ +  - ]:        654 :         if (!gid_valid(kgid))
     383                 :            :                 return -EINVAL;
     384                 :            : 
     385                 :        654 :         new = prepare_creds();
     386         [ +  - ]:        654 :         if (!new)
     387                 :            :                 return -ENOMEM;
     388                 :        654 :         old = current_cred();
     389                 :            : 
     390                 :            :         retval = -EPERM;
     391         [ +  + ]:        654 :         if (ns_capable(old->user_ns, CAP_SETGID))
     392                 :        652 :                 new->gid = new->egid = new->sgid = new->fsgid = kgid;
     393 [ +  - ][ -  + ]:          2 :         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                 :        652 :         return commit_creds(new);
     399                 :            : 
     400                 :            : error:
     401                 :          2 :         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                 :        333 : static int set_user(struct cred *new)
     409                 :            : {
     410                 :            :         struct user_struct *new_user;
     411                 :            : 
     412                 :        333 :         new_user = alloc_uid(new->uid);
     413         [ +  - ]:        333 :         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 [ -  + ][ #  # ]:        333 :         if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) &&
     424                 :            :                         new_user != INIT_USER)
     425                 :          0 :                 current->flags |= PF_NPROC_EXCEEDED;
     426                 :            :         else
     427                 :        333 :                 current->flags &= ~PF_NPROC_EXCEEDED;
     428                 :            : 
     429                 :        333 :         free_uid(new->user);
     430                 :        333 :         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 [ +  + ][ +  - ]:        117 :         if ((ruid != (uid_t) -1) && !uid_valid(kruid))
     461                 :            :                 return -EINVAL;
     462 [ +  + ][ +  - ]:        117 :         if ((euid != (uid_t) -1) && !uid_valid(keuid))
     463                 :            :                 return -EINVAL;
     464                 :            : 
     465                 :        117 :         new = prepare_creds();
     466         [ +  - ]:        117 :         if (!new)
     467                 :            :                 return -ENOMEM;
     468                 :        117 :         old = current_cred();
     469                 :            : 
     470                 :            :         retval = -EPERM;
     471         [ +  + ]:        117 :         if (ruid != (uid_t) -1) {
     472                 :         58 :                 new->uid = kruid;
     473 [ +  + ][ +  + ]:         58 :                 if (!uid_eq(old->uid, kruid) &&
     474            [ + ]:         36 :                     !uid_eq(old->euid, kruid) &&
     475                 :         36 :                     !ns_capable(old->user_ns, CAP_SETUID))
     476                 :            :                         goto error;
     477                 :            :         }
     478                 :            : 
     479         [ +  + ]:        218 :         if (euid != (uid_t) -1) {
     480                 :         77 :                 new->euid = keuid;
     481 [ +  + ][ +  - ]:         77 :                 if (!uid_eq(old->uid, keuid) &&
     482         [ +  + ]:         45 :                     !uid_eq(old->euid, keuid) &&
     483         [ +  + ]:         39 :                     !uid_eq(old->suid, keuid) &&
     484                 :         39 :                     !ns_capable(old->user_ns, CAP_SETUID))
     485                 :            :                         goto error;
     486                 :            :         }
     487                 :            : 
     488         [ +  + ]:         89 :         if (!uid_eq(new->uid, old->uid)) {
     489                 :         28 :                 retval = set_user(new);
     490         [ +  - ]:         28 :                 if (retval < 0)
     491                 :            :                         goto error;
     492                 :            :         }
     493 [ +  + ][ +  + ]:         89 :         if (ruid != (uid_t) -1 ||
     494         [ +  + ]:         41 :             (euid != (uid_t) -1 && !uid_eq(keuid, old->uid)))
     495                 :         59 :                 new->suid = new->euid;
     496                 :         89 :         new->fsuid = new->euid;
     497                 :            : 
     498                 :         89 :         retval = security_task_fix_setuid(new, old, LSM_SETID_RE);
     499         [ +  - ]:         89 :         if (retval < 0)
     500                 :            :                 goto error;
     501                 :            : 
     502                 :         89 :         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         [ +  - ]:        716 :         if (!uid_valid(kuid))
     530                 :            :                 return -EINVAL;
     531                 :            : 
     532                 :        716 :         new = prepare_creds();
     533         [ +  - ]:        716 :         if (!new)
     534                 :            :                 return -ENOMEM;
     535                 :        716 :         old = current_cred();
     536                 :            : 
     537                 :            :         retval = -EPERM;
     538         [ +  + ]:        716 :         if (ns_capable(old->user_ns, CAP_SETUID)) {
     539                 :        710 :                 new->suid = new->uid = kuid;
     540         [ +  + ]:        710 :                 if (!uid_eq(kuid, old->uid)) {
     541                 :        135 :                         retval = set_user(new);
     542         [ +  - ]:        135 :                         if (retval < 0)
     543                 :            :                                 goto error;
     544                 :            :                 }
     545 [ +  + ][ -  + ]:          6 :         } else if (!uid_eq(kuid, old->uid) && !uid_eq(kuid, new->suid)) {
     546                 :            :                 goto error;
     547                 :            :         }
     548                 :            : 
     549                 :        714 :         new->fsuid = new->euid = kuid;
     550                 :            : 
     551                 :        714 :         retval = security_task_fix_setuid(new, old, LSM_SETID_ID);
     552         [ +  - ]:        714 :         if (retval < 0)
     553                 :            :                 goto error;
     554                 :            : 
     555                 :        714 :         return commit_creds(new);
     556                 :            : 
     557                 :            : error:
     558                 :          2 :         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 [ +  + ][ +  - ]:       7569 :         if ((ruid != (uid_t) -1) && !uid_valid(kruid))
     580                 :            :                 return -EINVAL;
     581                 :            : 
     582 [ +  + ][ +  - ]:       7569 :         if ((euid != (uid_t) -1) && !uid_valid(keuid))
     583                 :            :                 return -EINVAL;
     584                 :            : 
     585 [ +  + ][ +  - ]:       7569 :         if ((suid != (uid_t) -1) && !uid_valid(ksuid))
     586                 :            :                 return -EINVAL;
     587                 :            : 
     588                 :       7569 :         new = prepare_creds();
     589         [ +  - ]:       7569 :         if (!new)
     590                 :            :                 return -ENOMEM;
     591                 :            : 
     592                 :       7569 :         old = current_cred();
     593                 :            : 
     594                 :            :         retval = -EPERM;
     595         [ +  + ]:       7569 :         if (!ns_capable(old->user_ns, CAP_SETUID)) {
     596 [ +  + ][ +  + ]:       1795 :                 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 [ +  + ][ +  + ]:       9362 :                 if (euid != (uid_t) -1        && !uid_eq(keuid, old->uid) &&
                 [ +  + ]
     600         [ -  + ]:          4 :                     !uid_eq(keuid, old->euid) && !uid_eq(keuid, old->suid))
     601                 :            :                         goto error;
     602 [ +  + ][ +  + ]:       9358 :                 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         [ +  + ]:       7559 :         if (ruid != (uid_t) -1) {
     608                 :        649 :                 new->uid = kruid;
     609         [ +  + ]:        649 :                 if (!uid_eq(kruid, old->uid)) {
     610                 :        170 :                         retval = set_user(new);
     611         [ +  - ]:        170 :                         if (retval < 0)
     612                 :            :                                 goto error;
     613                 :            :                 }
     614                 :            :         }
     615         [ +  + ]:       7559 :         if (euid != (uid_t) -1)
     616                 :       5655 :                 new->euid = keuid;
     617         [ +  + ]:       7559 :         if (suid != (uid_t) -1)
     618                 :        653 :                 new->suid = ksuid;
     619                 :       7559 :         new->fsuid = new->euid;
     620                 :            : 
     621                 :       7559 :         retval = security_task_fix_setuid(new, old, LSM_SETID_RES);
     622         [ +  - ]:       7559 :         if (retval < 0)
     623                 :            :                 goto error;
     624                 :            : 
     625                 :       7559 :         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                 :            :         ruid = from_kuid_munged(cred->user_ns, cred->uid);
     639                 :            :         euid = from_kuid_munged(cred->user_ns, cred->euid);
     640                 :            :         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 [ +  + ][ +  - ]:       4249 :         if ((rgid != (gid_t) -1) && !gid_valid(krgid))
     665                 :            :                 return -EINVAL;
     666 [ +  + ][ +  - ]:       4249 :         if ((egid != (gid_t) -1) && !gid_valid(kegid))
     667                 :            :                 return -EINVAL;
     668 [ +  + ][ +  - ]:       4249 :         if ((sgid != (gid_t) -1) && !gid_valid(ksgid))
     669                 :            :                 return -EINVAL;
     670                 :            : 
     671                 :       4249 :         new = prepare_creds();
     672         [ +  - ]:       4249 :         if (!new)
     673                 :            :                 return -ENOMEM;
     674                 :       4249 :         old = current_cred();
     675                 :            : 
     676                 :            :         retval = -EPERM;
     677         [ +  + ]:       4249 :         if (!ns_capable(old->user_ns, CAP_SETGID)) {
     678 [ +  + ][ +  - ]:        291 :                 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 [ +  + ][ +  + ]:       4536 :                 if (egid != (gid_t) -1        && !gid_eq(kegid, old->gid) &&
                 [ +  + ]
     682         [ +  + ]:          4 :                     !gid_eq(kegid, old->egid) && !gid_eq(kegid, old->sgid))
     683                 :            :                         goto error;
     684 [ +  + ][ +  - ]:       4534 :                 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         [ +  + ]:       4241 :         if (rgid != (gid_t) -1)
     690                 :         12 :                 new->gid = krgid;
     691         [ +  + ]:       4241 :         if (egid != (gid_t) -1)
     692                 :       1235 :                 new->egid = kegid;
     693         [ +  + ]:       4241 :         if (sgid != (gid_t) -1)
     694                 :         14 :                 new->sgid = ksgid;
     695                 :       4241 :         new->fsgid = new->egid;
     696                 :            : 
     697                 :       4241 :         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                 :            :         rgid = from_kgid_munged(cred->user_ns, cred->gid);
     711                 :            :         egid = from_kgid_munged(cred->user_ns, cred->egid);
     712                 :            :         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                 :            :         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                 :            :         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                 :      15468 :         return task_tgid_vnr(current);
     814                 :            : }
     815                 :            : 
     816                 :            : /* Thread ID - the internal kernel "pid" */
     817                 :          0 : SYSCALL_DEFINE0(gettid)
     818                 :            : {
     819                 :        224 :         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                 :      59821 :         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
     834                 :            :         rcu_read_unlock();
     835                 :            : 
     836                 :      59821 :         return pid;
     837                 :            : }
     838                 :            : 
     839                 :          0 : SYSCALL_DEFINE0(getuid)
     840                 :            : {
     841                 :            :         /* Only we change this so SMP safe */
     842                 :     252283 :         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                 :      25079 :         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                 :      16596 :         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                 :      15426 :         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                 :    5593386 :         spin_lock_irq(&current->sighand->siglock);
     868                 :    5593386 :         thread_group_cputime_adjusted(current, &tgutime, &tgstime);
     869                 :    5593386 :         cutime = current->signal->cutime;
     870                 :    5593386 :         cstime = current->signal->cstime;
     871                 :    5593386 :         spin_unlock_irq(&current->sighand->siglock);
     872                 :    5593386 :         tms->tms_utime = cputime_to_clock_t(tgutime);
     873                 :    5593386 :         tms->tms_stime = cputime_to_clock_t(tgstime);
     874                 :    5593386 :         tms->tms_cutime = cputime_to_clock_t(cutime);
     875                 :    5593386 :         tms->tms_cstime = cputime_to_clock_t(cstime);
     876                 :    5593386 : }
     877                 :            : 
     878                 :          0 : SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
     879                 :            : {
     880         [ +  - ]:    5593386 :         if (tbuf) {
     881                 :            :                 struct tms tmp;
     882                 :            : 
     883                 :    5593386 :                 do_sys_times(&tmp);
     884         [ -  + ]:   11186772 :                 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
     885                 :    5593386 :                         return -EFAULT;
     886                 :            :         }
     887                 :            :         force_successful_syscall_return();
     888                 :    5593386 :         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                 :            :  * !PF_FORKNOEXEC check to conform completely to POSIX.
     901                 :            :  */
     902                 :          0 : SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
     903                 :            : {
     904                 :            :         struct task_struct *p;
     905                 :       1433 :         struct task_struct *group_leader = current->group_leader;
     906                 :            :         struct pid *pgrp;
     907                 :            :         int err;
     908                 :            : 
     909         [ +  + ]:       1433 :         if (!pid)
     910                 :            :                 pid = task_pid_vnr(group_leader);
     911         [ +  + ]:       1433 :         if (!pgid)
     912                 :            :                 pgid = pid;
     913         [ +  + ]:       1433 :         if (pgid < 0)
     914                 :            :                 return -EINVAL;
     915                 :            :         rcu_read_lock();
     916                 :            : 
     917                 :            :         /* From this point forward we keep holding onto the tasklist lock
     918                 :            :          * so that our parent does not change from under us. -DaveM
     919                 :            :          */
     920                 :       1432 :         write_lock_irq(&tasklist_lock);
     921                 :            : 
     922                 :            :         err = -ESRCH;
     923                 :       1432 :         p = find_task_by_vpid(pid);
     924         [ +  + ]:       1432 :         if (!p)
     925                 :            :                 goto out;
     926                 :            : 
     927                 :            :         err = -EINVAL;
     928         [ +  - ]:       1431 :         if (!thread_group_leader(p))
     929                 :            :                 goto out;
     930                 :            : 
     931         [ +  + ]:       1431 :         if (same_thread_group(p->real_parent, group_leader)) {
     932                 :            :                 err = -EPERM;
     933         [ +  + ]:         20 :                 if (task_session(p) != task_session(group_leader))
     934                 :            :                         goto out;
     935                 :            :                 err = -EACCES;
     936         [ +  + ]:         19 :                 if (!(p->flags & PF_FORKNOEXEC))
     937                 :            :                         goto out;
     938                 :            :         } else {
     939                 :            :                 err = -ESRCH;
     940         [ +  - ]:       1411 :                 if (p != group_leader)
     941                 :            :                         goto out;
     942                 :            :         }
     943                 :            : 
     944                 :            :         err = -EPERM;
     945         [ +  - ]:       1429 :         if (p->signal->leader)
     946                 :            :                 goto out;
     947                 :            : 
     948                 :            :         pgrp = task_pid(p);
     949         [ +  + ]:       1429 :         if (pgid != pid) {
     950                 :            :                 struct task_struct *g;
     951                 :            : 
     952                 :          7 :                 pgrp = find_vpid(pgid);
     953                 :          7 :                 g = pid_task(pgrp, PIDTYPE_PGID);
     954 [ +  + ][ +  - ]:          7 :                 if (!g || task_session(g) != task_session(group_leader))
     955                 :            :                         goto out;
     956                 :            :         }
     957                 :            : 
     958                 :       1428 :         err = security_task_setpgid(p, pgid);
     959         [ +  - ]:       1428 :         if (err)
     960                 :            :                 goto out;
     961                 :            : 
     962         [ +  + ]:       1428 :         if (task_pgrp(p) != pgrp)
     963                 :       1408 :                 change_pid(p, PIDTYPE_PGID, pgrp);
     964                 :            : 
     965                 :            :         err = 0;
     966                 :            : out:
     967                 :            :         /* All paths lead to here, thus we are safe. -DaveM */
     968                 :            :         write_unlock_irq(&tasklist_lock);
     969                 :            :         rcu_read_unlock();
     970                 :            :         return err;
     971                 :            : }
     972                 :            : 
     973                 :          0 : SYSCALL_DEFINE1(getpgid, pid_t, pid)
     974                 :            : {
     975                 :            :         struct task_struct *p;
     976                 :            :         struct pid *grp;
     977                 :            :         int retval;
     978                 :            : 
     979                 :            :         rcu_read_lock();
     980         [ +  + ]:       1273 :         if (!pid)
     981                 :       1235 :                 grp = task_pgrp(current);
     982                 :            :         else {
     983                 :            :                 retval = -ESRCH;
     984                 :         38 :                 p = find_task_by_vpid(pid);
     985         [ +  + ]:         38 :                 if (!p)
     986                 :            :                         goto out;
     987                 :            :                 grp = task_pgrp(p);
     988         [ +  - ]:         36 :                 if (!grp)
     989                 :            :                         goto out;
     990                 :            : 
     991                 :         36 :                 retval = security_task_getpgid(p);
     992         [ +  - ]:         36 :                 if (retval)
     993                 :            :                         goto out;
     994                 :            :         }
     995                 :       1271 :         retval = pid_vnr(grp);
     996                 :            : out:
     997                 :            :         rcu_read_unlock();
     998                 :            :         return retval;
     999                 :            : }
    1000                 :            : 
    1001                 :            : #ifdef __ARCH_WANT_SYS_GETPGRP
    1002                 :            : 
    1003                 :          0 : SYSCALL_DEFINE0(getpgrp)
    1004                 :            : {
    1005                 :        679 :         return sys_getpgid(0);
    1006                 :            : }
    1007                 :            : 
    1008                 :            : #endif
    1009                 :            : 
    1010                 :          0 : SYSCALL_DEFINE1(getsid, pid_t, pid)
    1011                 :            : {
    1012                 :            :         struct task_struct *p;
    1013                 :            :         struct pid *sid;
    1014                 :            :         int retval;
    1015                 :            : 
    1016                 :            :         rcu_read_lock();
    1017         [ +  + ]:        557 :         if (!pid)
    1018                 :        556 :                 sid = task_session(current);
    1019                 :            :         else {
    1020                 :            :                 retval = -ESRCH;
    1021                 :          1 :                 p = find_task_by_vpid(pid);
    1022         [ -  + ]:          1 :                 if (!p)
    1023                 :            :                         goto out;
    1024                 :            :                 sid = task_session(p);
    1025         [ #  # ]:          0 :                 if (!sid)
    1026                 :            :                         goto out;
    1027                 :            : 
    1028                 :          0 :                 retval = security_task_getsid(p);
    1029         [ #  # ]:          0 :                 if (retval)
    1030                 :            :                         goto out;
    1031                 :            :         }
    1032                 :        556 :         retval = pid_vnr(sid);
    1033                 :            : out:
    1034                 :            :         rcu_read_unlock();
    1035                 :            :         return retval;
    1036                 :            : }
    1037                 :            : 
    1038                 :          0 : static void set_special_pids(struct pid *pid)
    1039                 :            : {
    1040                 :        100 :         struct task_struct *curr = current->group_leader;
    1041                 :            : 
    1042         [ +  - ]:        100 :         if (task_session(curr) != pid)
    1043                 :        100 :                 change_pid(curr, PIDTYPE_SID, pid);
    1044                 :            : 
    1045         [ +  - ]:        100 :         if (task_pgrp(curr) != pid)
    1046                 :        100 :                 change_pid(curr, PIDTYPE_PGID, pid);
    1047                 :        100 : }
    1048                 :            : 
    1049                 :          0 : SYSCALL_DEFINE0(setsid)
    1050                 :            : {
    1051                 :        101 :         struct task_struct *group_leader = current->group_leader;
    1052                 :            :         struct pid *sid = task_pid(group_leader);
    1053                 :        101 :         pid_t session = pid_vnr(sid);
    1054                 :            :         int err = -EPERM;
    1055                 :            : 
    1056                 :        101 :         write_lock_irq(&tasklist_lock);
    1057                 :            :         /* Fail if I am already a session leader */
    1058         [ +  - ]:        101 :         if (group_leader->signal->leader)
    1059                 :            :                 goto out;
    1060                 :            : 
    1061                 :            :         /* Fail if a process group id already exists that equals the
    1062                 :            :          * proposed session id.
    1063                 :            :          */
    1064         [ +  + ]:        101 :         if (pid_task(sid, PIDTYPE_PGID))
    1065                 :            :                 goto out;
    1066                 :            : 
    1067                 :        100 :         group_leader->signal->leader = 1;
    1068                 :        100 :         set_special_pids(sid);
    1069                 :            : 
    1070                 :        100 :         proc_clear_tty(group_leader);
    1071                 :            : 
    1072                 :            :         err = session;
    1073                 :            : out:
    1074                 :            :         write_unlock_irq(&tasklist_lock);
    1075         [ +  + ]:        101 :         if (err > 0) {
    1076                 :        100 :                 proc_sid_connector(group_leader);
    1077                 :            :                 sched_autogroup_create_attach(group_leader);
    1078                 :            :         }
    1079                 :        101 :         return err;
    1080                 :            : }
    1081                 :            : 
    1082                 :            : DECLARE_RWSEM(uts_sem);
    1083                 :            : 
    1084                 :            : #ifdef COMPAT_UTS_MACHINE
    1085                 :            : #define override_architecture(name) \
    1086                 :            :         (personality(current->personality) == PER_LINUX32 && \
    1087                 :            :          copy_to_user(name->machine, COMPAT_UTS_MACHINE, \
    1088                 :            :                       sizeof(COMPAT_UTS_MACHINE)))
    1089                 :            : #else
    1090                 :            : #define override_architecture(name)     0
    1091                 :            : #endif
    1092                 :            : 
    1093                 :            : /*
    1094                 :            :  * Work around broken programs that cannot handle "Linux 3.0".
    1095                 :            :  * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
    1096                 :            :  */
    1097                 :          0 : static int override_release(char __user *release, size_t len)
    1098                 :            : {
    1099                 :            :         int ret = 0;
    1100                 :            : 
    1101         [ -  + ]:      29271 :         if (current->personality & UNAME26) {
    1102                 :            :                 const char *rest = UTS_RELEASE;
    1103                 :          0 :                 char buf[65] = { 0 };
    1104                 :            :                 int ndots = 0;
    1105                 :            :                 unsigned v;
    1106                 :            :                 size_t copy;
    1107                 :            : 
    1108         [ #  # ]:          0 :                 while (*rest) {
    1109 [ #  # ][ #  # ]:          0 :                         if (*rest == '.' && ++ndots >= 3)
    1110                 :            :                                 break;
    1111 [ #  # ][ #  # ]:          0 :                         if (!isdigit(*rest) && *rest != '.')
    1112                 :            :                                 break;
    1113                 :          0 :                         rest++;
    1114                 :            :                 }
    1115                 :            :                 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
    1116                 :          0 :                 copy = clamp_t(size_t, len, 1, sizeof(buf));
    1117                 :          0 :                 copy = scnprintf(buf, copy, "2.6.%u%s", v, rest);
    1118                 :          0 :                 ret = copy_to_user(release, buf, copy + 1);
    1119                 :            :         }
    1120                 :      29271 :         return ret;
    1121                 :            : }
    1122                 :            : 
    1123                 :          0 : SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
    1124                 :            : {
    1125                 :            :         int errno = 0;
    1126                 :            : 
    1127                 :      29272 :         down_read(&uts_sem);
    1128         [ +  + ]:      29272 :         if (copy_to_user(name, utsname(), sizeof *name))
    1129                 :            :                 errno = -EFAULT;
    1130                 :      29272 :         up_read(&uts_sem);
    1131                 :            : 
    1132 [ +  + ][ -  + ]:      29272 :         if (!errno && override_release(name->release, sizeof(name->release)))
    1133                 :            :                 errno = -EFAULT;
    1134                 :            :         if (!errno && override_architecture(name))
    1135                 :            :                 errno = -EFAULT;
    1136                 :            :         return errno;
    1137                 :            : }
    1138                 :            : 
    1139                 :            : #ifdef __ARCH_WANT_SYS_OLD_UNAME
    1140                 :            : /*
    1141                 :            :  * Old cruft
    1142                 :            :  */
    1143                 :            : SYSCALL_DEFINE1(uname, struct old_utsname __user *, name)
    1144                 :            : {
    1145                 :            :         int error = 0;
    1146                 :            : 
    1147                 :            :         if (!name)
    1148                 :            :                 return -EFAULT;
    1149                 :            : 
    1150                 :            :         down_read(&uts_sem);
    1151                 :            :         if (copy_to_user(name, utsname(), sizeof(*name)))
    1152                 :            :                 error = -EFAULT;
    1153                 :            :         up_read(&uts_sem);
    1154                 :            : 
    1155                 :            :         if (!error && override_release(name->release, sizeof(name->release)))
    1156                 :            :                 error = -EFAULT;
    1157                 :            :         if (!error && override_architecture(name))
    1158                 :            :                 error = -EFAULT;
    1159                 :            :         return error;
    1160                 :            : }
    1161                 :            : 
    1162                 :            : SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
    1163                 :            : {
    1164                 :            :         int error;
    1165                 :            : 
    1166                 :            :         if (!name)
    1167                 :            :                 return -EFAULT;
    1168                 :            :         if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
    1169                 :            :                 return -EFAULT;
    1170                 :            : 
    1171                 :            :         down_read(&uts_sem);
    1172                 :            :         error = __copy_to_user(&name->sysname, &utsname()->sysname,
    1173                 :            :                                __OLD_UTS_LEN);
    1174                 :            :         error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
    1175                 :            :         error |= __copy_to_user(&name->nodename, &utsname()->nodename,
    1176                 :            :                                 __OLD_UTS_LEN);
    1177                 :            :         error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
    1178                 :            :         error |= __copy_to_user(&name->release, &utsname()->release,
    1179                 :            :                                 __OLD_UTS_LEN);
    1180                 :            :         error |= __put_user(0, name->release + __OLD_UTS_LEN);
    1181                 :            :         error |= __copy_to_user(&name->version, &utsname()->version,
    1182                 :            :                                 __OLD_UTS_LEN);
    1183                 :            :         error |= __put_user(0, name->version + __OLD_UTS_LEN);
    1184                 :            :         error |= __copy_to_user(&name->machine, &utsname()->machine,
    1185                 :            :                                 __OLD_UTS_LEN);
    1186                 :            :         error |= __put_user(0, name->machine + __OLD_UTS_LEN);
    1187                 :            :         up_read(&uts_sem);
    1188                 :            : 
    1189                 :            :         if (!error && override_architecture(name))
    1190                 :            :                 error = -EFAULT;
    1191                 :            :         if (!error && override_release(name->release, sizeof(name->release)))
    1192                 :            :                 error = -EFAULT;
    1193                 :            :         return error ? -EFAULT : 0;
    1194                 :            : }
    1195                 :            : #endif
    1196                 :            : 
    1197                 :          0 : SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
    1198                 :            : {
    1199                 :            :         int errno;
    1200                 :            :         char tmp[__NEW_UTS_LEN];
    1201                 :            : 
    1202         [ +  + ]:          8 :         if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
    1203                 :            :                 return -EPERM;
    1204                 :            : 
    1205         [ +  + ]:          7 :         if (len < 0 || len > __NEW_UTS_LEN)
    1206                 :            :                 return -EINVAL;
    1207                 :          5 :         down_write(&uts_sem);
    1208                 :            :         errno = -EFAULT;
    1209         [ +  + ]:          5 :         if (!copy_from_user(tmp, name, len)) {
    1210                 :            :                 struct new_utsname *u = utsname();
    1211                 :            : 
    1212                 :          4 :                 memcpy(u->nodename, tmp, len);
    1213         [ +  - ]:          4 :                 memset(u->nodename + len, 0, sizeof(u->nodename) - len);
    1214                 :            :                 errno = 0;
    1215                 :          4 :                 uts_proc_notify(UTS_PROC_HOSTNAME);
    1216                 :            :         }
    1217                 :          5 :         up_write(&uts_sem);
    1218                 :            :         return errno;
    1219                 :            : }
    1220                 :            : 
    1221                 :            : #ifdef __ARCH_WANT_SYS_GETHOSTNAME
    1222                 :            : 
    1223                 :          0 : SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
    1224                 :            : {
    1225                 :            :         int i, errno;
    1226                 :            :         struct new_utsname *u;
    1227                 :            : 
    1228         [ #  # ]:          0 :         if (len < 0)
    1229                 :            :                 return -EINVAL;
    1230                 :          0 :         down_read(&uts_sem);
    1231                 :            :         u = utsname();
    1232                 :          0 :         i = 1 + strlen(u->nodename);
    1233         [ #  # ]:          0 :         if (i > len)
    1234                 :            :                 i = len;
    1235                 :            :         errno = 0;
    1236         [ #  # ]:          0 :         if (copy_to_user(name, u->nodename, i))
    1237                 :            :                 errno = -EFAULT;
    1238                 :          0 :         up_read(&uts_sem);
    1239                 :            :         return errno;
    1240                 :            : }
    1241                 :            : 
    1242                 :            : #endif
    1243                 :            : 
    1244                 :            : /*
    1245                 :            :  * Only setdomainname; getdomainname can be implemented by calling
    1246                 :            :  * uname()
    1247                 :            :  */
    1248                 :          0 : SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
    1249                 :            : {
    1250                 :            :         int errno;
    1251                 :            :         char tmp[__NEW_UTS_LEN];
    1252                 :            : 
    1253         [ +  + ]:          8 :         if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
    1254                 :            :                 return -EPERM;
    1255         [ +  + ]:          7 :         if (len < 0 || len > __NEW_UTS_LEN)
    1256                 :            :                 return -EINVAL;
    1257                 :            : 
    1258                 :          5 :         down_write(&uts_sem);
    1259                 :            :         errno = -EFAULT;
    1260         [ +  + ]:          5 :         if (!copy_from_user(tmp, name, len)) {
    1261                 :            :                 struct new_utsname *u = utsname();
    1262                 :            : 
    1263                 :          4 :                 memcpy(u->domainname, tmp, len);
    1264         [ +  - ]:          4 :                 memset(u->domainname + len, 0, sizeof(u->domainname) - len);
    1265                 :            :                 errno = 0;
    1266                 :          4 :                 uts_proc_notify(UTS_PROC_DOMAINNAME);
    1267                 :            :         }
    1268                 :          5 :         up_write(&uts_sem);
    1269                 :            :         return errno;
    1270                 :            : }
    1271                 :            : 
    1272                 :          0 : SYSCALL_DEFINE2(getrlimit, unsigned int, resource, struct rlimit __user *, rlim)
    1273                 :            : {
    1274                 :            :         struct rlimit value;
    1275                 :            :         int ret;
    1276                 :            : 
    1277                 :       5791 :         ret = do_prlimit(current, resource, NULL, &value);
    1278         [ +  + ]:       5791 :         if (!ret)
    1279         [ +  + ]:      11581 :                 ret = copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
    1280                 :            : 
    1281                 :            :         return ret;
    1282                 :            : }
    1283                 :            : 
    1284                 :            : #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
    1285                 :            : 
    1286                 :            : /*
    1287                 :            :  *      Back compatibility for getrlimit. Needed for some apps.
    1288                 :            :  */
    1289                 :            :  
    1290                 :            : SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
    1291                 :            :                 struct rlimit __user *, rlim)
    1292                 :            : {
    1293                 :            :         struct rlimit x;
    1294                 :            :         if (resource >= RLIM_NLIMITS)
    1295                 :            :                 return -EINVAL;
    1296                 :            : 
    1297                 :            :         task_lock(current->group_leader);
    1298                 :            :         x = current->signal->rlim[resource];
    1299                 :            :         task_unlock(current->group_leader);
    1300                 :            :         if (x.rlim_cur > 0x7FFFFFFF)
    1301                 :            :                 x.rlim_cur = 0x7FFFFFFF;
    1302                 :            :         if (x.rlim_max > 0x7FFFFFFF)
    1303                 :            :                 x.rlim_max = 0x7FFFFFFF;
    1304                 :            :         return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
    1305                 :            : }
    1306                 :            : 
    1307                 :            : #endif
    1308                 :            : 
    1309                 :            : static inline bool rlim64_is_infinity(__u64 rlim64)
    1310                 :            : {
    1311                 :            : #if BITS_PER_LONG < 64
    1312                 :            :         return rlim64 >= ULONG_MAX;
    1313                 :            : #else
    1314                 :            :         return rlim64 == RLIM64_INFINITY;
    1315                 :            : #endif
    1316                 :            : }
    1317                 :            : 
    1318                 :          0 : static void rlim_to_rlim64(const struct rlimit *rlim, struct rlimit64 *rlim64)
    1319                 :            : {
    1320         [ +  + ]:       2262 :         if (rlim->rlim_cur == RLIM_INFINITY)
    1321                 :        926 :                 rlim64->rlim_cur = RLIM64_INFINITY;
    1322                 :            :         else
    1323                 :       1336 :                 rlim64->rlim_cur = rlim->rlim_cur;
    1324         [ +  + ]:       2262 :         if (rlim->rlim_max == RLIM_INFINITY)
    1325                 :       1547 :                 rlim64->rlim_max = RLIM64_INFINITY;
    1326                 :            :         else
    1327                 :        715 :                 rlim64->rlim_max = rlim->rlim_max;
    1328                 :       2262 : }
    1329                 :            : 
    1330                 :          0 : static void rlim64_to_rlim(const struct rlimit64 *rlim64, struct rlimit *rlim)
    1331                 :            : {
    1332         [ +  + ]:       2604 :         if (rlim64_is_infinity(rlim64->rlim_cur))
    1333                 :        723 :                 rlim->rlim_cur = RLIM_INFINITY;
    1334                 :            :         else
    1335                 :       1881 :                 rlim->rlim_cur = (unsigned long)rlim64->rlim_cur;
    1336         [ +  + ]:       2604 :         if (rlim64_is_infinity(rlim64->rlim_max))
    1337                 :       1890 :                 rlim->rlim_max = RLIM_INFINITY;
    1338                 :            :         else
    1339                 :        714 :                 rlim->rlim_max = (unsigned long)rlim64->rlim_max;
    1340                 :       2604 : }
    1341                 :            : 
    1342                 :            : /* make sure you are allowed to change @tsk limits before calling this */
    1343                 :          0 : int do_prlimit(struct task_struct *tsk, unsigned int resource,
    1344                 :            :                 struct rlimit *new_rlim, struct rlimit *old_rlim)
    1345                 :            : {
    1346                 :            :         struct rlimit *rlim;
    1347                 :            :         int retval = 0;
    1348                 :            : 
    1349         [ +  + ]:      10921 :         if (resource >= RLIM_NLIMITS)
    1350                 :            :                 return -EINVAL;
    1351         [ +  + ]:      10919 :         if (new_rlim) {
    1352         [ +  - ]:       2867 :                 if (new_rlim->rlim_cur > new_rlim->rlim_max)
    1353                 :            :                         return -EINVAL;
    1354 [ +  + ][ +  + ]:       2867 :                 if (resource == RLIMIT_NOFILE &&
    1355                 :         26 :                                 new_rlim->rlim_max > sysctl_nr_open)
    1356                 :            :                         return -EPERM;
    1357                 :            :         }
    1358                 :            : 
    1359                 :            :         /* protect tsk->signal and tsk->sighand from disappearing */
    1360                 :      10918 :         read_lock(&tasklist_lock);
    1361         [ +  - ]:      10918 :         if (!tsk->sighand) {
    1362                 :            :                 retval = -ESRCH;
    1363                 :            :                 goto out;
    1364                 :            :         }
    1365                 :            : 
    1366                 :      10918 :         rlim = tsk->signal->rlim + resource;
    1367                 :      10918 :         task_lock(tsk->group_leader);
    1368         [ +  + ]:      10918 :         if (new_rlim) {
    1369                 :            :                 /* Keep the capable check against init_user_ns until
    1370                 :            :                    cgroups can contain all limits */
    1371   [ +  +  +  + ]:       3425 :                 if (new_rlim->rlim_max > rlim->rlim_max &&
    1372                 :        559 :                                 !capable(CAP_SYS_RESOURCE))
    1373                 :            :                         retval = -EPERM;
    1374         [ +  + ]:       2866 :                 if (!retval)
    1375                 :       2865 :                         retval = security_task_setrlimit(tsk->group_leader,
    1376                 :            :                                         resource, new_rlim);
    1377 [ +  + ][ -  + ]:       2866 :                 if (resource == RLIMIT_CPU && new_rlim->rlim_cur == 0) {
    1378                 :            :                         /*
    1379                 :            :                          * The caller is asking for an immediate RLIMIT_CPU
    1380                 :            :                          * expiry.  But we use the zero value to mean "it was
    1381                 :            :                          * never set".  So let's cheat and make it one second
    1382                 :            :                          * instead
    1383                 :            :                          */
    1384                 :          0 :                         new_rlim->rlim_cur = 1;
    1385                 :            :                 }
    1386                 :            :         }
    1387         [ +  + ]:      10918 :         if (!retval) {
    1388         [ +  + ]:      10917 :                 if (old_rlim)
    1389                 :       8052 :                         *old_rlim = *rlim;
    1390         [ +  + ]:      10917 :                 if (new_rlim)
    1391                 :       2865 :                         *rlim = *new_rlim;
    1392                 :            :         }
    1393                 :          0 :         task_unlock(tsk->group_leader);
    1394                 :            : 
    1395                 :            :         /*
    1396                 :            :          * RLIMIT_CPU handling.   Note that the kernel fails to return an error
    1397                 :            :          * code if it rejected the user's attempt to set RLIMIT_CPU.  This is a
    1398                 :            :          * very long-standing error, and fixing it now risks breakage of
    1399                 :            :          * applications, so we live with it
    1400                 :            :          */
    1401 [ +  + ][ +  + ]:      10918 :          if (!retval && new_rlim && resource == RLIMIT_CPU &&
                 [ -  + ]
    1402                 :         23 :                          new_rlim->rlim_cur != RLIM_INFINITY)
    1403                 :          0 :                 update_rlimit_cpu(tsk, new_rlim->rlim_cur);
    1404                 :            : out:
    1405                 :            :         read_unlock(&tasklist_lock);
    1406                 :      10918 :         return retval;
    1407                 :            : }
    1408                 :            : 
    1409                 :            : /* rcu lock must be held */
    1410                 :          0 : static int check_prlimit_permission(struct task_struct *task)
    1411                 :            : {
    1412                 :       4866 :         const struct cred *cred = current_cred(), *tcred;
    1413                 :            : 
    1414         [ -  + ]:       4866 :         if (current == task)
    1415                 :            :                 return 0;
    1416                 :            : 
    1417                 :          0 :         tcred = __task_cred(task);
    1418 [ #  # ][ #  # ]:          0 :         if (uid_eq(cred->uid, tcred->euid) &&
    1419         [ #  # ]:          0 :             uid_eq(cred->uid, tcred->suid) &&
    1420         [ #  # ]:          0 :             uid_eq(cred->uid, tcred->uid)  &&
    1421         [ #  # ]:          0 :             gid_eq(cred->gid, tcred->egid) &&
    1422         [ #  # ]:          0 :             gid_eq(cred->gid, tcred->sgid) &&
    1423                 :            :             gid_eq(cred->gid, tcred->gid))
    1424                 :            :                 return 0;
    1425         [ #  # ]:          0 :         if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
    1426                 :            :                 return 0;
    1427                 :            : 
    1428                 :          0 :         return -EPERM;
    1429                 :            : }
    1430                 :            : 
    1431                 :          0 : SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
    1432                 :            :                 const struct rlimit64 __user *, new_rlim,
    1433                 :            :                 struct rlimit64 __user *, old_rlim)
    1434                 :            : {
    1435                 :            :         struct rlimit64 old64, new64;
    1436                 :            :         struct rlimit old, new;
    1437                 :            :         struct task_struct *tsk;
    1438                 :            :         int ret;
    1439                 :            : 
    1440         [ +  + ]:       4866 :         if (new_rlim) {
    1441         [ +  - ]:       2604 :                 if (copy_from_user(&new64, new_rlim, sizeof(new64)))
    1442                 :            :                         return -EFAULT;
    1443                 :       2604 :                 rlim64_to_rlim(&new64, &new);
    1444                 :            :         }
    1445                 :            : 
    1446                 :            :         rcu_read_lock();
    1447         [ -  + ]:       4866 :         tsk = pid ? find_task_by_vpid(pid) : current;
    1448         [ -  + ]:       4866 :         if (!tsk) {
    1449                 :            :                 rcu_read_unlock();
    1450                 :            :                 return -ESRCH;
    1451                 :            :         }
    1452                 :       4866 :         ret = check_prlimit_permission(tsk);
    1453         [ -  + ]:       4866 :         if (ret) {
    1454                 :            :                 rcu_read_unlock();
    1455                 :            :                 return ret;
    1456                 :            :         }
    1457                 :       4866 :         get_task_struct(tsk);
    1458                 :            :         rcu_read_unlock();
    1459                 :            : 
    1460 [ +  + ][ +  + ]:       4866 :         ret = do_prlimit(tsk, resource, new_rlim ? &new : NULL,
    1461                 :            :                         old_rlim ? &old : NULL);
    1462                 :            : 
    1463         [ +  + ]:       4866 :         if (!ret && old_rlim) {
    1464                 :       2262 :                 rlim_to_rlim64(&old, &old64);
    1465         [ -  + ]:       2262 :                 if (copy_to_user(old_rlim, &old64, sizeof(old64)))
    1466                 :            :                         ret = -EFAULT;
    1467                 :            :         }
    1468                 :            : 
    1469                 :            :         put_task_struct(tsk);
    1470                 :            :         return ret;
    1471                 :            : }
    1472                 :            : 
    1473                 :          0 : SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
    1474                 :            : {
    1475                 :            :         struct rlimit new_rlim;
    1476                 :            : 
    1477         [ +  + ]:        265 :         if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
    1478                 :            :                 return -EFAULT;
    1479                 :        264 :         return do_prlimit(current, resource, &new_rlim, NULL);
    1480                 :            : }
    1481                 :            : 
    1482                 :            : /*
    1483                 :            :  * It would make sense to put struct rusage in the task_struct,
    1484                 :            :  * except that would make the task_struct be *really big*.  After
    1485                 :            :  * task_struct gets moved into malloc'ed memory, it would
    1486                 :            :  * make sense to do this.  It will make moving the rest of the information
    1487                 :            :  * a lot simpler!  (Which we're not doing right now because we're not
    1488                 :            :  * measuring them yet).
    1489                 :            :  *
    1490                 :            :  * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
    1491                 :            :  * races with threads incrementing their own counters.  But since word
    1492                 :            :  * reads are atomic, we either get new values or old values and we don't
    1493                 :            :  * care which for the sums.  We always take the siglock to protect reading
    1494                 :            :  * the c* fields from p->signal from races with exit.c updating those
    1495                 :            :  * fields when reaping, so a sample either gets all the additions of a
    1496                 :            :  * given child after it's reaped, or none so this sample is before reaping.
    1497                 :            :  *
    1498                 :            :  * Locking:
    1499                 :            :  * We need to take the siglock for CHILDEREN, SELF and BOTH
    1500                 :            :  * for  the cases current multithreaded, non-current single threaded
    1501                 :            :  * non-current multithreaded.  Thread traversal is now safe with
    1502                 :            :  * the siglock held.
    1503                 :            :  * Strictly speaking, we donot need to take the siglock if we are current and
    1504                 :            :  * single threaded,  as no one else can take our signal_struct away, no one
    1505                 :            :  * else can  reap the  children to update signal->c* counters, and no one else
    1506                 :            :  * can race with the signal-> fields. If we do not take any lock, the
    1507                 :            :  * signal-> fields could be read out of order while another thread was just
    1508                 :            :  * exiting. So we should  place a read memory barrier when we avoid the lock.
    1509                 :            :  * On the writer side,  write memory barrier is implied in  __exit_signal
    1510                 :            :  * as __exit_signal releases  the siglock spinlock after updating the signal->
    1511                 :            :  * fields. But we don't do this yet to keep things simple.
    1512                 :            :  *
    1513                 :            :  */
    1514                 :            : 
    1515                 :            : static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r)
    1516                 :            : {
    1517                 :     141950 :         r->ru_nvcsw += t->nvcsw;
    1518                 :     141950 :         r->ru_nivcsw += t->nivcsw;
    1519                 :     141950 :         r->ru_minflt += t->min_flt;
    1520                 :     141950 :         r->ru_majflt += t->maj_flt;
    1521                 :            :         r->ru_inblock += task_io_get_inblock(t);
    1522                 :            :         r->ru_oublock += task_io_get_oublock(t);
    1523                 :            : }
    1524                 :            : 
    1525                 :          0 : static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
    1526                 :            : {
    1527                 :            :         struct task_struct *t;
    1528                 :            :         unsigned long flags;
    1529                 :            :         cputime_t tgutime, tgstime, utime, stime;
    1530                 :            :         unsigned long maxrss = 0;
    1531                 :            : 
    1532                 :     141962 :         memset((char *) r, 0, sizeof *r);
    1533                 :     141962 :         utime = stime = 0;
    1534                 :            : 
    1535         [ +  + ]:     141962 :         if (who == RUSAGE_THREAD) {
    1536                 :     141916 :                 task_cputime_adjusted(current, &utime, &stime);
    1537                 :            :                 accumulate_thread_rusage(p, r);
    1538                 :     141916 :                 maxrss = p->signal->maxrss;
    1539                 :     141916 :                 goto out;
    1540                 :            :         }
    1541                 :            : 
    1542         [ +  - ]:         46 :         if (!lock_task_sighand(p, &flags))
    1543                 :          0 :                 return;
    1544                 :            : 
    1545      [ +  +  - ]:         46 :         switch (who) {
    1546                 :            :                 case RUSAGE_BOTH:
    1547                 :            :                 case RUSAGE_CHILDREN:
    1548                 :         13 :                         utime = p->signal->cutime;
    1549                 :         13 :                         stime = p->signal->cstime;
    1550                 :         13 :                         r->ru_nvcsw = p->signal->cnvcsw;
    1551                 :         13 :                         r->ru_nivcsw = p->signal->cnivcsw;
    1552                 :         13 :                         r->ru_minflt = p->signal->cmin_flt;
    1553                 :         13 :                         r->ru_majflt = p->signal->cmaj_flt;
    1554                 :         13 :                         r->ru_inblock = p->signal->cinblock;
    1555                 :         13 :                         r->ru_oublock = p->signal->coublock;
    1556                 :         13 :                         maxrss = p->signal->cmaxrss;
    1557                 :            : 
    1558         [ +  + ]:         13 :                         if (who == RUSAGE_CHILDREN)
    1559                 :            :                                 break;
    1560                 :            : 
    1561                 :            :                 case RUSAGE_SELF:
    1562                 :         34 :                         thread_group_cputime_adjusted(p, &tgutime, &tgstime);
    1563                 :         34 :                         utime += tgutime;
    1564                 :         34 :                         stime += tgstime;
    1565                 :         34 :                         r->ru_nvcsw += p->signal->nvcsw;
    1566                 :         34 :                         r->ru_nivcsw += p->signal->nivcsw;
    1567                 :         34 :                         r->ru_minflt += p->signal->min_flt;
    1568                 :         34 :                         r->ru_majflt += p->signal->maj_flt;
    1569                 :         34 :                         r->ru_inblock += p->signal->inblock;
    1570                 :         34 :                         r->ru_oublock += p->signal->oublock;
    1571         [ +  + ]:         34 :                         if (maxrss < p->signal->maxrss)
    1572                 :            :                                 maxrss = p->signal->maxrss;
    1573                 :            :                         t = p;
    1574                 :            :                         do {
    1575                 :            :                                 accumulate_thread_rusage(t, r);
    1576         [ -  + ]:         34 :                         } while_each_thread(p, t);
    1577                 :            :                         break;
    1578                 :            : 
    1579                 :            :                 default:
    1580                 :          0 :                         BUG();
    1581                 :            :         }
    1582                 :         46 :         unlock_task_sighand(p, &flags);
    1583                 :            : 
    1584                 :            : out:
    1585                 :     141962 :         cputime_to_timeval(utime, &r->ru_utime);
    1586                 :     141962 :         cputime_to_timeval(stime, &r->ru_stime);
    1587                 :            : 
    1588         [ +  + ]:     141962 :         if (who != RUSAGE_CHILDREN) {
    1589                 :     141950 :                 struct mm_struct *mm = get_task_mm(p);
    1590         [ +  + ]:     141950 :                 if (mm) {
    1591                 :            :                         setmax_mm_hiwater_rss(&maxrss, mm);
    1592                 :     141949 :                         mmput(mm);
    1593                 :            :                 }
    1594                 :            :         }
    1595                 :     141962 :         r->ru_maxrss = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */
    1596                 :            : }
    1597                 :            : 
    1598                 :          0 : int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
    1599                 :            : {
    1600                 :            :         struct rusage r;
    1601                 :     141962 :         k_getrusage(p, who, &r);
    1602         [ +  + ]:     283924 :         return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
    1603                 :            : }
    1604                 :            : 
    1605                 :          0 : SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)
    1606                 :            : {
    1607 [ +  + ][ +  + ]:     141962 :         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
    1608                 :            :             who != RUSAGE_THREAD)
    1609                 :            :                 return -EINVAL;
    1610                 :     141961 :         return getrusage(current, who, ru);
    1611                 :            : }
    1612                 :            : 
    1613                 :            : #ifdef CONFIG_COMPAT
    1614                 :            : COMPAT_SYSCALL_DEFINE2(getrusage, int, who, struct compat_rusage __user *, ru)
    1615                 :            : {
    1616                 :            :         struct rusage r;
    1617                 :            : 
    1618                 :            :         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
    1619                 :            :             who != RUSAGE_THREAD)
    1620                 :            :                 return -EINVAL;
    1621                 :            : 
    1622                 :            :         k_getrusage(current, who, &r);
    1623                 :            :         return put_compat_rusage(&r, ru);
    1624                 :            : }
    1625                 :            : #endif
    1626                 :            : 
    1627                 :          0 : SYSCALL_DEFINE1(umask, int, mask)
    1628                 :            : {
    1629                 :      35016 :         mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
    1630                 :            :         return mask;
    1631                 :            : }
    1632                 :            : 
    1633                 :          0 : static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
    1634                 :            : {
    1635                 :            :         struct fd exe;
    1636                 :            :         struct inode *inode;
    1637                 :            :         int err;
    1638                 :            : 
    1639                 :            :         exe = fdget(fd);
    1640         [ #  # ]:          0 :         if (!exe.file)
    1641                 :            :                 return -EBADF;
    1642                 :            : 
    1643                 :            :         inode = file_inode(exe.file);
    1644                 :            : 
    1645                 :            :         /*
    1646                 :            :          * Because the original mm->exe_file points to executable file, make
    1647                 :            :          * sure that this one is executable as well, to avoid breaking an
    1648                 :            :          * overall picture.
    1649                 :            :          */
    1650                 :            :         err = -EACCES;
    1651 [ #  # ][ #  # ]:          0 :         if (!S_ISREG(inode->i_mode)  ||
    1652                 :          0 :             exe.file->f_path.mnt->mnt_flags & MNT_NOEXEC)
    1653                 :            :                 goto exit;
    1654                 :            : 
    1655                 :          0 :         err = inode_permission(inode, MAY_EXEC);
    1656         [ #  # ]:          0 :         if (err)
    1657                 :            :                 goto exit;
    1658                 :            : 
    1659                 :          0 :         down_write(&mm->mmap_sem);
    1660                 :            : 
    1661                 :            :         /*
    1662                 :            :          * Forbid mm->exe_file change if old file still mapped.
    1663                 :            :          */
    1664                 :            :         err = -EBUSY;
    1665         [ #  # ]:          0 :         if (mm->exe_file) {
    1666                 :            :                 struct vm_area_struct *vma;
    1667                 :            : 
    1668         [ #  # ]:          0 :                 for (vma = mm->mmap; vma; vma = vma->vm_next)
    1669 [ #  # ][ #  # ]:          0 :                         if (vma->vm_file &&
    1670                 :            :                             path_equal(&vma->vm_file->f_path,
    1671                 :            :                                        &mm->exe_file->f_path))
    1672                 :            :                                 goto exit_unlock;
    1673                 :            :         }
    1674                 :            : 
    1675                 :            :         /*
    1676                 :            :          * The symlink can be changed only once, just to disallow arbitrary
    1677                 :            :          * transitions malicious software might bring in. This means one
    1678                 :            :          * could make a snapshot over all processes running and monitor
    1679                 :            :          * /proc/pid/exe changes to notice unusual activity if needed.
    1680                 :            :          */
    1681                 :            :         err = -EPERM;
    1682         [ #  # ]:          0 :         if (test_and_set_bit(MMF_EXE_FILE_CHANGED, &mm->flags))
    1683                 :            :                 goto exit_unlock;
    1684                 :            : 
    1685                 :            :         err = 0;
    1686                 :          0 :         set_mm_exe_file(mm, exe.file);  /* this grabs a reference to exe.file */
    1687                 :            : exit_unlock:
    1688                 :          0 :         up_write(&mm->mmap_sem);
    1689                 :            : 
    1690                 :            : exit:
    1691                 :            :         fdput(exe);
    1692                 :          0 :         return err;
    1693                 :            : }
    1694                 :            : 
    1695                 :          0 : static int prctl_set_mm(int opt, unsigned long addr,
    1696                 :            :                         unsigned long arg4, unsigned long arg5)
    1697                 :            : {
    1698                 :            :         unsigned long rlim = rlimit(RLIMIT_DATA);
    1699                 :          0 :         struct mm_struct *mm = current->mm;
    1700                 :            :         struct vm_area_struct *vma;
    1701                 :            :         int error;
    1702                 :            : 
    1703 [ #  # ][ #  # ]:          0 :         if (arg5 || (arg4 && opt != PR_SET_MM_AUXV))
    1704                 :            :                 return -EINVAL;
    1705                 :            : 
    1706         [ #  # ]:          0 :         if (!capable(CAP_SYS_RESOURCE))
    1707                 :            :                 return -EPERM;
    1708                 :            : 
    1709         [ #  # ]:          0 :         if (opt == PR_SET_MM_EXE_FILE)
    1710                 :          0 :                 return prctl_set_mm_exe_file(mm, (unsigned int)addr);
    1711                 :            : 
    1712 [ #  # ][ #  # ]:          0 :         if (addr >= TASK_SIZE || addr < mmap_min_addr)
    1713                 :            :                 return -EINVAL;
    1714                 :            : 
    1715                 :            :         error = -EINVAL;
    1716                 :            : 
    1717                 :          0 :         down_read(&mm->mmap_sem);
    1718                 :          0 :         vma = find_vma(mm, addr);
    1719                 :            : 
    1720   [ #  #  #  #  :          0 :         switch (opt) {
             #  #  #  #  
                      # ]
    1721                 :            :         case PR_SET_MM_START_CODE:
    1722                 :          0 :                 mm->start_code = addr;
    1723                 :          0 :                 break;
    1724                 :            :         case PR_SET_MM_END_CODE:
    1725                 :          0 :                 mm->end_code = addr;
    1726                 :          0 :                 break;
    1727                 :            :         case PR_SET_MM_START_DATA:
    1728                 :          0 :                 mm->start_data = addr;
    1729                 :          0 :                 break;
    1730                 :            :         case PR_SET_MM_END_DATA:
    1731                 :          0 :                 mm->end_data = addr;
    1732                 :          0 :                 break;
    1733                 :            : 
    1734                 :            :         case PR_SET_MM_START_BRK:
    1735         [ #  # ]:          0 :                 if (addr <= mm->end_data)
    1736                 :            :                         goto out;
    1737                 :            : 
    1738 [ #  # ][ #  # ]:          0 :                 if (rlim < RLIM_INFINITY &&
    1739                 :          0 :                     (mm->brk - addr) +
    1740                 :          0 :                     (mm->end_data - mm->start_data) > rlim)
    1741                 :            :                         goto out;
    1742                 :            : 
    1743                 :          0 :                 mm->start_brk = addr;
    1744                 :          0 :                 break;
    1745                 :            : 
    1746                 :            :         case PR_SET_MM_BRK:
    1747         [ #  # ]:          0 :                 if (addr <= mm->end_data)
    1748                 :            :                         goto out;
    1749                 :            : 
    1750 [ #  # ][ #  # ]:          0 :                 if (rlim < RLIM_INFINITY &&
    1751                 :          0 :                     (addr - mm->start_brk) +
    1752                 :          0 :                     (mm->end_data - mm->start_data) > rlim)
    1753                 :            :                         goto out;
    1754                 :            : 
    1755                 :          0 :                 mm->brk = addr;
    1756                 :          0 :                 break;
    1757                 :            : 
    1758                 :            :         /*
    1759                 :            :          * If command line arguments and environment
    1760                 :            :          * are placed somewhere else on stack, we can
    1761                 :            :          * set them up here, ARG_START/END to setup
    1762                 :            :          * command line argumets and ENV_START/END
    1763                 :            :          * for environment.
    1764                 :            :          */
    1765                 :            :         case PR_SET_MM_START_STACK:
    1766                 :            :         case PR_SET_MM_ARG_START:
    1767                 :            :         case PR_SET_MM_ARG_END:
    1768                 :            :         case PR_SET_MM_ENV_START:
    1769                 :            :         case PR_SET_MM_ENV_END:
    1770         [ #  # ]:          0 :                 if (!vma) {
    1771                 :            :                         error = -EFAULT;
    1772                 :            :                         goto out;
    1773                 :            :                 }
    1774         [ #  # ]:          0 :                 if (opt == PR_SET_MM_START_STACK)
    1775                 :          0 :                         mm->start_stack = addr;
    1776         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ARG_START)
    1777                 :          0 :                         mm->arg_start = addr;
    1778         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ARG_END)
    1779                 :          0 :                         mm->arg_end = addr;
    1780         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ENV_START)
    1781                 :          0 :                         mm->env_start = addr;
    1782         [ #  # ]:          0 :                 else if (opt == PR_SET_MM_ENV_END)
    1783                 :          0 :                         mm->env_end = addr;
    1784                 :            :                 break;
    1785                 :            : 
    1786                 :            :         /*
    1787                 :            :          * This doesn't move auxiliary vector itself
    1788                 :            :          * since it's pinned to mm_struct, but allow
    1789                 :            :          * to fill vector with new values. It's up
    1790                 :            :          * to a caller to provide sane values here
    1791                 :            :          * otherwise user space tools which use this
    1792                 :            :          * vector might be unhappy.
    1793                 :            :          */
    1794                 :            :         case PR_SET_MM_AUXV: {
    1795                 :            :                 unsigned long user_auxv[AT_VECTOR_SIZE];
    1796                 :            : 
    1797         [ #  # ]:          0 :                 if (arg4 > sizeof(user_auxv))
    1798                 :            :                         goto out;
    1799                 :          0 :                 up_read(&mm->mmap_sem);
    1800                 :            : 
    1801         [ #  # ]:          0 :                 if (copy_from_user(user_auxv, (const void __user *)addr, arg4))
    1802                 :          0 :                         return -EFAULT;
    1803                 :            : 
    1804                 :            :                 /* Make sure the last entry is always AT_NULL */
    1805                 :          0 :                 user_auxv[AT_VECTOR_SIZE - 2] = 0;
    1806                 :          0 :                 user_auxv[AT_VECTOR_SIZE - 1] = 0;
    1807                 :            : 
    1808                 :            :                 BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
    1809                 :            : 
    1810                 :          0 :                 task_lock(current);
    1811                 :          0 :                 memcpy(mm->saved_auxv, user_auxv, arg4);
    1812                 :          0 :                 task_unlock(current);
    1813                 :            : 
    1814                 :          0 :                 return 0;
    1815                 :            :         }
    1816                 :            :         default:
    1817                 :            :                 goto out;
    1818                 :            :         }
    1819                 :            : 
    1820                 :            :         error = 0;
    1821                 :            : out:
    1822                 :          0 :         up_read(&mm->mmap_sem);
    1823                 :          0 :         return error;
    1824                 :            : }
    1825                 :            : 
    1826                 :            : #ifdef CONFIG_CHECKPOINT_RESTORE
    1827                 :            : static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
    1828                 :            : {
    1829                 :            :         return put_user(me->clear_child_tid, tid_addr);
    1830                 :            : }
    1831                 :            : #else
    1832                 :          0 : static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
    1833                 :            : {
    1834                 :          0 :         return -EINVAL;
    1835                 :            : }
    1836                 :            : #endif
    1837                 :            : 
    1838                 :            : #ifdef CONFIG_MMU
    1839                 :          0 : static int prctl_update_vma_anon_name(struct vm_area_struct *vma,
    1840                 :            :                 struct vm_area_struct **prev,
    1841                 :            :                 unsigned long start, unsigned long end,
    1842                 :            :                 const char __user *name_addr)
    1843                 :            : {
    1844                 :          0 :         struct mm_struct * mm = vma->vm_mm;
    1845                 :            :         int error = 0;
    1846                 :            :         pgoff_t pgoff;
    1847                 :            : 
    1848         [ #  # ]:          0 :         if (name_addr == vma_get_anon_name(vma)) {
    1849                 :          0 :                 *prev = vma;
    1850                 :          0 :                 goto out;
    1851                 :            :         }
    1852                 :            : 
    1853                 :          0 :         pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
    1854                 :          0 :         *prev = vma_merge(mm, *prev, start, end, vma->vm_flags, vma->anon_vma,
    1855                 :            :                                 vma->vm_file, pgoff, vma_policy(vma),
    1856                 :            :                                 name_addr);
    1857         [ #  # ]:          0 :         if (*prev) {
    1858                 :            :                 vma = *prev;
    1859                 :            :                 goto success;
    1860                 :            :         }
    1861                 :            : 
    1862                 :          0 :         *prev = vma;
    1863                 :            : 
    1864         [ #  # ]:          0 :         if (start != vma->vm_start) {
    1865                 :          0 :                 error = split_vma(mm, vma, start, 1);
    1866         [ #  # ]:          0 :                 if (error)
    1867                 :            :                         goto out;
    1868                 :            :         }
    1869                 :            : 
    1870         [ #  # ]:          0 :         if (end != vma->vm_end) {
    1871                 :          0 :                 error = split_vma(mm, vma, end, 0);
    1872         [ #  # ]:          0 :                 if (error)
    1873                 :            :                         goto out;
    1874                 :            :         }
    1875                 :            : 
    1876                 :            : success:
    1877         [ #  # ]:          0 :         if (!vma->vm_file)
    1878                 :          0 :                 vma->shared.anon_name = name_addr;
    1879                 :            : 
    1880                 :            : out:
    1881         [ #  # ]:          0 :         if (error == -ENOMEM)
    1882                 :            :                 error = -EAGAIN;
    1883                 :          0 :         return error;
    1884                 :            : }
    1885                 :            : 
    1886                 :          0 : static int prctl_set_vma_anon_name(unsigned long start, unsigned long end,
    1887                 :            :                         unsigned long arg)
    1888                 :            : {
    1889                 :            :         unsigned long tmp;
    1890                 :            :         struct vm_area_struct * vma, *prev;
    1891                 :            :         int unmapped_error = 0;
    1892                 :            :         int error = -EINVAL;
    1893                 :            : 
    1894                 :            :         /*
    1895                 :            :          * If the interval [start,end) covers some unmapped address
    1896                 :            :          * ranges, just ignore them, but return -ENOMEM at the end.
    1897                 :            :          * - this matches the handling in madvise.
    1898                 :            :          */
    1899                 :          0 :         vma = find_vma_prev(current->mm, start, &prev);
    1900 [ #  # ][ #  # ]:          0 :         if (vma && start > vma->vm_start)
    1901                 :          0 :                 prev = vma;
    1902                 :            : 
    1903                 :            :         for (;;) {
    1904                 :            :                 /* Still start < end. */
    1905                 :            :                 error = -ENOMEM;
    1906         [ #  # ]:          0 :                 if (!vma)
    1907                 :            :                         return error;
    1908                 :            : 
    1909                 :            :                 /* Here start < (end|vma->vm_end). */
    1910         [ #  # ]:          0 :                 if (start < vma->vm_start) {
    1911                 :            :                         unmapped_error = -ENOMEM;
    1912                 :            :                         start = vma->vm_start;
    1913         [ #  # ]:          0 :                         if (start >= end)
    1914                 :            :                                 return error;
    1915                 :            :                 }
    1916                 :            : 
    1917                 :            :                 /* Here vma->vm_start <= start < (end|vma->vm_end) */
    1918                 :          0 :                 tmp = vma->vm_end;
    1919         [ #  # ]:          0 :                 if (end < tmp)
    1920                 :            :                         tmp = end;
    1921                 :            : 
    1922                 :            :                 /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */
    1923                 :          0 :                 error = prctl_update_vma_anon_name(vma, &prev, start, end,
    1924                 :            :                                 (const char __user *)arg);
    1925         [ #  # ]:          0 :                 if (error)
    1926                 :            :                         return error;
    1927                 :            :                 start = tmp;
    1928 [ #  # ][ #  # ]:          0 :                 if (prev && start < prev->vm_end)
    1929                 :            :                         start = prev->vm_end;
    1930                 :            :                 error = unmapped_error;
    1931         [ #  # ]:          0 :                 if (start >= end)
    1932                 :            :                         return error;
    1933         [ #  # ]:          0 :                 if (prev)
    1934                 :          0 :                         vma = prev->vm_next;
    1935                 :            :                 else    /* madvise_remove dropped mmap_sem */
    1936                 :          0 :                         vma = find_vma(current->mm, start);
    1937                 :            :         }
    1938                 :            : }
    1939                 :            : 
    1940                 :          0 : static int prctl_set_vma(unsigned long opt, unsigned long start,
    1941                 :            :                 unsigned long len_in, unsigned long arg)
    1942                 :            : {
    1943                 :          0 :         struct mm_struct *mm = current->mm;
    1944                 :            :         int error;
    1945                 :            :         unsigned long len;
    1946                 :            :         unsigned long end;
    1947                 :            : 
    1948         [ #  # ]:          0 :         if (start & ~PAGE_MASK)
    1949                 :            :                 return -EINVAL;
    1950                 :          0 :         len = (len_in + ~PAGE_MASK) & PAGE_MASK;
    1951                 :            : 
    1952                 :            :         /* Check to see whether len was rounded up from small -ve to zero */
    1953         [ #  # ]:          0 :         if (len_in && !len)
    1954                 :            :                 return -EINVAL;
    1955                 :            : 
    1956                 :          0 :         end = start + len;
    1957         [ #  # ]:          0 :         if (end < start)
    1958                 :            :                 return -EINVAL;
    1959                 :            : 
    1960         [ #  # ]:          0 :         if (end == start)
    1961                 :            :                 return 0;
    1962                 :            : 
    1963                 :          0 :         down_write(&mm->mmap_sem);
    1964                 :            : 
    1965         [ #  # ]:          0 :         switch (opt) {
    1966                 :            :         case PR_SET_VMA_ANON_NAME:
    1967                 :          0 :                 error = prctl_set_vma_anon_name(start, end, arg);
    1968                 :          0 :                 break;
    1969                 :            :         default:
    1970                 :            :                 error = -EINVAL;
    1971                 :            :         }
    1972                 :            : 
    1973                 :          0 :         up_write(&mm->mmap_sem);
    1974                 :            : 
    1975                 :          0 :         return error;
    1976                 :            : }
    1977                 :            : #else /* CONFIG_MMU */
    1978                 :            : static int prctl_set_vma(unsigned long opt, unsigned long start,
    1979                 :            :                 unsigned long len_in, unsigned long arg)
    1980                 :            : {
    1981                 :            :         return -EINVAL;
    1982                 :            : }
    1983                 :            : #endif
    1984                 :            : 
    1985                 :          0 : SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
    1986                 :            :                 unsigned long, arg4, unsigned long, arg5)
    1987                 :            : {
    1988                 :       9249 :         struct task_struct *me = current;
    1989                 :            :         unsigned char comm[sizeof(me->comm)];
    1990                 :            :         long error;
    1991                 :            : 
    1992                 :       9249 :         error = security_task_prctl(option, arg2, arg3, arg4, arg5);
    1993         [ +  - ]:       9249 :         if (error != -ENOSYS)
    1994                 :            :                 return error;
    1995                 :            : 
    1996                 :            :         error = 0;
    1997   [ +  +  +  -  :       9249 :         switch (option) {
          -  -  +  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
             -  -  -  -  
                      + ]
    1998                 :            :         case PR_SET_PDEATHSIG:
    1999         [ +  + ]:         29 :                 if (!valid_signal(arg2)) {
    2000                 :            :                         error = -EINVAL;
    2001                 :            :                         break;
    2002                 :            :                 }
    2003                 :         28 :                 me->pdeath_signal = arg2;
    2004                 :            :                 break;
    2005                 :            :         case PR_GET_PDEATHSIG:
    2006                 :          1 :                 error = put_user(me->pdeath_signal, (int __user *)arg2);
    2007                 :            :                 break;
    2008                 :            :         case PR_GET_DUMPABLE:
    2009                 :       9187 :                 error = get_dumpable(me->mm);
    2010                 :            :                 break;
    2011                 :            :         case PR_SET_DUMPABLE:
    2012         [ #  # ]:          0 :                 if (arg2 != SUID_DUMP_DISABLE && arg2 != SUID_DUMP_USER) {
    2013                 :            :                         error = -EINVAL;
    2014                 :            :                         break;
    2015                 :            :                 }
    2016                 :          0 :                 set_dumpable(me->mm, arg2);
    2017                 :            :                 break;
    2018                 :            : 
    2019                 :            :         case PR_SET_UNALIGN:
    2020                 :            :                 error = SET_UNALIGN_CTL(me, arg2);
    2021                 :            :                 break;
    2022                 :            :         case PR_GET_UNALIGN:
    2023                 :            :                 error = GET_UNALIGN_CTL(me, arg2);
    2024                 :            :                 break;
    2025                 :            :         case PR_SET_FPEMU:
    2026                 :            :                 error = SET_FPEMU_CTL(me, arg2);
    2027                 :            :                 break;
    2028                 :            :         case PR_GET_FPEMU:
    2029                 :            :                 error = GET_FPEMU_CTL(me, arg2);
    2030                 :            :                 break;
    2031                 :            :         case PR_SET_FPEXC:
    2032                 :            :                 error = SET_FPEXC_CTL(me, arg2);
    2033                 :            :                 break;
    2034                 :            :         case PR_GET_FPEXC:
    2035                 :            :                 error = GET_FPEXC_CTL(me, arg2);
    2036                 :            :                 break;
    2037                 :            :         case PR_GET_TIMING:
    2038                 :            :                 error = PR_TIMING_STATISTICAL;
    2039                 :            :                 break;
    2040                 :            :         case PR_SET_TIMING:
    2041         [ #  # ]:          0 :                 if (arg2 != PR_TIMING_STATISTICAL)
    2042                 :            :                         error = -EINVAL;
    2043                 :            :                 break;
    2044                 :            :         case PR_SET_NAME:
    2045                 :         31 :                 comm[sizeof(me->comm) - 1] = 0;
    2046         [ +  - ]:         31 :                 if (strncpy_from_user(comm, (char __user *)arg2,
    2047                 :            :                                       sizeof(me->comm) - 1) < 0)
    2048                 :            :                         return -EFAULT;
    2049                 :         31 :                 set_task_comm(me, comm);
    2050                 :         31 :                 proc_comm_connector(me);
    2051                 :            :                 break;
    2052                 :            :         case PR_GET_NAME:
    2053                 :          0 :                 get_task_comm(comm, me);
    2054         [ #  # ]:          0 :                 if (copy_to_user((char __user *)arg2, comm, sizeof(comm)))
    2055                 :            :                         return -EFAULT;
    2056                 :            :                 break;
    2057                 :            :         case PR_GET_ENDIAN:
    2058                 :            :                 error = GET_ENDIAN(me, arg2);
    2059                 :            :                 break;
    2060                 :            :         case PR_SET_ENDIAN:
    2061                 :            :                 error = SET_ENDIAN(me, arg2);
    2062                 :            :                 break;
    2063                 :            :         case PR_GET_SECCOMP:
    2064                 :          0 :                 error = prctl_get_seccomp();
    2065                 :            :                 break;
    2066                 :            :         case PR_SET_SECCOMP:
    2067                 :          0 :                 error = prctl_set_seccomp(arg2, (char __user *)arg3);
    2068                 :            :                 break;
    2069                 :            :         case PR_GET_TSC:
    2070                 :            :                 error = GET_TSC_CTL(arg2);
    2071                 :            :                 break;
    2072                 :            :         case PR_SET_TSC:
    2073                 :            :                 error = SET_TSC_CTL(arg2);
    2074                 :            :                 break;
    2075                 :            :         case PR_TASK_PERF_EVENTS_DISABLE:
    2076                 :          0 :                 error = perf_event_task_disable();
    2077                 :            :                 break;
    2078                 :            :         case PR_TASK_PERF_EVENTS_ENABLE:
    2079                 :          0 :                 error = perf_event_task_enable();
    2080                 :            :                 break;
    2081                 :            :         case PR_GET_TIMERSLACK:
    2082                 :          0 :                 error = current->timer_slack_ns;
    2083                 :            :                 break;
    2084                 :            :         case PR_SET_TIMERSLACK:
    2085         [ #  # ]:          0 :                 if (arg2 <= 0)
    2086                 :          0 :                         current->timer_slack_ns =
    2087                 :          0 :                                         current->default_timer_slack_ns;
    2088                 :            :                 else
    2089                 :          0 :                         current->timer_slack_ns = arg2;
    2090                 :            :                 break;
    2091                 :            :         case PR_MCE_KILL:
    2092         [ #  # ]:          0 :                 if (arg4 | arg5)
    2093                 :            :                         return -EINVAL;
    2094      [ #  #  # ]:          0 :                 switch (arg2) {
    2095                 :            :                 case PR_MCE_KILL_CLEAR:
    2096         [ #  # ]:          0 :                         if (arg3 != 0)
    2097                 :            :                                 return -EINVAL;
    2098                 :          0 :                         current->flags &= ~PF_MCE_PROCESS;
    2099                 :            :                         break;
    2100                 :            :                 case PR_MCE_KILL_SET:
    2101                 :          0 :                         current->flags |= PF_MCE_PROCESS;
    2102         [ #  # ]:          0 :                         if (arg3 == PR_MCE_KILL_EARLY)
    2103                 :          0 :                                 current->flags |= PF_MCE_EARLY;
    2104         [ #  # ]:          0 :                         else if (arg3 == PR_MCE_KILL_LATE)
    2105                 :          0 :                                 current->flags &= ~PF_MCE_EARLY;
    2106         [ #  # ]:          0 :                         else if (arg3 == PR_MCE_KILL_DEFAULT)
    2107                 :          0 :                                 current->flags &=
    2108                 :            :                                                 ~(PF_MCE_EARLY|PF_MCE_PROCESS);
    2109                 :            :                         else
    2110                 :            :                                 return -EINVAL;
    2111                 :            :                         break;
    2112                 :            :                 default:
    2113                 :            :                         return -EINVAL;
    2114                 :            :                 }
    2115                 :            :                 break;
    2116                 :            :         case PR_MCE_KILL_GET:
    2117         [ #  # ]:          0 :                 if (arg2 | arg3 | arg4 | arg5)
    2118                 :            :                         return -EINVAL;
    2119         [ #  # ]:          0 :                 if (current->flags & PF_MCE_PROCESS)
    2120                 :          0 :                         error = (current->flags & PF_MCE_EARLY) ?
    2121                 :          0 :                                 PR_MCE_KILL_EARLY : PR_MCE_KILL_LATE;
    2122                 :            :                 else
    2123                 :            :                         error = PR_MCE_KILL_DEFAULT;
    2124                 :            :                 break;
    2125                 :            :         case PR_SET_MM:
    2126                 :          0 :                 error = prctl_set_mm(arg2, arg3, arg4, arg5);
    2127                 :            :                 break;
    2128                 :            :         case PR_GET_TID_ADDRESS:
    2129                 :          0 :                 error = prctl_get_tid_address(me, (int __user **)arg2);
    2130                 :            :                 break;
    2131                 :            :         case PR_SET_CHILD_SUBREAPER:
    2132                 :          0 :                 me->signal->is_child_subreaper = !!arg2;
    2133                 :            :                 break;
    2134                 :            :         case PR_GET_CHILD_SUBREAPER:
    2135                 :          0 :                 error = put_user(me->signal->is_child_subreaper,
    2136                 :            :                                  (int __user *)arg2);
    2137                 :            :                 break;
    2138                 :            :         case PR_SET_NO_NEW_PRIVS:
    2139 [ #  # ][ #  # ]:          0 :                 if (arg2 != 1 || arg3 || arg4 || arg5)
    2140                 :            :                         return -EINVAL;
    2141                 :            : 
    2142                 :          0 :                 current->no_new_privs = 1;
    2143                 :            :                 break;
    2144                 :            :         case PR_GET_NO_NEW_PRIVS:
    2145         [ #  # ]:          0 :                 if (arg2 || arg3 || arg4 || arg5)
    2146                 :            :                         return -EINVAL;
    2147                 :          0 :                 return current->no_new_privs ? 1 : 0;
    2148                 :            :         case PR_SET_VMA:
    2149                 :          0 :                 error = prctl_set_vma(arg2, arg3, arg4, arg5);
    2150                 :            :                 break;
    2151                 :            :         default:
    2152                 :            :                 error = -EINVAL;
    2153                 :            :                 break;
    2154                 :            :         }
    2155                 :            :         return error;
    2156                 :            : }
    2157                 :            : 
    2158                 :          0 : SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,
    2159                 :            :                 struct getcpu_cache __user *, unused)
    2160                 :            : {
    2161                 :            :         int err = 0;
    2162                 :          0 :         int cpu = raw_smp_processor_id();
    2163         [ #  # ]:          0 :         if (cpup)
    2164                 :          0 :                 err |= put_user(cpu, cpup);
    2165         [ #  # ]:          0 :         if (nodep)
    2166                 :          0 :                 err |= put_user(cpu_to_node(cpu), nodep);
    2167         [ #  # ]:          0 :         return err ? -EFAULT : 0;
    2168                 :            : }
    2169                 :            : 
    2170                 :            : /**
    2171                 :            :  * do_sysinfo - fill in sysinfo struct
    2172                 :            :  * @info: pointer to buffer to fill
    2173                 :            :  */
    2174                 :          0 : static int do_sysinfo(struct sysinfo *info)
    2175                 :            : {
    2176                 :            :         unsigned long mem_total, sav_total;
    2177                 :            :         unsigned int mem_unit, bitcount;
    2178                 :            :         struct timespec tp;
    2179                 :            : 
    2180                 :         17 :         memset(info, 0, sizeof(struct sysinfo));
    2181                 :            : 
    2182                 :         17 :         get_monotonic_boottime(&tp);
    2183         [ -  + ]:         17 :         info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
    2184                 :            : 
    2185                 :         17 :         get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
    2186                 :            : 
    2187                 :         17 :         info->procs = nr_threads;
    2188                 :            : 
    2189                 :         17 :         si_meminfo(info);
    2190                 :         17 :         si_swapinfo(info);
    2191                 :            : 
    2192                 :            :         /*
    2193                 :            :          * If the sum of all the available memory (i.e. ram + swap)
    2194                 :            :          * is less than can be stored in a 32 bit unsigned long then
    2195                 :            :          * we can be binary compatible with 2.2.x kernels.  If not,
    2196                 :            :          * well, in that case 2.2.x was broken anyways...
    2197                 :            :          *
    2198                 :            :          *  -Erik Andersen <andersee@debian.org>
    2199                 :            :          */
    2200                 :            : 
    2201                 :         17 :         mem_total = info->totalram + info->totalswap;
    2202    [ +  - ][ + ]:         17 :         if (mem_total < info->totalram || mem_total < info->totalswap)
    2203                 :            :                 goto out;
    2204                 :            :         bitcount = 0;
    2205                 :         17 :         mem_unit = info->mem_unit;
    2206         [ +  + ]:        238 :         while (mem_unit > 1) {
    2207                 :        204 :                 bitcount++;
    2208                 :        204 :                 mem_unit >>= 1;
    2209                 :            :                 sav_total = mem_total;
    2210                 :        204 :                 mem_total <<= 1;
    2211         [ +  - ]:        204 :                 if (mem_total < sav_total)
    2212                 :            :                         goto out;
    2213                 :            :         }
    2214                 :            : 
    2215                 :            :         /*
    2216                 :            :          * If mem_total did not overflow, multiply all memory values by
    2217                 :            :          * info->mem_unit and set it to 1.  This leaves things compatible
    2218                 :            :          * with 2.2.x, and also retains compatibility with earlier 2.4.x
    2219                 :            :          * kernels...
    2220                 :            :          */
    2221                 :            : 
    2222                 :         17 :         info->mem_unit = 1;
    2223                 :         17 :         info->totalram <<= bitcount;
    2224                 :         17 :         info->freeram <<= bitcount;
    2225                 :         17 :         info->sharedram <<= bitcount;
    2226                 :         17 :         info->bufferram <<= bitcount;
    2227                 :         17 :         info->totalswap <<= bitcount;
    2228                 :         17 :         info->freeswap <<= bitcount;
    2229                 :         17 :         info->totalhigh <<= bitcount;
    2230                 :         17 :         info->freehigh <<= bitcount;
    2231                 :            : 
    2232                 :            : out:
    2233                 :          0 :         return 0;
    2234                 :            : }
    2235                 :            : 
    2236                 :          0 : SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info)
    2237                 :            : {
    2238                 :            :         struct sysinfo val;
    2239                 :            : 
    2240                 :         17 :         do_sysinfo(&val);
    2241                 :            : 
    2242         [ +  + ]:         34 :         if (copy_to_user(info, &val, sizeof(struct sysinfo)))
    2243                 :            :                 return -EFAULT;
    2244                 :            : 
    2245                 :            :         return 0;
    2246                 :            : }
    2247                 :            : 
    2248                 :            : #ifdef CONFIG_COMPAT
    2249                 :            : struct compat_sysinfo {
    2250                 :            :         s32 uptime;
    2251                 :            :         u32 loads[3];
    2252                 :            :         u32 totalram;
    2253                 :            :         u32 freeram;
    2254                 :            :         u32 sharedram;
    2255                 :            :         u32 bufferram;
    2256                 :            :         u32 totalswap;
    2257                 :            :         u32 freeswap;
    2258                 :            :         u16 procs;
    2259                 :            :         u16 pad;
    2260                 :            :         u32 totalhigh;
    2261                 :            :         u32 freehigh;
    2262                 :            :         u32 mem_unit;
    2263                 :            :         char _f[20-2*sizeof(u32)-sizeof(int)];
    2264                 :            : };
    2265                 :            : 
    2266                 :            : COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
    2267                 :            : {
    2268                 :            :         struct sysinfo s;
    2269                 :            : 
    2270                 :            :         do_sysinfo(&s);
    2271                 :            : 
    2272                 :            :         /* Check to see if any memory value is too large for 32-bit and scale
    2273                 :            :          *  down if needed
    2274                 :            :          */
    2275                 :            :         if ((s.totalram >> 32) || (s.totalswap >> 32)) {
    2276                 :            :                 int bitcount = 0;
    2277                 :            : 
    2278                 :            :                 while (s.mem_unit < PAGE_SIZE) {
    2279                 :            :                         s.mem_unit <<= 1;
    2280                 :            :                         bitcount++;
    2281                 :            :                 }
    2282                 :            : 
    2283                 :            :                 s.totalram >>= bitcount;
    2284                 :            :                 s.freeram >>= bitcount;
    2285                 :            :                 s.sharedram >>= bitcount;
    2286                 :            :                 s.bufferram >>= bitcount;
    2287                 :            :                 s.totalswap >>= bitcount;
    2288                 :            :                 s.freeswap >>= bitcount;
    2289                 :            :                 s.totalhigh >>= bitcount;
    2290                 :            :                 s.freehigh >>= bitcount;
    2291                 :            :         }
    2292                 :            : 
    2293                 :            :         if (!access_ok(VERIFY_WRITE, info, sizeof(struct compat_sysinfo)) ||
    2294                 :            :             __put_user(s.uptime, &info->uptime) ||
    2295                 :            :             __put_user(s.loads[0], &info->loads[0]) ||
    2296                 :            :             __put_user(s.loads[1], &info->loads[1]) ||
    2297                 :            :             __put_user(s.loads[2], &info->loads[2]) ||
    2298                 :            :             __put_user(s.totalram, &info->totalram) ||
    2299                 :            :             __put_user(s.freeram, &info->freeram) ||
    2300                 :            :             __put_user(s.sharedram, &info->sharedram) ||
    2301                 :            :             __put_user(s.bufferram, &info->bufferram) ||
    2302                 :            :             __put_user(s.totalswap, &info->totalswap) ||
    2303                 :            :             __put_user(s.freeswap, &info->freeswap) ||
    2304                 :            :             __put_user(s.procs, &info->procs) ||
    2305                 :            :             __put_user(s.totalhigh, &info->totalhigh) ||
    2306                 :            :             __put_user(s.freehigh, &info->freehigh) ||
    2307                 :            :             __put_user(s.mem_unit, &info->mem_unit))
    2308                 :            :                 return -EFAULT;
    2309                 :            : 
    2310                 :            :         return 0;
    2311                 :            : }
    2312                 :            : #endif /* CONFIG_COMPAT */

Generated by: LCOV version 1.9