1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 1991, 1992 Linus Torvalds
8 #include <linux/export.h>
10 #include <linux/mm_inline.h>
11 #include <linux/utsname.h>
12 #include <linux/mman.h>
13 #include <linux/reboot.h>
14 #include <linux/prctl.h>
15 #include <linux/highuid.h>
17 #include <linux/kmod.h>
18 #include <linux/perf_event.h>
19 #include <linux/resource.h>
20 #include <linux/kernel.h>
21 #include <linux/workqueue.h>
22 #include <linux/capability.h>
23 #include <linux/device.h>
24 #include <linux/key.h>
25 #include <linux/times.h>
26 #include <linux/posix-timers.h>
27 #include <linux/security.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 #include <linux/syscall_user_dispatch.h>
47 #include <linux/compat.h>
48 #include <linux/syscalls.h>
49 #include <linux/kprobes.h>
50 #include <linux/user_namespace.h>
51 #include <linux/time_namespace.h>
52 #include <linux/binfmts.h>
54 #include <linux/sched.h>
55 #include <linux/sched/autogroup.h>
56 #include <linux/sched/loadavg.h>
57 #include <linux/sched/stat.h>
58 #include <linux/sched/mm.h>
59 #include <linux/sched/coredump.h>
60 #include <linux/sched/task.h>
61 #include <linux/sched/cputime.h>
62 #include <linux/rcupdate.h>
63 #include <linux/uidgid.h>
64 #include <linux/cred.h>
66 #include <linux/nospec.h>
68 #include <linux/kmsg_dump.h>
69 /* Move somewhere else to avoid recompiling? */
70 #include <generated/utsrelease.h>
72 #include <linux/uaccess.h>
74 #include <asm/unistd.h>
78 #ifndef SET_UNALIGN_CTL
79 # define SET_UNALIGN_CTL(a, b) (-EINVAL)
81 #ifndef GET_UNALIGN_CTL
82 # define GET_UNALIGN_CTL(a, b) (-EINVAL)
85 # define SET_FPEMU_CTL(a, b) (-EINVAL)
88 # define GET_FPEMU_CTL(a, b) (-EINVAL)
91 # define SET_FPEXC_CTL(a, b) (-EINVAL)
94 # define GET_FPEXC_CTL(a, b) (-EINVAL)
97 # define GET_ENDIAN(a, b) (-EINVAL)
100 # define SET_ENDIAN(a, b) (-EINVAL)
103 # define GET_TSC_CTL(a) (-EINVAL)
106 # define SET_TSC_CTL(a) (-EINVAL)
109 # define GET_FP_MODE(a) (-EINVAL)
112 # define SET_FP_MODE(a,b) (-EINVAL)
115 # define SVE_SET_VL(a) (-EINVAL)
118 # define SVE_GET_VL() (-EINVAL)
121 # define SME_SET_VL(a) (-EINVAL)
124 # define SME_GET_VL() (-EINVAL)
126 #ifndef PAC_RESET_KEYS
127 # define PAC_RESET_KEYS(a, b) (-EINVAL)
129 #ifndef PAC_SET_ENABLED_KEYS
130 # define PAC_SET_ENABLED_KEYS(a, b, c) (-EINVAL)
132 #ifndef PAC_GET_ENABLED_KEYS
133 # define PAC_GET_ENABLED_KEYS(a) (-EINVAL)
135 #ifndef SET_TAGGED_ADDR_CTRL
136 # define SET_TAGGED_ADDR_CTRL(a) (-EINVAL)
138 #ifndef GET_TAGGED_ADDR_CTRL
139 # define GET_TAGGED_ADDR_CTRL() (-EINVAL)
143 * this is where the system-wide overflow UID and GID are defined, for
144 * architectures that now have 32-bit UID/GID but didn't in the past
147 int overflowuid
= DEFAULT_OVERFLOWUID
;
148 int overflowgid
= DEFAULT_OVERFLOWGID
;
150 EXPORT_SYMBOL(overflowuid
);
151 EXPORT_SYMBOL(overflowgid
);
154 * the same as above, but for filesystems which can only store a 16-bit
155 * UID and GID. as such, this is needed on all architectures
158 int fs_overflowuid
= DEFAULT_FS_OVERFLOWUID
;
159 int fs_overflowgid
= DEFAULT_FS_OVERFLOWGID
;
161 EXPORT_SYMBOL(fs_overflowuid
);
162 EXPORT_SYMBOL(fs_overflowgid
);
165 * Returns true if current's euid is same as p's uid or euid,
166 * or has CAP_SYS_NICE to p's user_ns.
168 * Called with rcu_read_lock, creds are safe
170 static bool set_one_prio_perm(struct task_struct
*p
)
172 const struct cred
*cred
= current_cred(), *pcred
= __task_cred(p
);
174 if (uid_eq(pcred
->uid
, cred
->euid
) ||
175 uid_eq(pcred
->euid
, cred
->euid
))
177 if (ns_capable(pcred
->user_ns
, CAP_SYS_NICE
))
183 * set the priority of a task
184 * - the caller must hold the RCU read lock
186 static int set_one_prio(struct task_struct
*p
, int niceval
, int error
)
190 if (!set_one_prio_perm(p
)) {
194 if (niceval
< task_nice(p
) && !can_nice(p
, niceval
)) {
198 no_nice
= security_task_setnice(p
, niceval
);
205 set_user_nice(p
, niceval
);
210 SYSCALL_DEFINE3(setpriority
, int, which
, int, who
, int, niceval
)
212 struct task_struct
*g
, *p
;
213 struct user_struct
*user
;
214 const struct cred
*cred
= current_cred();
219 if (which
> PRIO_USER
|| which
< PRIO_PROCESS
)
222 /* normalize: avoid signed division (rounding problems) */
224 if (niceval
< MIN_NICE
)
226 if (niceval
> MAX_NICE
)
233 p
= find_task_by_vpid(who
);
237 error
= set_one_prio(p
, niceval
, error
);
241 pgrp
= find_vpid(who
);
243 pgrp
= task_pgrp(current
);
244 read_lock(&tasklist_lock
);
245 do_each_pid_thread(pgrp
, PIDTYPE_PGID
, p
) {
246 error
= set_one_prio(p
, niceval
, error
);
247 } while_each_pid_thread(pgrp
, PIDTYPE_PGID
, p
);
248 read_unlock(&tasklist_lock
);
251 uid
= make_kuid(cred
->user_ns
, who
);
255 else if (!uid_eq(uid
, cred
->uid
)) {
256 user
= find_user(uid
);
258 goto out_unlock
; /* No processes for this user */
260 for_each_process_thread(g
, p
) {
261 if (uid_eq(task_uid(p
), uid
) && task_pid_vnr(p
))
262 error
= set_one_prio(p
, niceval
, error
);
264 if (!uid_eq(uid
, cred
->uid
))
265 free_uid(user
); /* For find_user() */
275 * Ugh. To avoid negative return values, "getpriority()" will
276 * not return the normal nice-value, but a negated value that
277 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
278 * to stay compatible.
280 SYSCALL_DEFINE2(getpriority
, int, which
, int, who
)
282 struct task_struct
*g
, *p
;
283 struct user_struct
*user
;
284 const struct cred
*cred
= current_cred();
285 long niceval
, retval
= -ESRCH
;
289 if (which
> PRIO_USER
|| which
< PRIO_PROCESS
)
296 p
= find_task_by_vpid(who
);
300 niceval
= nice_to_rlimit(task_nice(p
));
301 if (niceval
> retval
)
307 pgrp
= find_vpid(who
);
309 pgrp
= task_pgrp(current
);
310 read_lock(&tasklist_lock
);
311 do_each_pid_thread(pgrp
, PIDTYPE_PGID
, p
) {
312 niceval
= nice_to_rlimit(task_nice(p
));
313 if (niceval
> retval
)
315 } while_each_pid_thread(pgrp
, PIDTYPE_PGID
, p
);
316 read_unlock(&tasklist_lock
);
319 uid
= make_kuid(cred
->user_ns
, who
);
323 else if (!uid_eq(uid
, cred
->uid
)) {
324 user
= find_user(uid
);
326 goto out_unlock
; /* No processes for this user */
328 for_each_process_thread(g
, p
) {
329 if (uid_eq(task_uid(p
), uid
) && task_pid_vnr(p
)) {
330 niceval
= nice_to_rlimit(task_nice(p
));
331 if (niceval
> retval
)
335 if (!uid_eq(uid
, cred
->uid
))
336 free_uid(user
); /* for find_user() */
346 * Unprivileged users may change the real gid to the effective gid
347 * or vice versa. (BSD-style)
349 * If you set the real gid at all, or set the effective gid to a value not
350 * equal to the real gid, then the saved gid is set to the new effective gid.
352 * This makes it possible for a setgid program to completely drop its
353 * privileges, which is often a useful assertion to make when you are doing
354 * a security audit over a program.
356 * The general idea is that a program which uses just setregid() will be
357 * 100% compatible with BSD. A program which uses just setgid() will be
358 * 100% compatible with POSIX with saved IDs.
360 * SMP: There are not races, the GIDs are checked only by filesystem
361 * operations (as far as semantic preservation is concerned).
363 #ifdef CONFIG_MULTIUSER
364 long __sys_setregid(gid_t rgid
, gid_t egid
)
366 struct user_namespace
*ns
= current_user_ns();
367 const struct cred
*old
;
372 krgid
= make_kgid(ns
, rgid
);
373 kegid
= make_kgid(ns
, egid
);
375 if ((rgid
!= (gid_t
) -1) && !gid_valid(krgid
))
377 if ((egid
!= (gid_t
) -1) && !gid_valid(kegid
))
380 new = prepare_creds();
383 old
= current_cred();
386 if (rgid
!= (gid_t
) -1) {
387 if (gid_eq(old
->gid
, krgid
) ||
388 gid_eq(old
->egid
, krgid
) ||
389 ns_capable_setid(old
->user_ns
, CAP_SETGID
))
394 if (egid
!= (gid_t
) -1) {
395 if (gid_eq(old
->gid
, kegid
) ||
396 gid_eq(old
->egid
, kegid
) ||
397 gid_eq(old
->sgid
, kegid
) ||
398 ns_capable_setid(old
->user_ns
, CAP_SETGID
))
404 if (rgid
!= (gid_t
) -1 ||
405 (egid
!= (gid_t
) -1 && !gid_eq(kegid
, old
->gid
)))
406 new->sgid
= new->egid
;
407 new->fsgid
= new->egid
;
409 retval
= security_task_fix_setgid(new, old
, LSM_SETID_RE
);
413 return commit_creds(new);
420 SYSCALL_DEFINE2(setregid
, gid_t
, rgid
, gid_t
, egid
)
422 return __sys_setregid(rgid
, egid
);
426 * setgid() is implemented like SysV w/ SAVED_IDS
428 * SMP: Same implicit races as above.
430 long __sys_setgid(gid_t gid
)
432 struct user_namespace
*ns
= current_user_ns();
433 const struct cred
*old
;
438 kgid
= make_kgid(ns
, gid
);
439 if (!gid_valid(kgid
))
442 new = prepare_creds();
445 old
= current_cred();
448 if (ns_capable_setid(old
->user_ns
, CAP_SETGID
))
449 new->gid
= new->egid
= new->sgid
= new->fsgid
= kgid
;
450 else if (gid_eq(kgid
, old
->gid
) || gid_eq(kgid
, old
->sgid
))
451 new->egid
= new->fsgid
= kgid
;
455 retval
= security_task_fix_setgid(new, old
, LSM_SETID_ID
);
459 return commit_creds(new);
466 SYSCALL_DEFINE1(setgid
, gid_t
, gid
)
468 return __sys_setgid(gid
);
472 * change the user struct in a credentials set to match the new UID
474 static int set_user(struct cred
*new)
476 struct user_struct
*new_user
;
478 new_user
= alloc_uid(new->uid
);
483 new->user
= new_user
;
487 static void flag_nproc_exceeded(struct cred
*new)
489 if (new->ucounts
== current_ucounts())
493 * We don't fail in case of NPROC limit excess here because too many
494 * poorly written programs don't check set*uid() return code, assuming
495 * it never fails if called by root. We may still enforce NPROC limit
496 * for programs doing set*uid()+execve() by harmlessly deferring the
497 * failure to the execve() stage.
499 if (is_ucounts_overlimit(new->ucounts
, UCOUNT_RLIMIT_NPROC
, rlimit(RLIMIT_NPROC
)) &&
500 new->user
!= INIT_USER
)
501 current
->flags
|= PF_NPROC_EXCEEDED
;
503 current
->flags
&= ~PF_NPROC_EXCEEDED
;
507 * Unprivileged users may change the real uid to the effective uid
508 * or vice versa. (BSD-style)
510 * If you set the real uid at all, or set the effective uid to a value not
511 * equal to the real uid, then the saved uid is set to the new effective uid.
513 * This makes it possible for a setuid program to completely drop its
514 * privileges, which is often a useful assertion to make when you are doing
515 * a security audit over a program.
517 * The general idea is that a program which uses just setreuid() will be
518 * 100% compatible with BSD. A program which uses just setuid() will be
519 * 100% compatible with POSIX with saved IDs.
521 long __sys_setreuid(uid_t ruid
, uid_t euid
)
523 struct user_namespace
*ns
= current_user_ns();
524 const struct cred
*old
;
529 kruid
= make_kuid(ns
, ruid
);
530 keuid
= make_kuid(ns
, euid
);
532 if ((ruid
!= (uid_t
) -1) && !uid_valid(kruid
))
534 if ((euid
!= (uid_t
) -1) && !uid_valid(keuid
))
537 new = prepare_creds();
540 old
= current_cred();
543 if (ruid
!= (uid_t
) -1) {
545 if (!uid_eq(old
->uid
, kruid
) &&
546 !uid_eq(old
->euid
, kruid
) &&
547 !ns_capable_setid(old
->user_ns
, CAP_SETUID
))
551 if (euid
!= (uid_t
) -1) {
553 if (!uid_eq(old
->uid
, keuid
) &&
554 !uid_eq(old
->euid
, keuid
) &&
555 !uid_eq(old
->suid
, keuid
) &&
556 !ns_capable_setid(old
->user_ns
, CAP_SETUID
))
560 if (!uid_eq(new->uid
, old
->uid
)) {
561 retval
= set_user(new);
565 if (ruid
!= (uid_t
) -1 ||
566 (euid
!= (uid_t
) -1 && !uid_eq(keuid
, old
->uid
)))
567 new->suid
= new->euid
;
568 new->fsuid
= new->euid
;
570 retval
= security_task_fix_setuid(new, old
, LSM_SETID_RE
);
574 retval
= set_cred_ucounts(new);
578 flag_nproc_exceeded(new);
579 return commit_creds(new);
586 SYSCALL_DEFINE2(setreuid
, uid_t
, ruid
, uid_t
, euid
)
588 return __sys_setreuid(ruid
, euid
);
592 * setuid() is implemented like SysV with SAVED_IDS
594 * Note that SAVED_ID's is deficient in that a setuid root program
595 * like sendmail, for example, cannot set its uid to be a normal
596 * user and then switch back, because if you're root, setuid() sets
597 * the saved uid too. If you don't like this, blame the bright people
598 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
599 * will allow a root program to temporarily drop privileges and be able to
600 * regain them by swapping the real and effective uid.
602 long __sys_setuid(uid_t uid
)
604 struct user_namespace
*ns
= current_user_ns();
605 const struct cred
*old
;
610 kuid
= make_kuid(ns
, uid
);
611 if (!uid_valid(kuid
))
614 new = prepare_creds();
617 old
= current_cred();
620 if (ns_capable_setid(old
->user_ns
, CAP_SETUID
)) {
621 new->suid
= new->uid
= kuid
;
622 if (!uid_eq(kuid
, old
->uid
)) {
623 retval
= set_user(new);
627 } else if (!uid_eq(kuid
, old
->uid
) && !uid_eq(kuid
, new->suid
)) {
631 new->fsuid
= new->euid
= kuid
;
633 retval
= security_task_fix_setuid(new, old
, LSM_SETID_ID
);
637 retval
= set_cred_ucounts(new);
641 flag_nproc_exceeded(new);
642 return commit_creds(new);
649 SYSCALL_DEFINE1(setuid
, uid_t
, uid
)
651 return __sys_setuid(uid
);
656 * This function implements a generic ability to update ruid, euid,
657 * and suid. This allows you to implement the 4.4 compatible seteuid().
659 long __sys_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
661 struct user_namespace
*ns
= current_user_ns();
662 const struct cred
*old
;
665 kuid_t kruid
, keuid
, ksuid
;
667 kruid
= make_kuid(ns
, ruid
);
668 keuid
= make_kuid(ns
, euid
);
669 ksuid
= make_kuid(ns
, suid
);
671 if ((ruid
!= (uid_t
) -1) && !uid_valid(kruid
))
674 if ((euid
!= (uid_t
) -1) && !uid_valid(keuid
))
677 if ((suid
!= (uid_t
) -1) && !uid_valid(ksuid
))
680 new = prepare_creds();
684 old
= current_cred();
687 if (!ns_capable_setid(old
->user_ns
, CAP_SETUID
)) {
688 if (ruid
!= (uid_t
) -1 && !uid_eq(kruid
, old
->uid
) &&
689 !uid_eq(kruid
, old
->euid
) && !uid_eq(kruid
, old
->suid
))
691 if (euid
!= (uid_t
) -1 && !uid_eq(keuid
, old
->uid
) &&
692 !uid_eq(keuid
, old
->euid
) && !uid_eq(keuid
, old
->suid
))
694 if (suid
!= (uid_t
) -1 && !uid_eq(ksuid
, old
->uid
) &&
695 !uid_eq(ksuid
, old
->euid
) && !uid_eq(ksuid
, old
->suid
))
699 if (ruid
!= (uid_t
) -1) {
701 if (!uid_eq(kruid
, old
->uid
)) {
702 retval
= set_user(new);
707 if (euid
!= (uid_t
) -1)
709 if (suid
!= (uid_t
) -1)
711 new->fsuid
= new->euid
;
713 retval
= security_task_fix_setuid(new, old
, LSM_SETID_RES
);
717 retval
= set_cred_ucounts(new);
721 flag_nproc_exceeded(new);
722 return commit_creds(new);
729 SYSCALL_DEFINE3(setresuid
, uid_t
, ruid
, uid_t
, euid
, uid_t
, suid
)
731 return __sys_setresuid(ruid
, euid
, suid
);
734 SYSCALL_DEFINE3(getresuid
, uid_t __user
*, ruidp
, uid_t __user
*, euidp
, uid_t __user
*, suidp
)
736 const struct cred
*cred
= current_cred();
738 uid_t ruid
, euid
, suid
;
740 ruid
= from_kuid_munged(cred
->user_ns
, cred
->uid
);
741 euid
= from_kuid_munged(cred
->user_ns
, cred
->euid
);
742 suid
= from_kuid_munged(cred
->user_ns
, cred
->suid
);
744 retval
= put_user(ruid
, ruidp
);
746 retval
= put_user(euid
, euidp
);
748 return put_user(suid
, suidp
);
754 * Same as above, but for rgid, egid, sgid.
756 long __sys_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
758 struct user_namespace
*ns
= current_user_ns();
759 const struct cred
*old
;
762 kgid_t krgid
, kegid
, ksgid
;
764 krgid
= make_kgid(ns
, rgid
);
765 kegid
= make_kgid(ns
, egid
);
766 ksgid
= make_kgid(ns
, sgid
);
768 if ((rgid
!= (gid_t
) -1) && !gid_valid(krgid
))
770 if ((egid
!= (gid_t
) -1) && !gid_valid(kegid
))
772 if ((sgid
!= (gid_t
) -1) && !gid_valid(ksgid
))
775 new = prepare_creds();
778 old
= current_cred();
781 if (!ns_capable_setid(old
->user_ns
, CAP_SETGID
)) {
782 if (rgid
!= (gid_t
) -1 && !gid_eq(krgid
, old
->gid
) &&
783 !gid_eq(krgid
, old
->egid
) && !gid_eq(krgid
, old
->sgid
))
785 if (egid
!= (gid_t
) -1 && !gid_eq(kegid
, old
->gid
) &&
786 !gid_eq(kegid
, old
->egid
) && !gid_eq(kegid
, old
->sgid
))
788 if (sgid
!= (gid_t
) -1 && !gid_eq(ksgid
, old
->gid
) &&
789 !gid_eq(ksgid
, old
->egid
) && !gid_eq(ksgid
, old
->sgid
))
793 if (rgid
!= (gid_t
) -1)
795 if (egid
!= (gid_t
) -1)
797 if (sgid
!= (gid_t
) -1)
799 new->fsgid
= new->egid
;
801 retval
= security_task_fix_setgid(new, old
, LSM_SETID_RES
);
805 return commit_creds(new);
812 SYSCALL_DEFINE3(setresgid
, gid_t
, rgid
, gid_t
, egid
, gid_t
, sgid
)
814 return __sys_setresgid(rgid
, egid
, sgid
);
817 SYSCALL_DEFINE3(getresgid
, gid_t __user
*, rgidp
, gid_t __user
*, egidp
, gid_t __user
*, sgidp
)
819 const struct cred
*cred
= current_cred();
821 gid_t rgid
, egid
, sgid
;
823 rgid
= from_kgid_munged(cred
->user_ns
, cred
->gid
);
824 egid
= from_kgid_munged(cred
->user_ns
, cred
->egid
);
825 sgid
= from_kgid_munged(cred
->user_ns
, cred
->sgid
);
827 retval
= put_user(rgid
, rgidp
);
829 retval
= put_user(egid
, egidp
);
831 retval
= put_user(sgid
, sgidp
);
839 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
840 * is used for "access()" and for the NFS daemon (letting nfsd stay at
841 * whatever uid it wants to). It normally shadows "euid", except when
842 * explicitly set by setfsuid() or for access..
844 long __sys_setfsuid(uid_t uid
)
846 const struct cred
*old
;
851 old
= current_cred();
852 old_fsuid
= from_kuid_munged(old
->user_ns
, old
->fsuid
);
854 kuid
= make_kuid(old
->user_ns
, uid
);
855 if (!uid_valid(kuid
))
858 new = prepare_creds();
862 if (uid_eq(kuid
, old
->uid
) || uid_eq(kuid
, old
->euid
) ||
863 uid_eq(kuid
, old
->suid
) || uid_eq(kuid
, old
->fsuid
) ||
864 ns_capable_setid(old
->user_ns
, CAP_SETUID
)) {
865 if (!uid_eq(kuid
, old
->fsuid
)) {
867 if (security_task_fix_setuid(new, old
, LSM_SETID_FS
) == 0)
880 SYSCALL_DEFINE1(setfsuid
, uid_t
, uid
)
882 return __sys_setfsuid(uid
);
886 * Samma på svenska..
888 long __sys_setfsgid(gid_t gid
)
890 const struct cred
*old
;
895 old
= current_cred();
896 old_fsgid
= from_kgid_munged(old
->user_ns
, old
->fsgid
);
898 kgid
= make_kgid(old
->user_ns
, gid
);
899 if (!gid_valid(kgid
))
902 new = prepare_creds();
906 if (gid_eq(kgid
, old
->gid
) || gid_eq(kgid
, old
->egid
) ||
907 gid_eq(kgid
, old
->sgid
) || gid_eq(kgid
, old
->fsgid
) ||
908 ns_capable_setid(old
->user_ns
, CAP_SETGID
)) {
909 if (!gid_eq(kgid
, old
->fsgid
)) {
911 if (security_task_fix_setgid(new,old
,LSM_SETID_FS
) == 0)
924 SYSCALL_DEFINE1(setfsgid
, gid_t
, gid
)
926 return __sys_setfsgid(gid
);
928 #endif /* CONFIG_MULTIUSER */
931 * sys_getpid - return the thread group id of the current process
933 * Note, despite the name, this returns the tgid not the pid. The tgid and
934 * the pid are identical unless CLONE_THREAD was specified on clone() in
935 * which case the tgid is the same in all threads of the same group.
937 * This is SMP safe as current->tgid does not change.
939 SYSCALL_DEFINE0(getpid
)
941 return task_tgid_vnr(current
);
944 /* Thread ID - the internal kernel "pid" */
945 SYSCALL_DEFINE0(gettid
)
947 return task_pid_vnr(current
);
951 * Accessing ->real_parent is not SMP-safe, it could
952 * change from under us. However, we can use a stale
953 * value of ->real_parent under rcu_read_lock(), see
954 * release_task()->call_rcu(delayed_put_task_struct).
956 SYSCALL_DEFINE0(getppid
)
961 pid
= task_tgid_vnr(rcu_dereference(current
->real_parent
));
967 SYSCALL_DEFINE0(getuid
)
969 /* Only we change this so SMP safe */
970 return from_kuid_munged(current_user_ns(), current_uid());
973 SYSCALL_DEFINE0(geteuid
)
975 /* Only we change this so SMP safe */
976 return from_kuid_munged(current_user_ns(), current_euid());
979 SYSCALL_DEFINE0(getgid
)
981 /* Only we change this so SMP safe */
982 return from_kgid_munged(current_user_ns(), current_gid());
985 SYSCALL_DEFINE0(getegid
)
987 /* Only we change this so SMP safe */
988 return from_kgid_munged(current_user_ns(), current_egid());
991 static void do_sys_times(struct tms
*tms
)
993 u64 tgutime
, tgstime
, cutime
, cstime
;
995 thread_group_cputime_adjusted(current
, &tgutime
, &tgstime
);
996 cutime
= current
->signal
->cutime
;
997 cstime
= current
->signal
->cstime
;
998 tms
->tms_utime
= nsec_to_clock_t(tgutime
);
999 tms
->tms_stime
= nsec_to_clock_t(tgstime
);
1000 tms
->tms_cutime
= nsec_to_clock_t(cutime
);
1001 tms
->tms_cstime
= nsec_to_clock_t(cstime
);
1004 SYSCALL_DEFINE1(times
, struct tms __user
*, tbuf
)
1010 if (copy_to_user(tbuf
, &tmp
, sizeof(struct tms
)))
1013 force_successful_syscall_return();
1014 return (long) jiffies_64_to_clock_t(get_jiffies_64());
1017 #ifdef CONFIG_COMPAT
1018 static compat_clock_t
clock_t_to_compat_clock_t(clock_t x
)
1020 return compat_jiffies_to_clock_t(clock_t_to_jiffies(x
));
1023 COMPAT_SYSCALL_DEFINE1(times
, struct compat_tms __user
*, tbuf
)
1027 struct compat_tms tmp
;
1030 /* Convert our struct tms to the compat version. */
1031 tmp
.tms_utime
= clock_t_to_compat_clock_t(tms
.tms_utime
);
1032 tmp
.tms_stime
= clock_t_to_compat_clock_t(tms
.tms_stime
);
1033 tmp
.tms_cutime
= clock_t_to_compat_clock_t(tms
.tms_cutime
);
1034 tmp
.tms_cstime
= clock_t_to_compat_clock_t(tms
.tms_cstime
);
1035 if (copy_to_user(tbuf
, &tmp
, sizeof(tmp
)))
1038 force_successful_syscall_return();
1039 return compat_jiffies_to_clock_t(jiffies
);
1044 * This needs some heavy checking ...
1045 * I just haven't the stomach for it. I also don't fully
1046 * understand sessions/pgrp etc. Let somebody who does explain it.
1048 * OK, I think I have the protection semantics right.... this is really
1049 * only important on a multi-user system anyway, to make sure one user
1050 * can't send a signal to a process owned by another. -TYT, 12/12/91
1052 * !PF_FORKNOEXEC check to conform completely to POSIX.
1054 SYSCALL_DEFINE2(setpgid
, pid_t
, pid
, pid_t
, pgid
)
1056 struct task_struct
*p
;
1057 struct task_struct
*group_leader
= current
->group_leader
;
1062 pid
= task_pid_vnr(group_leader
);
1069 /* From this point forward we keep holding onto the tasklist lock
1070 * so that our parent does not change from under us. -DaveM
1072 write_lock_irq(&tasklist_lock
);
1075 p
= find_task_by_vpid(pid
);
1080 if (!thread_group_leader(p
))
1083 if (same_thread_group(p
->real_parent
, group_leader
)) {
1085 if (task_session(p
) != task_session(group_leader
))
1088 if (!(p
->flags
& PF_FORKNOEXEC
))
1092 if (p
!= group_leader
)
1097 if (p
->signal
->leader
)
1102 struct task_struct
*g
;
1104 pgrp
= find_vpid(pgid
);
1105 g
= pid_task(pgrp
, PIDTYPE_PGID
);
1106 if (!g
|| task_session(g
) != task_session(group_leader
))
1110 err
= security_task_setpgid(p
, pgid
);
1114 if (task_pgrp(p
) != pgrp
)
1115 change_pid(p
, PIDTYPE_PGID
, pgrp
);
1119 /* All paths lead to here, thus we are safe. -DaveM */
1120 write_unlock_irq(&tasklist_lock
);
1125 static int do_getpgid(pid_t pid
)
1127 struct task_struct
*p
;
1133 grp
= task_pgrp(current
);
1136 p
= find_task_by_vpid(pid
);
1143 retval
= security_task_getpgid(p
);
1147 retval
= pid_vnr(grp
);
1153 SYSCALL_DEFINE1(getpgid
, pid_t
, pid
)
1155 return do_getpgid(pid
);
1158 #ifdef __ARCH_WANT_SYS_GETPGRP
1160 SYSCALL_DEFINE0(getpgrp
)
1162 return do_getpgid(0);
1167 SYSCALL_DEFINE1(getsid
, pid_t
, pid
)
1169 struct task_struct
*p
;
1175 sid
= task_session(current
);
1178 p
= find_task_by_vpid(pid
);
1181 sid
= task_session(p
);
1185 retval
= security_task_getsid(p
);
1189 retval
= pid_vnr(sid
);
1195 static void set_special_pids(struct pid
*pid
)
1197 struct task_struct
*curr
= current
->group_leader
;
1199 if (task_session(curr
) != pid
)
1200 change_pid(curr
, PIDTYPE_SID
, pid
);
1202 if (task_pgrp(curr
) != pid
)
1203 change_pid(curr
, PIDTYPE_PGID
, pid
);
1206 int ksys_setsid(void)
1208 struct task_struct
*group_leader
= current
->group_leader
;
1209 struct pid
*sid
= task_pid(group_leader
);
1210 pid_t session
= pid_vnr(sid
);
1213 write_lock_irq(&tasklist_lock
);
1214 /* Fail if I am already a session leader */
1215 if (group_leader
->signal
->leader
)
1218 /* Fail if a process group id already exists that equals the
1219 * proposed session id.
1221 if (pid_task(sid
, PIDTYPE_PGID
))
1224 group_leader
->signal
->leader
= 1;
1225 set_special_pids(sid
);
1227 proc_clear_tty(group_leader
);
1231 write_unlock_irq(&tasklist_lock
);
1233 proc_sid_connector(group_leader
);
1234 sched_autogroup_create_attach(group_leader
);
1239 SYSCALL_DEFINE0(setsid
)
1241 return ksys_setsid();
1244 DECLARE_RWSEM(uts_sem
);
1246 #ifdef COMPAT_UTS_MACHINE
1247 #define override_architecture(name) \
1248 (personality(current->personality) == PER_LINUX32 && \
1249 copy_to_user(name->machine, COMPAT_UTS_MACHINE, \
1250 sizeof(COMPAT_UTS_MACHINE)))
1252 #define override_architecture(name) 0
1256 * Work around broken programs that cannot handle "Linux 3.0".
1257 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
1258 * And we map 4.x and later versions to 2.6.60+x, so 4.0/5.0/6.0/... would be
1261 static int override_release(char __user
*release
, size_t len
)
1265 if (current
->personality
& UNAME26
) {
1266 const char *rest
= UTS_RELEASE
;
1267 char buf
[65] = { 0 };
1273 if (*rest
== '.' && ++ndots
>= 3)
1275 if (!isdigit(*rest
) && *rest
!= '.')
1279 v
= LINUX_VERSION_PATCHLEVEL
+ 60;
1280 copy
= clamp_t(size_t, len
, 1, sizeof(buf
));
1281 copy
= scnprintf(buf
, copy
, "2.6.%u%s", v
, rest
);
1282 ret
= copy_to_user(release
, buf
, copy
+ 1);
1287 SYSCALL_DEFINE1(newuname
, struct new_utsname __user
*, name
)
1289 struct new_utsname tmp
;
1291 down_read(&uts_sem
);
1292 memcpy(&tmp
, utsname(), sizeof(tmp
));
1294 if (copy_to_user(name
, &tmp
, sizeof(tmp
)))
1297 if (override_release(name
->release
, sizeof(name
->release
)))
1299 if (override_architecture(name
))
1304 #ifdef __ARCH_WANT_SYS_OLD_UNAME
1308 SYSCALL_DEFINE1(uname
, struct old_utsname __user
*, name
)
1310 struct old_utsname tmp
;
1315 down_read(&uts_sem
);
1316 memcpy(&tmp
, utsname(), sizeof(tmp
));
1318 if (copy_to_user(name
, &tmp
, sizeof(tmp
)))
1321 if (override_release(name
->release
, sizeof(name
->release
)))
1323 if (override_architecture(name
))
1328 SYSCALL_DEFINE1(olduname
, struct oldold_utsname __user
*, name
)
1330 struct oldold_utsname tmp
;
1335 memset(&tmp
, 0, sizeof(tmp
));
1337 down_read(&uts_sem
);
1338 memcpy(&tmp
.sysname
, &utsname()->sysname
, __OLD_UTS_LEN
);
1339 memcpy(&tmp
.nodename
, &utsname()->nodename
, __OLD_UTS_LEN
);
1340 memcpy(&tmp
.release
, &utsname()->release
, __OLD_UTS_LEN
);
1341 memcpy(&tmp
.version
, &utsname()->version
, __OLD_UTS_LEN
);
1342 memcpy(&tmp
.machine
, &utsname()->machine
, __OLD_UTS_LEN
);
1344 if (copy_to_user(name
, &tmp
, sizeof(tmp
)))
1347 if (override_architecture(name
))
1349 if (override_release(name
->release
, sizeof(name
->release
)))
1355 SYSCALL_DEFINE2(sethostname
, char __user
*, name
, int, len
)
1358 char tmp
[__NEW_UTS_LEN
];
1360 if (!ns_capable(current
->nsproxy
->uts_ns
->user_ns
, CAP_SYS_ADMIN
))
1363 if (len
< 0 || len
> __NEW_UTS_LEN
)
1366 if (!copy_from_user(tmp
, name
, len
)) {
1367 struct new_utsname
*u
;
1369 down_write(&uts_sem
);
1371 memcpy(u
->nodename
, tmp
, len
);
1372 memset(u
->nodename
+ len
, 0, sizeof(u
->nodename
) - len
);
1374 uts_proc_notify(UTS_PROC_HOSTNAME
);
1380 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1382 SYSCALL_DEFINE2(gethostname
, char __user
*, name
, int, len
)
1385 struct new_utsname
*u
;
1386 char tmp
[__NEW_UTS_LEN
+ 1];
1390 down_read(&uts_sem
);
1392 i
= 1 + strlen(u
->nodename
);
1395 memcpy(tmp
, u
->nodename
, i
);
1397 if (copy_to_user(name
, tmp
, i
))
1405 * Only setdomainname; getdomainname can be implemented by calling
1408 SYSCALL_DEFINE2(setdomainname
, char __user
*, name
, int, len
)
1411 char tmp
[__NEW_UTS_LEN
];
1413 if (!ns_capable(current
->nsproxy
->uts_ns
->user_ns
, CAP_SYS_ADMIN
))
1415 if (len
< 0 || len
> __NEW_UTS_LEN
)
1419 if (!copy_from_user(tmp
, name
, len
)) {
1420 struct new_utsname
*u
;
1422 down_write(&uts_sem
);
1424 memcpy(u
->domainname
, tmp
, len
);
1425 memset(u
->domainname
+ len
, 0, sizeof(u
->domainname
) - len
);
1427 uts_proc_notify(UTS_PROC_DOMAINNAME
);
1433 /* make sure you are allowed to change @tsk limits before calling this */
1434 static int do_prlimit(struct task_struct
*tsk
, unsigned int resource
,
1435 struct rlimit
*new_rlim
, struct rlimit
*old_rlim
)
1437 struct rlimit
*rlim
;
1440 if (resource
>= RLIM_NLIMITS
)
1443 if (new_rlim
->rlim_cur
> new_rlim
->rlim_max
)
1445 if (resource
== RLIMIT_NOFILE
&&
1446 new_rlim
->rlim_max
> sysctl_nr_open
)
1450 /* Holding a refcount on tsk protects tsk->signal from disappearing. */
1451 rlim
= tsk
->signal
->rlim
+ resource
;
1452 task_lock(tsk
->group_leader
);
1455 * Keep the capable check against init_user_ns until cgroups can
1456 * contain all limits.
1458 if (new_rlim
->rlim_max
> rlim
->rlim_max
&&
1459 !capable(CAP_SYS_RESOURCE
))
1462 retval
= security_task_setrlimit(tsk
, resource
, new_rlim
);
1470 task_unlock(tsk
->group_leader
);
1473 * RLIMIT_CPU handling. Arm the posix CPU timer if the limit is not
1474 * infinite. In case of RLIM_INFINITY the posix CPU timer code
1475 * ignores the rlimit.
1477 if (!retval
&& new_rlim
&& resource
== RLIMIT_CPU
&&
1478 new_rlim
->rlim_cur
!= RLIM_INFINITY
&&
1479 IS_ENABLED(CONFIG_POSIX_TIMERS
)) {
1481 * update_rlimit_cpu can fail if the task is exiting, but there
1482 * may be other tasks in the thread group that are not exiting,
1483 * and they need their cpu timers adjusted.
1485 * The group_leader is the last task to be released, so if we
1486 * cannot update_rlimit_cpu on it, then the entire process is
1487 * exiting and we do not need to update at all.
1489 update_rlimit_cpu(tsk
->group_leader
, new_rlim
->rlim_cur
);
1495 SYSCALL_DEFINE2(getrlimit
, unsigned int, resource
, struct rlimit __user
*, rlim
)
1497 struct rlimit value
;
1500 ret
= do_prlimit(current
, resource
, NULL
, &value
);
1502 ret
= copy_to_user(rlim
, &value
, sizeof(*rlim
)) ? -EFAULT
: 0;
1507 #ifdef CONFIG_COMPAT
1509 COMPAT_SYSCALL_DEFINE2(setrlimit
, unsigned int, resource
,
1510 struct compat_rlimit __user
*, rlim
)
1513 struct compat_rlimit r32
;
1515 if (copy_from_user(&r32
, rlim
, sizeof(struct compat_rlimit
)))
1518 if (r32
.rlim_cur
== COMPAT_RLIM_INFINITY
)
1519 r
.rlim_cur
= RLIM_INFINITY
;
1521 r
.rlim_cur
= r32
.rlim_cur
;
1522 if (r32
.rlim_max
== COMPAT_RLIM_INFINITY
)
1523 r
.rlim_max
= RLIM_INFINITY
;
1525 r
.rlim_max
= r32
.rlim_max
;
1526 return do_prlimit(current
, resource
, &r
, NULL
);
1529 COMPAT_SYSCALL_DEFINE2(getrlimit
, unsigned int, resource
,
1530 struct compat_rlimit __user
*, rlim
)
1535 ret
= do_prlimit(current
, resource
, NULL
, &r
);
1537 struct compat_rlimit r32
;
1538 if (r
.rlim_cur
> COMPAT_RLIM_INFINITY
)
1539 r32
.rlim_cur
= COMPAT_RLIM_INFINITY
;
1541 r32
.rlim_cur
= r
.rlim_cur
;
1542 if (r
.rlim_max
> COMPAT_RLIM_INFINITY
)
1543 r32
.rlim_max
= COMPAT_RLIM_INFINITY
;
1545 r32
.rlim_max
= r
.rlim_max
;
1547 if (copy_to_user(rlim
, &r32
, sizeof(struct compat_rlimit
)))
1555 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1558 * Back compatibility for getrlimit. Needed for some apps.
1560 SYSCALL_DEFINE2(old_getrlimit
, unsigned int, resource
,
1561 struct rlimit __user
*, rlim
)
1564 if (resource
>= RLIM_NLIMITS
)
1567 resource
= array_index_nospec(resource
, RLIM_NLIMITS
);
1568 task_lock(current
->group_leader
);
1569 x
= current
->signal
->rlim
[resource
];
1570 task_unlock(current
->group_leader
);
1571 if (x
.rlim_cur
> 0x7FFFFFFF)
1572 x
.rlim_cur
= 0x7FFFFFFF;
1573 if (x
.rlim_max
> 0x7FFFFFFF)
1574 x
.rlim_max
= 0x7FFFFFFF;
1575 return copy_to_user(rlim
, &x
, sizeof(x
)) ? -EFAULT
: 0;
1578 #ifdef CONFIG_COMPAT
1579 COMPAT_SYSCALL_DEFINE2(old_getrlimit
, unsigned int, resource
,
1580 struct compat_rlimit __user
*, rlim
)
1584 if (resource
>= RLIM_NLIMITS
)
1587 resource
= array_index_nospec(resource
, RLIM_NLIMITS
);
1588 task_lock(current
->group_leader
);
1589 r
= current
->signal
->rlim
[resource
];
1590 task_unlock(current
->group_leader
);
1591 if (r
.rlim_cur
> 0x7FFFFFFF)
1592 r
.rlim_cur
= 0x7FFFFFFF;
1593 if (r
.rlim_max
> 0x7FFFFFFF)
1594 r
.rlim_max
= 0x7FFFFFFF;
1596 if (put_user(r
.rlim_cur
, &rlim
->rlim_cur
) ||
1597 put_user(r
.rlim_max
, &rlim
->rlim_max
))
1605 static inline bool rlim64_is_infinity(__u64 rlim64
)
1607 #if BITS_PER_LONG < 64
1608 return rlim64
>= ULONG_MAX
;
1610 return rlim64
== RLIM64_INFINITY
;
1614 static void rlim_to_rlim64(const struct rlimit
*rlim
, struct rlimit64
*rlim64
)
1616 if (rlim
->rlim_cur
== RLIM_INFINITY
)
1617 rlim64
->rlim_cur
= RLIM64_INFINITY
;
1619 rlim64
->rlim_cur
= rlim
->rlim_cur
;
1620 if (rlim
->rlim_max
== RLIM_INFINITY
)
1621 rlim64
->rlim_max
= RLIM64_INFINITY
;
1623 rlim64
->rlim_max
= rlim
->rlim_max
;
1626 static void rlim64_to_rlim(const struct rlimit64
*rlim64
, struct rlimit
*rlim
)
1628 if (rlim64_is_infinity(rlim64
->rlim_cur
))
1629 rlim
->rlim_cur
= RLIM_INFINITY
;
1631 rlim
->rlim_cur
= (unsigned long)rlim64
->rlim_cur
;
1632 if (rlim64_is_infinity(rlim64
->rlim_max
))
1633 rlim
->rlim_max
= RLIM_INFINITY
;
1635 rlim
->rlim_max
= (unsigned long)rlim64
->rlim_max
;
1638 /* rcu lock must be held */
1639 static int check_prlimit_permission(struct task_struct
*task
,
1642 const struct cred
*cred
= current_cred(), *tcred
;
1645 if (current
== task
)
1648 tcred
= __task_cred(task
);
1649 id_match
= (uid_eq(cred
->uid
, tcred
->euid
) &&
1650 uid_eq(cred
->uid
, tcred
->suid
) &&
1651 uid_eq(cred
->uid
, tcred
->uid
) &&
1652 gid_eq(cred
->gid
, tcred
->egid
) &&
1653 gid_eq(cred
->gid
, tcred
->sgid
) &&
1654 gid_eq(cred
->gid
, tcred
->gid
));
1655 if (!id_match
&& !ns_capable(tcred
->user_ns
, CAP_SYS_RESOURCE
))
1658 return security_task_prlimit(cred
, tcred
, flags
);
1661 SYSCALL_DEFINE4(prlimit64
, pid_t
, pid
, unsigned int, resource
,
1662 const struct rlimit64 __user
*, new_rlim
,
1663 struct rlimit64 __user
*, old_rlim
)
1665 struct rlimit64 old64
, new64
;
1666 struct rlimit old
, new;
1667 struct task_struct
*tsk
;
1668 unsigned int checkflags
= 0;
1672 checkflags
|= LSM_PRLIMIT_READ
;
1675 if (copy_from_user(&new64
, new_rlim
, sizeof(new64
)))
1677 rlim64_to_rlim(&new64
, &new);
1678 checkflags
|= LSM_PRLIMIT_WRITE
;
1682 tsk
= pid
? find_task_by_vpid(pid
) : current
;
1687 ret
= check_prlimit_permission(tsk
, checkflags
);
1692 get_task_struct(tsk
);
1695 ret
= do_prlimit(tsk
, resource
, new_rlim
? &new : NULL
,
1696 old_rlim
? &old
: NULL
);
1698 if (!ret
&& old_rlim
) {
1699 rlim_to_rlim64(&old
, &old64
);
1700 if (copy_to_user(old_rlim
, &old64
, sizeof(old64
)))
1704 put_task_struct(tsk
);
1708 SYSCALL_DEFINE2(setrlimit
, unsigned int, resource
, struct rlimit __user
*, rlim
)
1710 struct rlimit new_rlim
;
1712 if (copy_from_user(&new_rlim
, rlim
, sizeof(*rlim
)))
1714 return do_prlimit(current
, resource
, &new_rlim
, NULL
);
1718 * It would make sense to put struct rusage in the task_struct,
1719 * except that would make the task_struct be *really big*. After
1720 * task_struct gets moved into malloc'ed memory, it would
1721 * make sense to do this. It will make moving the rest of the information
1722 * a lot simpler! (Which we're not doing right now because we're not
1723 * measuring them yet).
1725 * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
1726 * races with threads incrementing their own counters. But since word
1727 * reads are atomic, we either get new values or old values and we don't
1728 * care which for the sums. We always take the siglock to protect reading
1729 * the c* fields from p->signal from races with exit.c updating those
1730 * fields when reaping, so a sample either gets all the additions of a
1731 * given child after it's reaped, or none so this sample is before reaping.
1734 * We need to take the siglock for CHILDEREN, SELF and BOTH
1735 * for the cases current multithreaded, non-current single threaded
1736 * non-current multithreaded. Thread traversal is now safe with
1738 * Strictly speaking, we donot need to take the siglock if we are current and
1739 * single threaded, as no one else can take our signal_struct away, no one
1740 * else can reap the children to update signal->c* counters, and no one else
1741 * can race with the signal-> fields. If we do not take any lock, the
1742 * signal-> fields could be read out of order while another thread was just
1743 * exiting. So we should place a read memory barrier when we avoid the lock.
1744 * On the writer side, write memory barrier is implied in __exit_signal
1745 * as __exit_signal releases the siglock spinlock after updating the signal->
1746 * fields. But we don't do this yet to keep things simple.
1750 static void accumulate_thread_rusage(struct task_struct
*t
, struct rusage
*r
)
1752 r
->ru_nvcsw
+= t
->nvcsw
;
1753 r
->ru_nivcsw
+= t
->nivcsw
;
1754 r
->ru_minflt
+= t
->min_flt
;
1755 r
->ru_majflt
+= t
->maj_flt
;
1756 r
->ru_inblock
+= task_io_get_inblock(t
);
1757 r
->ru_oublock
+= task_io_get_oublock(t
);
1760 void getrusage(struct task_struct
*p
, int who
, struct rusage
*r
)
1762 struct task_struct
*t
;
1763 unsigned long flags
;
1764 u64 tgutime
, tgstime
, utime
, stime
;
1765 unsigned long maxrss
= 0;
1767 memset((char *)r
, 0, sizeof (*r
));
1770 if (who
== RUSAGE_THREAD
) {
1771 task_cputime_adjusted(current
, &utime
, &stime
);
1772 accumulate_thread_rusage(p
, r
);
1773 maxrss
= p
->signal
->maxrss
;
1777 if (!lock_task_sighand(p
, &flags
))
1782 case RUSAGE_CHILDREN
:
1783 utime
= p
->signal
->cutime
;
1784 stime
= p
->signal
->cstime
;
1785 r
->ru_nvcsw
= p
->signal
->cnvcsw
;
1786 r
->ru_nivcsw
= p
->signal
->cnivcsw
;
1787 r
->ru_minflt
= p
->signal
->cmin_flt
;
1788 r
->ru_majflt
= p
->signal
->cmaj_flt
;
1789 r
->ru_inblock
= p
->signal
->cinblock
;
1790 r
->ru_oublock
= p
->signal
->coublock
;
1791 maxrss
= p
->signal
->cmaxrss
;
1793 if (who
== RUSAGE_CHILDREN
)
1798 thread_group_cputime_adjusted(p
, &tgutime
, &tgstime
);
1801 r
->ru_nvcsw
+= p
->signal
->nvcsw
;
1802 r
->ru_nivcsw
+= p
->signal
->nivcsw
;
1803 r
->ru_minflt
+= p
->signal
->min_flt
;
1804 r
->ru_majflt
+= p
->signal
->maj_flt
;
1805 r
->ru_inblock
+= p
->signal
->inblock
;
1806 r
->ru_oublock
+= p
->signal
->oublock
;
1807 if (maxrss
< p
->signal
->maxrss
)
1808 maxrss
= p
->signal
->maxrss
;
1811 accumulate_thread_rusage(t
, r
);
1812 } while_each_thread(p
, t
);
1818 unlock_task_sighand(p
, &flags
);
1821 r
->ru_utime
= ns_to_kernel_old_timeval(utime
);
1822 r
->ru_stime
= ns_to_kernel_old_timeval(stime
);
1824 if (who
!= RUSAGE_CHILDREN
) {
1825 struct mm_struct
*mm
= get_task_mm(p
);
1828 setmax_mm_hiwater_rss(&maxrss
, mm
);
1832 r
->ru_maxrss
= maxrss
* (PAGE_SIZE
/ 1024); /* convert pages to KBs */
1835 SYSCALL_DEFINE2(getrusage
, int, who
, struct rusage __user
*, ru
)
1839 if (who
!= RUSAGE_SELF
&& who
!= RUSAGE_CHILDREN
&&
1840 who
!= RUSAGE_THREAD
)
1843 getrusage(current
, who
, &r
);
1844 return copy_to_user(ru
, &r
, sizeof(r
)) ? -EFAULT
: 0;
1847 #ifdef CONFIG_COMPAT
1848 COMPAT_SYSCALL_DEFINE2(getrusage
, int, who
, struct compat_rusage __user
*, ru
)
1852 if (who
!= RUSAGE_SELF
&& who
!= RUSAGE_CHILDREN
&&
1853 who
!= RUSAGE_THREAD
)
1856 getrusage(current
, who
, &r
);
1857 return put_compat_rusage(&r
, ru
);
1861 SYSCALL_DEFINE1(umask
, int, mask
)
1863 mask
= xchg(¤t
->fs
->umask
, mask
& S_IRWXUGO
);
1867 static int prctl_set_mm_exe_file(struct mm_struct
*mm
, unsigned int fd
)
1870 struct inode
*inode
;
1877 inode
= file_inode(exe
.file
);
1880 * Because the original mm->exe_file points to executable file, make
1881 * sure that this one is executable as well, to avoid breaking an
1885 if (!S_ISREG(inode
->i_mode
) || path_noexec(&exe
.file
->f_path
))
1888 err
= file_permission(exe
.file
, MAY_EXEC
);
1892 err
= replace_mm_exe_file(mm
, exe
.file
);
1899 * Check arithmetic relations of passed addresses.
1901 * WARNING: we don't require any capability here so be very careful
1902 * in what is allowed for modification from userspace.
1904 static int validate_prctl_map_addr(struct prctl_mm_map
*prctl_map
)
1906 unsigned long mmap_max_addr
= TASK_SIZE
;
1907 int error
= -EINVAL
, i
;
1909 static const unsigned char offsets
[] = {
1910 offsetof(struct prctl_mm_map
, start_code
),
1911 offsetof(struct prctl_mm_map
, end_code
),
1912 offsetof(struct prctl_mm_map
, start_data
),
1913 offsetof(struct prctl_mm_map
, end_data
),
1914 offsetof(struct prctl_mm_map
, start_brk
),
1915 offsetof(struct prctl_mm_map
, brk
),
1916 offsetof(struct prctl_mm_map
, start_stack
),
1917 offsetof(struct prctl_mm_map
, arg_start
),
1918 offsetof(struct prctl_mm_map
, arg_end
),
1919 offsetof(struct prctl_mm_map
, env_start
),
1920 offsetof(struct prctl_mm_map
, env_end
),
1924 * Make sure the members are not somewhere outside
1925 * of allowed address space.
1927 for (i
= 0; i
< ARRAY_SIZE(offsets
); i
++) {
1928 u64 val
= *(u64
*)((char *)prctl_map
+ offsets
[i
]);
1930 if ((unsigned long)val
>= mmap_max_addr
||
1931 (unsigned long)val
< mmap_min_addr
)
1936 * Make sure the pairs are ordered.
1938 #define __prctl_check_order(__m1, __op, __m2) \
1939 ((unsigned long)prctl_map->__m1 __op \
1940 (unsigned long)prctl_map->__m2) ? 0 : -EINVAL
1941 error
= __prctl_check_order(start_code
, <, end_code
);
1942 error
|= __prctl_check_order(start_data
,<=, end_data
);
1943 error
|= __prctl_check_order(start_brk
, <=, brk
);
1944 error
|= __prctl_check_order(arg_start
, <=, arg_end
);
1945 error
|= __prctl_check_order(env_start
, <=, env_end
);
1948 #undef __prctl_check_order
1953 * Neither we should allow to override limits if they set.
1955 if (check_data_rlimit(rlimit(RLIMIT_DATA
), prctl_map
->brk
,
1956 prctl_map
->start_brk
, prctl_map
->end_data
,
1957 prctl_map
->start_data
))
1965 #ifdef CONFIG_CHECKPOINT_RESTORE
1966 static int prctl_set_mm_map(int opt
, const void __user
*addr
, unsigned long data_size
)
1968 struct prctl_mm_map prctl_map
= { .exe_fd
= (u32
)-1, };
1969 unsigned long user_auxv
[AT_VECTOR_SIZE
];
1970 struct mm_struct
*mm
= current
->mm
;
1973 BUILD_BUG_ON(sizeof(user_auxv
) != sizeof(mm
->saved_auxv
));
1974 BUILD_BUG_ON(sizeof(struct prctl_mm_map
) > 256);
1976 if (opt
== PR_SET_MM_MAP_SIZE
)
1977 return put_user((unsigned int)sizeof(prctl_map
),
1978 (unsigned int __user
*)addr
);
1980 if (data_size
!= sizeof(prctl_map
))
1983 if (copy_from_user(&prctl_map
, addr
, sizeof(prctl_map
)))
1986 error
= validate_prctl_map_addr(&prctl_map
);
1990 if (prctl_map
.auxv_size
) {
1992 * Someone is trying to cheat the auxv vector.
1994 if (!prctl_map
.auxv
||
1995 prctl_map
.auxv_size
> sizeof(mm
->saved_auxv
))
1998 memset(user_auxv
, 0, sizeof(user_auxv
));
1999 if (copy_from_user(user_auxv
,
2000 (const void __user
*)prctl_map
.auxv
,
2001 prctl_map
.auxv_size
))
2004 /* Last entry must be AT_NULL as specification requires */
2005 user_auxv
[AT_VECTOR_SIZE
- 2] = AT_NULL
;
2006 user_auxv
[AT_VECTOR_SIZE
- 1] = AT_NULL
;
2009 if (prctl_map
.exe_fd
!= (u32
)-1) {
2011 * Check if the current user is checkpoint/restore capable.
2012 * At the time of this writing, it checks for CAP_SYS_ADMIN
2013 * or CAP_CHECKPOINT_RESTORE.
2014 * Note that a user with access to ptrace can masquerade an
2015 * arbitrary program as any executable, even setuid ones.
2016 * This may have implications in the tomoyo subsystem.
2018 if (!checkpoint_restore_ns_capable(current_user_ns()))
2021 error
= prctl_set_mm_exe_file(mm
, prctl_map
.exe_fd
);
2027 * arg_lock protects concurrent updates but we still need mmap_lock for
2028 * read to exclude races with sys_brk.
2033 * We don't validate if these members are pointing to
2034 * real present VMAs because application may have correspond
2035 * VMAs already unmapped and kernel uses these members for statistics
2036 * output in procfs mostly, except
2038 * - @start_brk/@brk which are used in do_brk_flags but kernel lookups
2039 * for VMAs when updating these members so anything wrong written
2040 * here cause kernel to swear at userspace program but won't lead
2041 * to any problem in kernel itself
2044 spin_lock(&mm
->arg_lock
);
2045 mm
->start_code
= prctl_map
.start_code
;
2046 mm
->end_code
= prctl_map
.end_code
;
2047 mm
->start_data
= prctl_map
.start_data
;
2048 mm
->end_data
= prctl_map
.end_data
;
2049 mm
->start_brk
= prctl_map
.start_brk
;
2050 mm
->brk
= prctl_map
.brk
;
2051 mm
->start_stack
= prctl_map
.start_stack
;
2052 mm
->arg_start
= prctl_map
.arg_start
;
2053 mm
->arg_end
= prctl_map
.arg_end
;
2054 mm
->env_start
= prctl_map
.env_start
;
2055 mm
->env_end
= prctl_map
.env_end
;
2056 spin_unlock(&mm
->arg_lock
);
2059 * Note this update of @saved_auxv is lockless thus
2060 * if someone reads this member in procfs while we're
2061 * updating -- it may get partly updated results. It's
2062 * known and acceptable trade off: we leave it as is to
2063 * not introduce additional locks here making the kernel
2066 if (prctl_map
.auxv_size
)
2067 memcpy(mm
->saved_auxv
, user_auxv
, sizeof(user_auxv
));
2069 mmap_read_unlock(mm
);
2072 #endif /* CONFIG_CHECKPOINT_RESTORE */
2074 static int prctl_set_auxv(struct mm_struct
*mm
, unsigned long addr
,
2078 * This doesn't move the auxiliary vector itself since it's pinned to
2079 * mm_struct, but it permits filling the vector with new values. It's
2080 * up to the caller to provide sane values here, otherwise userspace
2081 * tools which use this vector might be unhappy.
2083 unsigned long user_auxv
[AT_VECTOR_SIZE
] = {};
2085 if (len
> sizeof(user_auxv
))
2088 if (copy_from_user(user_auxv
, (const void __user
*)addr
, len
))
2091 /* Make sure the last entry is always AT_NULL */
2092 user_auxv
[AT_VECTOR_SIZE
- 2] = 0;
2093 user_auxv
[AT_VECTOR_SIZE
- 1] = 0;
2095 BUILD_BUG_ON(sizeof(user_auxv
) != sizeof(mm
->saved_auxv
));
2098 memcpy(mm
->saved_auxv
, user_auxv
, len
);
2099 task_unlock(current
);
2104 static int prctl_set_mm(int opt
, unsigned long addr
,
2105 unsigned long arg4
, unsigned long arg5
)
2107 struct mm_struct
*mm
= current
->mm
;
2108 struct prctl_mm_map prctl_map
= {
2113 struct vm_area_struct
*vma
;
2116 if (arg5
|| (arg4
&& (opt
!= PR_SET_MM_AUXV
&&
2117 opt
!= PR_SET_MM_MAP
&&
2118 opt
!= PR_SET_MM_MAP_SIZE
)))
2121 #ifdef CONFIG_CHECKPOINT_RESTORE
2122 if (opt
== PR_SET_MM_MAP
|| opt
== PR_SET_MM_MAP_SIZE
)
2123 return prctl_set_mm_map(opt
, (const void __user
*)addr
, arg4
);
2126 if (!capable(CAP_SYS_RESOURCE
))
2129 if (opt
== PR_SET_MM_EXE_FILE
)
2130 return prctl_set_mm_exe_file(mm
, (unsigned int)addr
);
2132 if (opt
== PR_SET_MM_AUXV
)
2133 return prctl_set_auxv(mm
, addr
, arg4
);
2135 if (addr
>= TASK_SIZE
|| addr
< mmap_min_addr
)
2141 * arg_lock protects concurrent updates of arg boundaries, we need
2142 * mmap_lock for a) concurrent sys_brk, b) finding VMA for addr
2146 vma
= find_vma(mm
, addr
);
2148 spin_lock(&mm
->arg_lock
);
2149 prctl_map
.start_code
= mm
->start_code
;
2150 prctl_map
.end_code
= mm
->end_code
;
2151 prctl_map
.start_data
= mm
->start_data
;
2152 prctl_map
.end_data
= mm
->end_data
;
2153 prctl_map
.start_brk
= mm
->start_brk
;
2154 prctl_map
.brk
= mm
->brk
;
2155 prctl_map
.start_stack
= mm
->start_stack
;
2156 prctl_map
.arg_start
= mm
->arg_start
;
2157 prctl_map
.arg_end
= mm
->arg_end
;
2158 prctl_map
.env_start
= mm
->env_start
;
2159 prctl_map
.env_end
= mm
->env_end
;
2162 case PR_SET_MM_START_CODE
:
2163 prctl_map
.start_code
= addr
;
2165 case PR_SET_MM_END_CODE
:
2166 prctl_map
.end_code
= addr
;
2168 case PR_SET_MM_START_DATA
:
2169 prctl_map
.start_data
= addr
;
2171 case PR_SET_MM_END_DATA
:
2172 prctl_map
.end_data
= addr
;
2174 case PR_SET_MM_START_STACK
:
2175 prctl_map
.start_stack
= addr
;
2177 case PR_SET_MM_START_BRK
:
2178 prctl_map
.start_brk
= addr
;
2181 prctl_map
.brk
= addr
;
2183 case PR_SET_MM_ARG_START
:
2184 prctl_map
.arg_start
= addr
;
2186 case PR_SET_MM_ARG_END
:
2187 prctl_map
.arg_end
= addr
;
2189 case PR_SET_MM_ENV_START
:
2190 prctl_map
.env_start
= addr
;
2192 case PR_SET_MM_ENV_END
:
2193 prctl_map
.env_end
= addr
;
2199 error
= validate_prctl_map_addr(&prctl_map
);
2205 * If command line arguments and environment
2206 * are placed somewhere else on stack, we can
2207 * set them up here, ARG_START/END to setup
2208 * command line arguments and ENV_START/END
2211 case PR_SET_MM_START_STACK
:
2212 case PR_SET_MM_ARG_START
:
2213 case PR_SET_MM_ARG_END
:
2214 case PR_SET_MM_ENV_START
:
2215 case PR_SET_MM_ENV_END
:
2222 mm
->start_code
= prctl_map
.start_code
;
2223 mm
->end_code
= prctl_map
.end_code
;
2224 mm
->start_data
= prctl_map
.start_data
;
2225 mm
->end_data
= prctl_map
.end_data
;
2226 mm
->start_brk
= prctl_map
.start_brk
;
2227 mm
->brk
= prctl_map
.brk
;
2228 mm
->start_stack
= prctl_map
.start_stack
;
2229 mm
->arg_start
= prctl_map
.arg_start
;
2230 mm
->arg_end
= prctl_map
.arg_end
;
2231 mm
->env_start
= prctl_map
.env_start
;
2232 mm
->env_end
= prctl_map
.env_end
;
2236 spin_unlock(&mm
->arg_lock
);
2237 mmap_read_unlock(mm
);
2241 #ifdef CONFIG_CHECKPOINT_RESTORE
2242 static int prctl_get_tid_address(struct task_struct
*me
, int __user
* __user
*tid_addr
)
2244 return put_user(me
->clear_child_tid
, tid_addr
);
2247 static int prctl_get_tid_address(struct task_struct
*me
, int __user
* __user
*tid_addr
)
2253 static int propagate_has_child_subreaper(struct task_struct
*p
, void *data
)
2256 * If task has has_child_subreaper - all its descendants
2257 * already have these flag too and new descendants will
2258 * inherit it on fork, skip them.
2260 * If we've found child_reaper - skip descendants in
2261 * it's subtree as they will never get out pidns.
2263 if (p
->signal
->has_child_subreaper
||
2264 is_child_reaper(task_pid(p
)))
2267 p
->signal
->has_child_subreaper
= 1;
2271 int __weak
arch_prctl_spec_ctrl_get(struct task_struct
*t
, unsigned long which
)
2276 int __weak
arch_prctl_spec_ctrl_set(struct task_struct
*t
, unsigned long which
,
2282 #define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE)
2284 #ifdef CONFIG_ANON_VMA_NAME
2286 #define ANON_VMA_NAME_MAX_LEN 80
2287 #define ANON_VMA_NAME_INVALID_CHARS "\\`$[]"
2289 static inline bool is_valid_name_char(char ch
)
2291 /* printable ascii characters, excluding ANON_VMA_NAME_INVALID_CHARS */
2292 return ch
> 0x1f && ch
< 0x7f &&
2293 !strchr(ANON_VMA_NAME_INVALID_CHARS
, ch
);
2296 static int prctl_set_vma(unsigned long opt
, unsigned long addr
,
2297 unsigned long size
, unsigned long arg
)
2299 struct mm_struct
*mm
= current
->mm
;
2300 const char __user
*uname
;
2301 struct anon_vma_name
*anon_name
= NULL
;
2305 case PR_SET_VMA_ANON_NAME
:
2306 uname
= (const char __user
*)arg
;
2310 name
= strndup_user(uname
, ANON_VMA_NAME_MAX_LEN
);
2312 return PTR_ERR(name
);
2314 for (pch
= name
; *pch
!= '\0'; pch
++) {
2315 if (!is_valid_name_char(*pch
)) {
2320 /* anon_vma has its own copy */
2321 anon_name
= anon_vma_name_alloc(name
);
2328 mmap_write_lock(mm
);
2329 error
= madvise_set_anon_name(mm
, addr
, size
, anon_name
);
2330 mmap_write_unlock(mm
);
2331 anon_vma_name_put(anon_name
);
2340 #else /* CONFIG_ANON_VMA_NAME */
2341 static int prctl_set_vma(unsigned long opt
, unsigned long start
,
2342 unsigned long size
, unsigned long arg
)
2346 #endif /* CONFIG_ANON_VMA_NAME */
2348 SYSCALL_DEFINE5(prctl
, int, option
, unsigned long, arg2
, unsigned long, arg3
,
2349 unsigned long, arg4
, unsigned long, arg5
)
2351 struct task_struct
*me
= current
;
2352 unsigned char comm
[sizeof(me
->comm
)];
2355 error
= security_task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
2356 if (error
!= -ENOSYS
)
2361 case PR_SET_PDEATHSIG
:
2362 if (!valid_signal(arg2
)) {
2366 me
->pdeath_signal
= arg2
;
2368 case PR_GET_PDEATHSIG
:
2369 error
= put_user(me
->pdeath_signal
, (int __user
*)arg2
);
2371 case PR_GET_DUMPABLE
:
2372 error
= get_dumpable(me
->mm
);
2374 case PR_SET_DUMPABLE
:
2375 if (arg2
!= SUID_DUMP_DISABLE
&& arg2
!= SUID_DUMP_USER
) {
2379 set_dumpable(me
->mm
, arg2
);
2382 case PR_SET_UNALIGN
:
2383 error
= SET_UNALIGN_CTL(me
, arg2
);
2385 case PR_GET_UNALIGN
:
2386 error
= GET_UNALIGN_CTL(me
, arg2
);
2389 error
= SET_FPEMU_CTL(me
, arg2
);
2392 error
= GET_FPEMU_CTL(me
, arg2
);
2395 error
= SET_FPEXC_CTL(me
, arg2
);
2398 error
= GET_FPEXC_CTL(me
, arg2
);
2401 error
= PR_TIMING_STATISTICAL
;
2404 if (arg2
!= PR_TIMING_STATISTICAL
)
2408 comm
[sizeof(me
->comm
) - 1] = 0;
2409 if (strncpy_from_user(comm
, (char __user
*)arg2
,
2410 sizeof(me
->comm
) - 1) < 0)
2412 set_task_comm(me
, comm
);
2413 proc_comm_connector(me
);
2416 get_task_comm(comm
, me
);
2417 if (copy_to_user((char __user
*)arg2
, comm
, sizeof(comm
)))
2421 error
= GET_ENDIAN(me
, arg2
);
2424 error
= SET_ENDIAN(me
, arg2
);
2426 case PR_GET_SECCOMP
:
2427 error
= prctl_get_seccomp();
2429 case PR_SET_SECCOMP
:
2430 error
= prctl_set_seccomp(arg2
, (char __user
*)arg3
);
2433 error
= GET_TSC_CTL(arg2
);
2436 error
= SET_TSC_CTL(arg2
);
2438 case PR_TASK_PERF_EVENTS_DISABLE
:
2439 error
= perf_event_task_disable();
2441 case PR_TASK_PERF_EVENTS_ENABLE
:
2442 error
= perf_event_task_enable();
2444 case PR_GET_TIMERSLACK
:
2445 if (current
->timer_slack_ns
> ULONG_MAX
)
2448 error
= current
->timer_slack_ns
;
2450 case PR_SET_TIMERSLACK
:
2452 current
->timer_slack_ns
=
2453 current
->default_timer_slack_ns
;
2455 current
->timer_slack_ns
= arg2
;
2461 case PR_MCE_KILL_CLEAR
:
2464 current
->flags
&= ~PF_MCE_PROCESS
;
2466 case PR_MCE_KILL_SET
:
2467 current
->flags
|= PF_MCE_PROCESS
;
2468 if (arg3
== PR_MCE_KILL_EARLY
)
2469 current
->flags
|= PF_MCE_EARLY
;
2470 else if (arg3
== PR_MCE_KILL_LATE
)
2471 current
->flags
&= ~PF_MCE_EARLY
;
2472 else if (arg3
== PR_MCE_KILL_DEFAULT
)
2474 ~(PF_MCE_EARLY
|PF_MCE_PROCESS
);
2482 case PR_MCE_KILL_GET
:
2483 if (arg2
| arg3
| arg4
| arg5
)
2485 if (current
->flags
& PF_MCE_PROCESS
)
2486 error
= (current
->flags
& PF_MCE_EARLY
) ?
2487 PR_MCE_KILL_EARLY
: PR_MCE_KILL_LATE
;
2489 error
= PR_MCE_KILL_DEFAULT
;
2492 error
= prctl_set_mm(arg2
, arg3
, arg4
, arg5
);
2494 case PR_GET_TID_ADDRESS
:
2495 error
= prctl_get_tid_address(me
, (int __user
* __user
*)arg2
);
2497 case PR_SET_CHILD_SUBREAPER
:
2498 me
->signal
->is_child_subreaper
= !!arg2
;
2502 walk_process_tree(me
, propagate_has_child_subreaper
, NULL
);
2504 case PR_GET_CHILD_SUBREAPER
:
2505 error
= put_user(me
->signal
->is_child_subreaper
,
2506 (int __user
*)arg2
);
2508 case PR_SET_NO_NEW_PRIVS
:
2509 if (arg2
!= 1 || arg3
|| arg4
|| arg5
)
2512 task_set_no_new_privs(current
);
2514 case PR_GET_NO_NEW_PRIVS
:
2515 if (arg2
|| arg3
|| arg4
|| arg5
)
2517 return task_no_new_privs(current
) ? 1 : 0;
2518 case PR_GET_THP_DISABLE
:
2519 if (arg2
|| arg3
|| arg4
|| arg5
)
2521 error
= !!test_bit(MMF_DISABLE_THP
, &me
->mm
->flags
);
2523 case PR_SET_THP_DISABLE
:
2524 if (arg3
|| arg4
|| arg5
)
2526 if (mmap_write_lock_killable(me
->mm
))
2529 set_bit(MMF_DISABLE_THP
, &me
->mm
->flags
);
2531 clear_bit(MMF_DISABLE_THP
, &me
->mm
->flags
);
2532 mmap_write_unlock(me
->mm
);
2534 case PR_MPX_ENABLE_MANAGEMENT
:
2535 case PR_MPX_DISABLE_MANAGEMENT
:
2536 /* No longer implemented: */
2538 case PR_SET_FP_MODE
:
2539 error
= SET_FP_MODE(me
, arg2
);
2541 case PR_GET_FP_MODE
:
2542 error
= GET_FP_MODE(me
);
2545 error
= SVE_SET_VL(arg2
);
2548 error
= SVE_GET_VL();
2551 error
= SME_SET_VL(arg2
);
2554 error
= SME_GET_VL();
2556 case PR_GET_SPECULATION_CTRL
:
2557 if (arg3
|| arg4
|| arg5
)
2559 error
= arch_prctl_spec_ctrl_get(me
, arg2
);
2561 case PR_SET_SPECULATION_CTRL
:
2564 error
= arch_prctl_spec_ctrl_set(me
, arg2
, arg3
);
2566 case PR_PAC_RESET_KEYS
:
2567 if (arg3
|| arg4
|| arg5
)
2569 error
= PAC_RESET_KEYS(me
, arg2
);
2571 case PR_PAC_SET_ENABLED_KEYS
:
2574 error
= PAC_SET_ENABLED_KEYS(me
, arg2
, arg3
);
2576 case PR_PAC_GET_ENABLED_KEYS
:
2577 if (arg2
|| arg3
|| arg4
|| arg5
)
2579 error
= PAC_GET_ENABLED_KEYS(me
);
2581 case PR_SET_TAGGED_ADDR_CTRL
:
2582 if (arg3
|| arg4
|| arg5
)
2584 error
= SET_TAGGED_ADDR_CTRL(arg2
);
2586 case PR_GET_TAGGED_ADDR_CTRL
:
2587 if (arg2
|| arg3
|| arg4
|| arg5
)
2589 error
= GET_TAGGED_ADDR_CTRL();
2591 case PR_SET_IO_FLUSHER
:
2592 if (!capable(CAP_SYS_RESOURCE
))
2595 if (arg3
|| arg4
|| arg5
)
2599 current
->flags
|= PR_IO_FLUSHER
;
2601 current
->flags
&= ~PR_IO_FLUSHER
;
2605 case PR_GET_IO_FLUSHER
:
2606 if (!capable(CAP_SYS_RESOURCE
))
2609 if (arg2
|| arg3
|| arg4
|| arg5
)
2612 error
= (current
->flags
& PR_IO_FLUSHER
) == PR_IO_FLUSHER
;
2614 case PR_SET_SYSCALL_USER_DISPATCH
:
2615 error
= set_syscall_user_dispatch(arg2
, arg3
, arg4
,
2616 (char __user
*) arg5
);
2618 #ifdef CONFIG_SCHED_CORE
2620 error
= sched_core_share_pid(arg2
, arg3
, arg4
, arg5
);
2624 error
= prctl_set_vma(arg2
, arg3
, arg4
, arg5
);
2633 SYSCALL_DEFINE3(getcpu
, unsigned __user
*, cpup
, unsigned __user
*, nodep
,
2634 struct getcpu_cache __user
*, unused
)
2637 int cpu
= raw_smp_processor_id();
2640 err
|= put_user(cpu
, cpup
);
2642 err
|= put_user(cpu_to_node(cpu
), nodep
);
2643 return err
? -EFAULT
: 0;
2647 * do_sysinfo - fill in sysinfo struct
2648 * @info: pointer to buffer to fill
2650 static int do_sysinfo(struct sysinfo
*info
)
2652 unsigned long mem_total
, sav_total
;
2653 unsigned int mem_unit
, bitcount
;
2654 struct timespec64 tp
;
2656 memset(info
, 0, sizeof(struct sysinfo
));
2658 ktime_get_boottime_ts64(&tp
);
2659 timens_add_boottime(&tp
);
2660 info
->uptime
= tp
.tv_sec
+ (tp
.tv_nsec
? 1 : 0);
2662 get_avenrun(info
->loads
, 0, SI_LOAD_SHIFT
- FSHIFT
);
2664 info
->procs
= nr_threads
;
2670 * If the sum of all the available memory (i.e. ram + swap)
2671 * is less than can be stored in a 32 bit unsigned long then
2672 * we can be binary compatible with 2.2.x kernels. If not,
2673 * well, in that case 2.2.x was broken anyways...
2675 * -Erik Andersen <andersee@debian.org>
2678 mem_total
= info
->totalram
+ info
->totalswap
;
2679 if (mem_total
< info
->totalram
|| mem_total
< info
->totalswap
)
2682 mem_unit
= info
->mem_unit
;
2683 while (mem_unit
> 1) {
2686 sav_total
= mem_total
;
2688 if (mem_total
< sav_total
)
2693 * If mem_total did not overflow, multiply all memory values by
2694 * info->mem_unit and set it to 1. This leaves things compatible
2695 * with 2.2.x, and also retains compatibility with earlier 2.4.x
2700 info
->totalram
<<= bitcount
;
2701 info
->freeram
<<= bitcount
;
2702 info
->sharedram
<<= bitcount
;
2703 info
->bufferram
<<= bitcount
;
2704 info
->totalswap
<<= bitcount
;
2705 info
->freeswap
<<= bitcount
;
2706 info
->totalhigh
<<= bitcount
;
2707 info
->freehigh
<<= bitcount
;
2713 SYSCALL_DEFINE1(sysinfo
, struct sysinfo __user
*, info
)
2719 if (copy_to_user(info
, &val
, sizeof(struct sysinfo
)))
2725 #ifdef CONFIG_COMPAT
2726 struct compat_sysinfo
{
2740 char _f
[20-2*sizeof(u32
)-sizeof(int)];
2743 COMPAT_SYSCALL_DEFINE1(sysinfo
, struct compat_sysinfo __user
*, info
)
2746 struct compat_sysinfo s_32
;
2750 /* Check to see if any memory value is too large for 32-bit and scale
2753 if (upper_32_bits(s
.totalram
) || upper_32_bits(s
.totalswap
)) {
2756 while (s
.mem_unit
< PAGE_SIZE
) {
2761 s
.totalram
>>= bitcount
;
2762 s
.freeram
>>= bitcount
;
2763 s
.sharedram
>>= bitcount
;
2764 s
.bufferram
>>= bitcount
;
2765 s
.totalswap
>>= bitcount
;
2766 s
.freeswap
>>= bitcount
;
2767 s
.totalhigh
>>= bitcount
;
2768 s
.freehigh
>>= bitcount
;
2771 memset(&s_32
, 0, sizeof(s_32
));
2772 s_32
.uptime
= s
.uptime
;
2773 s_32
.loads
[0] = s
.loads
[0];
2774 s_32
.loads
[1] = s
.loads
[1];
2775 s_32
.loads
[2] = s
.loads
[2];
2776 s_32
.totalram
= s
.totalram
;
2777 s_32
.freeram
= s
.freeram
;
2778 s_32
.sharedram
= s
.sharedram
;
2779 s_32
.bufferram
= s
.bufferram
;
2780 s_32
.totalswap
= s
.totalswap
;
2781 s_32
.freeswap
= s
.freeswap
;
2782 s_32
.procs
= s
.procs
;
2783 s_32
.totalhigh
= s
.totalhigh
;
2784 s_32
.freehigh
= s
.freehigh
;
2785 s_32
.mem_unit
= s
.mem_unit
;
2786 if (copy_to_user(info
, &s_32
, sizeof(s_32
)))
2790 #endif /* CONFIG_COMPAT */