~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/sys.c

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp