4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/config.h>
8 #include <linux/module.h>
10 #include <linux/utsname.h>
11 #include <linux/mman.h>
12 #include <linux/smp_lock.h>
13 #include <linux/notifier.h>
14 #include <linux/reboot.h>
15 #include <linux/prctl.h>
16 #include <linux/init.h>
17 #include <linux/highuid.h>
19 #include <linux/kernel.h>
20 #include <linux/kexec.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/dcookies.h>
29 #include <linux/suspend.h>
30 #include <linux/tty.h>
31 #include <linux/signal.h>
32 #include <linux/cn_proc.h>
34 #include <linux/compat.h>
35 #include <linux/syscalls.h>
36 #include <linux/kprobes.h>
38 #include <asm/uaccess.h>
40 #include <asm/unistd.h>
42 #ifndef SET_UNALIGN_CTL
43 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
45 #ifndef GET_UNALIGN_CTL
46 # define GET_UNALIGN_CTL(a,b) (-EINVAL)
49 # define SET_FPEMU_CTL(a,b) (-EINVAL)
52 # define GET_FPEMU_CTL(a,b) (-EINVAL)
55 # define SET_FPEXC_CTL(a,b) (-EINVAL)
58 # define GET_FPEXC_CTL(a,b) (-EINVAL)
62 * this is where the system-wide overflow UID and GID are defined, for
63 * architectures that now have 32-bit UID/GID but didn't in the past
66 int overflowuid = DEFAULT_OVERFLOWUID;
67 int overflowgid = DEFAULT_OVERFLOWGID;
70 EXPORT_SYMBOL(overflowuid);
71 EXPORT_SYMBOL(overflowgid);
75 * the same as above, but for filesystems which can only store a 16-bit
76 * UID and GID. as such, this is needed on all architectures
79 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
80 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
82 EXPORT_SYMBOL(fs_overflowuid);
83 EXPORT_SYMBOL(fs_overflowgid);
86 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
93 * Notifier list for kernel code which wants to be called
94 * at shutdown. This is used to stop any idling DMA operations
98 static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
101 * Notifier chain core routines. The exported routines below
102 * are layered on top of these, with appropriate locking added.
105 static int notifier_chain_register(struct notifier_block **nl,
106 struct notifier_block *n)
108 while ((*nl) != NULL) {
109 if (n->priority > (*nl)->priority)
114 rcu_assign_pointer(*nl, n);
118 static int notifier_chain_unregister(struct notifier_block **nl,
119 struct notifier_block *n)
121 while ((*nl) != NULL) {
123 rcu_assign_pointer(*nl, n->next);
131 static int __kprobes notifier_call_chain(struct notifier_block **nl,
132 unsigned long val, void *v)
134 int ret = NOTIFY_DONE;
135 struct notifier_block *nb;
137 nb = rcu_dereference(*nl);
139 ret = nb->notifier_call(nb, val, v);
140 if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
142 nb = rcu_dereference(nb->next);
148 * Atomic notifier chain routines. Registration and unregistration
149 * use a mutex, and call_chain is synchronized by RCU (no locks).
153 * atomic_notifier_chain_register - Add notifier to an atomic notifier chain
154 * @nh: Pointer to head of the atomic notifier chain
155 * @n: New entry in notifier chain
157 * Adds a notifier to an atomic notifier chain.
159 * Currently always returns zero.
162 int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
163 struct notifier_block *n)
168 spin_lock_irqsave(&nh->lock, flags);
169 ret = notifier_chain_register(&nh->head, n);
170 spin_unlock_irqrestore(&nh->lock, flags);
174 EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
177 * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain
178 * @nh: Pointer to head of the atomic notifier chain
179 * @n: Entry to remove from notifier chain
181 * Removes a notifier from an atomic notifier chain.
183 * Returns zero on success or %-ENOENT on failure.
185 int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
186 struct notifier_block *n)
191 spin_lock_irqsave(&nh->lock, flags);
192 ret = notifier_chain_unregister(&nh->head, n);
193 spin_unlock_irqrestore(&nh->lock, flags);
198 EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
201 * atomic_notifier_call_chain - Call functions in an atomic notifier chain
202 * @nh: Pointer to head of the atomic notifier chain
203 * @val: Value passed unmodified to notifier function
204 * @v: Pointer passed unmodified to notifier function
206 * Calls each function in a notifier chain in turn. The functions
207 * run in an atomic context, so they must not block.
208 * This routine uses RCU to synchronize with changes to the chain.
210 * If the return value of the notifier can be and'ed
211 * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain
212 * will return immediately, with the return value of
213 * the notifier function which halted execution.
214 * Otherwise the return value is the return value
215 * of the last notifier function called.
218 int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
219 unsigned long val, void *v)
224 ret = notifier_call_chain(&nh->head, val, v);
229 EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
232 * Blocking notifier chain routines. All access to the chain is
233 * synchronized by an rwsem.
237 * blocking_notifier_chain_register - Add notifier to a blocking notifier chain
238 * @nh: Pointer to head of the blocking notifier chain
239 * @n: New entry in notifier chain
241 * Adds a notifier to a blocking notifier chain.
242 * Must be called in process context.
244 * Currently always returns zero.
247 int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
248 struct notifier_block *n)
253 * This code gets used during boot-up, when task switching is
254 * not yet working and interrupts must remain disabled. At
255 * such times we must not call down_write().
257 if (unlikely(system_state == SYSTEM_BOOTING))
258 return notifier_chain_register(&nh->head, n);
260 down_write(&nh->rwsem);
261 ret = notifier_chain_register(&nh->head, n);
262 up_write(&nh->rwsem);
266 EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
269 * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
270 * @nh: Pointer to head of the blocking notifier chain
271 * @n: Entry to remove from notifier chain
273 * Removes a notifier from a blocking notifier chain.
274 * Must be called from process context.
276 * Returns zero on success or %-ENOENT on failure.
278 int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
279 struct notifier_block *n)
284 * This code gets used during boot-up, when task switching is
285 * not yet working and interrupts must remain disabled. At
286 * such times we must not call down_write().
288 if (unlikely(system_state == SYSTEM_BOOTING))
289 return notifier_chain_unregister(&nh->head, n);
291 down_write(&nh->rwsem);
292 ret = notifier_chain_unregister(&nh->head, n);
293 up_write(&nh->rwsem);
297 EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
300 * blocking_notifier_call_chain - Call functions in a blocking notifier chain
301 * @nh: Pointer to head of the blocking notifier chain
302 * @val: Value passed unmodified to notifier function
303 * @v: Pointer passed unmodified to notifier function
305 * Calls each function in a notifier chain in turn. The functions
306 * run in a process context, so they are allowed to block.
308 * If the return value of the notifier can be and'ed
309 * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain
310 * will return immediately, with the return value of
311 * the notifier function which halted execution.
312 * Otherwise the return value is the return value
313 * of the last notifier function called.
316 int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
317 unsigned long val, void *v)
321 down_read(&nh->rwsem);
322 ret = notifier_call_chain(&nh->head, val, v);
327 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
330 * Raw notifier chain routines. There is no protection;
331 * the caller must provide it. Use at your own risk!
335 * raw_notifier_chain_register - Add notifier to a raw notifier chain
336 * @nh: Pointer to head of the raw notifier chain
337 * @n: New entry in notifier chain
339 * Adds a notifier to a raw notifier chain.
340 * All locking must be provided by the caller.
342 * Currently always returns zero.
345 int raw_notifier_chain_register(struct raw_notifier_head *nh,
346 struct notifier_block *n)
348 return notifier_chain_register(&nh->head, n);
351 EXPORT_SYMBOL_GPL(raw_notifier_chain_register);
354 * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain
355 * @nh: Pointer to head of the raw notifier chain
356 * @n: Entry to remove from notifier chain
358 * Removes a notifier from a raw notifier chain.
359 * All locking must be provided by the caller.
361 * Returns zero on success or %-ENOENT on failure.
363 int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
364 struct notifier_block *n)
366 return notifier_chain_unregister(&nh->head, n);
369 EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
372 * raw_notifier_call_chain - Call functions in a raw notifier chain
373 * @nh: Pointer to head of the raw notifier chain
374 * @val: Value passed unmodified to notifier function
375 * @v: Pointer passed unmodified to notifier function
377 * Calls each function in a notifier chain in turn. The functions
378 * run in an undefined context.
379 * All locking must be provided by the caller.
381 * If the return value of the notifier can be and'ed
382 * with %NOTIFY_STOP_MASK then raw_notifier_call_chain
383 * will return immediately, with the return value of
384 * the notifier function which halted execution.
385 * Otherwise the return value is the return value
386 * of the last notifier function called.
389 int raw_notifier_call_chain(struct raw_notifier_head *nh,
390 unsigned long val, void *v)
392 return notifier_call_chain(&nh->head, val, v);
395 EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
398 * register_reboot_notifier - Register function to be called at reboot time
399 * @nb: Info about notifier function to be called
401 * Registers a function with the list of functions
402 * to be called at reboot time.
404 * Currently always returns zero, as blocking_notifier_chain_register
405 * always returns zero.
408 int register_reboot_notifier(struct notifier_block * nb)
410 return blocking_notifier_chain_register(&reboot_notifier_list, nb);
413 EXPORT_SYMBOL(register_reboot_notifier);
416 * unregister_reboot_notifier - Unregister previously registered reboot notifier
417 * @nb: Hook to be unregistered
419 * Unregisters a previously registered reboot
422 * Returns zero on success, or %-ENOENT on failure.
425 int unregister_reboot_notifier(struct notifier_block * nb)
427 return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
430 EXPORT_SYMBOL(unregister_reboot_notifier);
432 static int set_one_prio(struct task_struct *p, int niceval, int error)
436 if (p->uid != current->euid &&
437 p->euid != current->euid && !capable(CAP_SYS_NICE)) {
441 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
445 no_nice = security_task_setnice(p, niceval);
452 set_user_nice(p, niceval);
457 asmlinkage long sys_setpriority(int which, int who, int niceval)
459 struct task_struct *g, *p;
460 struct user_struct *user;
463 if (which > 2 || which < 0)
466 /* normalize: avoid signed division (rounding problems) */
473 read_lock(&tasklist_lock);
478 p = find_task_by_pid(who);
480 error = set_one_prio(p, niceval, error);
484 who = process_group(current);
485 do_each_task_pid(who, PIDTYPE_PGID, p) {
486 error = set_one_prio(p, niceval, error);
487 } while_each_task_pid(who, PIDTYPE_PGID, p);
490 user = current->user;
494 if ((who != current->uid) && !(user = find_user(who)))
495 goto out_unlock; /* No processes for this user */
499 error = set_one_prio(p, niceval, error);
500 while_each_thread(g, p);
501 if (who != current->uid)
502 free_uid(user); /* For find_user() */
506 read_unlock(&tasklist_lock);
512 * Ugh. To avoid negative return values, "getpriority()" will
513 * not return the normal nice-value, but a negated value that
514 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
515 * to stay compatible.
517 asmlinkage long sys_getpriority(int which, int who)
519 struct task_struct *g, *p;
520 struct user_struct *user;
521 long niceval, retval = -ESRCH;
523 if (which > 2 || which < 0)
526 read_lock(&tasklist_lock);
531 p = find_task_by_pid(who);
533 niceval = 20 - task_nice(p);
534 if (niceval > retval)
540 who = process_group(current);
541 do_each_task_pid(who, PIDTYPE_PGID, p) {
542 niceval = 20 - task_nice(p);
543 if (niceval > retval)
545 } while_each_task_pid(who, PIDTYPE_PGID, p);
548 user = current->user;
552 if ((who != current->uid) && !(user = find_user(who)))
553 goto out_unlock; /* No processes for this user */
557 niceval = 20 - task_nice(p);
558 if (niceval > retval)
561 while_each_thread(g, p);
562 if (who != current->uid)
563 free_uid(user); /* for find_user() */
567 read_unlock(&tasklist_lock);
573 * emergency_restart - reboot the system
575 * Without shutting down any hardware or taking any locks
576 * reboot the system. This is called when we know we are in
577 * trouble so this is our best effort to reboot. This is
578 * safe to call in interrupt context.
580 void emergency_restart(void)
582 machine_emergency_restart();
584 EXPORT_SYMBOL_GPL(emergency_restart);
586 void kernel_restart_prepare(char *cmd)
588 blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
589 system_state = SYSTEM_RESTART;
594 * kernel_restart - reboot the system
595 * @cmd: pointer to buffer containing command to execute for restart
598 * Shutdown everything and perform a clean reboot.
599 * This is not safe to call in interrupt context.
601 void kernel_restart(char *cmd)
603 kernel_restart_prepare(cmd);
605 printk(KERN_EMERG "Restarting system.\n");
607 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
610 machine_restart(cmd);
612 EXPORT_SYMBOL_GPL(kernel_restart);
615 * kernel_kexec - reboot the system
617 * Move into place and start executing a preloaded standalone
618 * executable. If nothing was preloaded return an error.
620 void kernel_kexec(void)
623 struct kimage *image;
624 image = xchg(&kexec_image, NULL);
628 kernel_restart_prepare(NULL);
629 printk(KERN_EMERG "Starting new kernel\n");
631 machine_kexec(image);
634 EXPORT_SYMBOL_GPL(kernel_kexec);
636 void kernel_shutdown_prepare(enum system_states state)
638 blocking_notifier_call_chain(&reboot_notifier_list,
639 (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
640 system_state = state;
644 * kernel_halt - halt the system
646 * Shutdown everything and perform a clean system halt.
648 void kernel_halt(void)
650 kernel_shutdown_prepare(SYSTEM_HALT);
651 printk(KERN_EMERG "System halted.\n");
655 EXPORT_SYMBOL_GPL(kernel_halt);
658 * kernel_power_off - power_off the system
660 * Shutdown everything and perform a clean system power_off.
662 void kernel_power_off(void)
664 kernel_shutdown_prepare(SYSTEM_POWER_OFF);
665 printk(KERN_EMERG "Power down.\n");
668 EXPORT_SYMBOL_GPL(kernel_power_off);
670 * Reboot system call: for obvious reasons only root may call it,
671 * and even root needs to set up some magic numbers in the registers
672 * so that some mistake won't make this reboot the whole machine.
673 * You can also set the meaning of the ctrl-alt-del-key here.
675 * reboot doesn't sync: do that yourself before calling this.
677 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
681 /* We only trust the superuser with rebooting the system. */
682 if (!capable(CAP_SYS_BOOT))
685 /* For safety, we require "magic" arguments. */
686 if (magic1 != LINUX_REBOOT_MAGIC1 ||
687 (magic2 != LINUX_REBOOT_MAGIC2 &&
688 magic2 != LINUX_REBOOT_MAGIC2A &&
689 magic2 != LINUX_REBOOT_MAGIC2B &&
690 magic2 != LINUX_REBOOT_MAGIC2C))
693 /* Instead of trying to make the power_off code look like
694 * halt when pm_power_off is not set do it the easy way.
696 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
697 cmd = LINUX_REBOOT_CMD_HALT;
701 case LINUX_REBOOT_CMD_RESTART:
702 kernel_restart(NULL);
705 case LINUX_REBOOT_CMD_CAD_ON:
709 case LINUX_REBOOT_CMD_CAD_OFF:
713 case LINUX_REBOOT_CMD_HALT:
719 case LINUX_REBOOT_CMD_POWER_OFF:
725 case LINUX_REBOOT_CMD_RESTART2:
726 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
730 buffer[sizeof(buffer) - 1] = '\0';
732 kernel_restart(buffer);
735 case LINUX_REBOOT_CMD_KEXEC:
740 #ifdef CONFIG_SOFTWARE_SUSPEND
741 case LINUX_REBOOT_CMD_SW_SUSPEND:
743 int ret = software_suspend();
757 static void deferred_cad(void *dummy)
759 kernel_restart(NULL);
763 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
764 * As it's called within an interrupt, it may NOT sync: the only choice
765 * is whether to reboot at once, or just ignore the ctrl-alt-del.
767 void ctrl_alt_del(void)
769 static DECLARE_WORK(cad_work, deferred_cad, NULL);
772 schedule_work(&cad_work);
774 kill_proc(cad_pid, SIGINT, 1);
779 * Unprivileged users may change the real gid to the effective gid
780 * or vice versa. (BSD-style)
782 * If you set the real gid at all, or set the effective gid to a value not
783 * equal to the real gid, then the saved gid is set to the new effective gid.
785 * This makes it possible for a setgid program to completely drop its
786 * privileges, which is often a useful assertion to make when you are doing
787 * a security audit over a program.
789 * The general idea is that a program which uses just setregid() will be
790 * 100% compatible with BSD. A program which uses just setgid() will be
791 * 100% compatible with POSIX with saved IDs.
793 * SMP: There are not races, the GIDs are checked only by filesystem
794 * operations (as far as semantic preservation is concerned).
796 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
798 int old_rgid = current->gid;
799 int old_egid = current->egid;
800 int new_rgid = old_rgid;
801 int new_egid = old_egid;
804 retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
808 if (rgid != (gid_t) -1) {
809 if ((old_rgid == rgid) ||
810 (current->egid==rgid) ||
816 if (egid != (gid_t) -1) {
817 if ((old_rgid == egid) ||
818 (current->egid == egid) ||
819 (current->sgid == egid) ||
826 if (new_egid != old_egid)
828 current->mm->dumpable = suid_dumpable;
831 if (rgid != (gid_t) -1 ||
832 (egid != (gid_t) -1 && egid != old_rgid))
833 current->sgid = new_egid;
834 current->fsgid = new_egid;
835 current->egid = new_egid;
836 current->gid = new_rgid;
837 key_fsgid_changed(current);
838 proc_id_connector(current, PROC_EVENT_GID);
843 * setgid() is implemented like SysV w/ SAVED_IDS
845 * SMP: Same implicit races as above.
847 asmlinkage long sys_setgid(gid_t gid)
849 int old_egid = current->egid;
852 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
856 if (capable(CAP_SETGID))
860 current->mm->dumpable = suid_dumpable;
863 current->gid = current->egid = current->sgid = current->fsgid = gid;
865 else if ((gid == current->gid) || (gid == current->sgid))
869 current->mm->dumpable = suid_dumpable;
872 current->egid = current->fsgid = gid;
877 key_fsgid_changed(current);
878 proc_id_connector(current, PROC_EVENT_GID);
882 static int set_user(uid_t new_ruid, int dumpclear)
884 struct user_struct *new_user;
886 new_user = alloc_uid(new_ruid);
890 if (atomic_read(&new_user->processes) >=
891 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
892 new_user != &root_user) {
897 switch_uid(new_user);
901 current->mm->dumpable = suid_dumpable;
904 current->uid = new_ruid;
909 * Unprivileged users may change the real uid to the effective uid
910 * or vice versa. (BSD-style)
912 * If you set the real uid at all, or set the effective uid to a value not
913 * equal to the real uid, then the saved uid is set to the new effective uid.
915 * This makes it possible for a setuid program to completely drop its
916 * privileges, which is often a useful assertion to make when you are doing
917 * a security audit over a program.
919 * The general idea is that a program which uses just setreuid() will be
920 * 100% compatible with BSD. A program which uses just setuid() will be
921 * 100% compatible with POSIX with saved IDs.
923 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
925 int old_ruid, old_euid, old_suid, new_ruid, new_euid;
928 retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
932 new_ruid = old_ruid = current->uid;
933 new_euid = old_euid = current->euid;
934 old_suid = current->suid;
936 if (ruid != (uid_t) -1) {
938 if ((old_ruid != ruid) &&
939 (current->euid != ruid) &&
940 !capable(CAP_SETUID))
944 if (euid != (uid_t) -1) {
946 if ((old_ruid != euid) &&
947 (current->euid != euid) &&
948 (current->suid != euid) &&
949 !capable(CAP_SETUID))
953 if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
956 if (new_euid != old_euid)
958 current->mm->dumpable = suid_dumpable;
961 current->fsuid = current->euid = new_euid;
962 if (ruid != (uid_t) -1 ||
963 (euid != (uid_t) -1 && euid != old_ruid))
964 current->suid = current->euid;
965 current->fsuid = current->euid;
967 key_fsuid_changed(current);
968 proc_id_connector(current, PROC_EVENT_UID);
970 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
976 * setuid() is implemented like SysV with SAVED_IDS
978 * Note that SAVED_ID's is deficient in that a setuid root program
979 * like sendmail, for example, cannot set its uid to be a normal
980 * user and then switch back, because if you're root, setuid() sets
981 * the saved uid too. If you don't like this, blame the bright people
982 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
983 * will allow a root program to temporarily drop privileges and be able to
984 * regain them by swapping the real and effective uid.
986 asmlinkage long sys_setuid(uid_t uid)
988 int old_euid = current->euid;
989 int old_ruid, old_suid, new_ruid, new_suid;
992 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
996 old_ruid = new_ruid = current->uid;
997 old_suid = current->suid;
1000 if (capable(CAP_SETUID)) {
1001 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
1004 } else if ((uid != current->uid) && (uid != new_suid))
1007 if (old_euid != uid)
1009 current->mm->dumpable = suid_dumpable;
1012 current->fsuid = current->euid = uid;
1013 current->suid = new_suid;
1015 key_fsuid_changed(current);
1016 proc_id_connector(current, PROC_EVENT_UID);
1018 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
1023 * This function implements a generic ability to update ruid, euid,
1024 * and suid. This allows you to implement the 4.4 compatible seteuid().
1026 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
1028 int old_ruid = current->uid;
1029 int old_euid = current->euid;
1030 int old_suid = current->suid;
1033 retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
1037 if (!capable(CAP_SETUID)) {
1038 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
1039 (ruid != current->euid) && (ruid != current->suid))
1041 if ((euid != (uid_t) -1) && (euid != current->uid) &&
1042 (euid != current->euid) && (euid != current->suid))
1044 if ((suid != (uid_t) -1) && (suid != current->uid) &&
1045 (suid != current->euid) && (suid != current->suid))
1048 if (ruid != (uid_t) -1) {
1049 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
1052 if (euid != (uid_t) -1) {
1053 if (euid != current->euid)
1055 current->mm->dumpable = suid_dumpable;
1058 current->euid = euid;
1060 current->fsuid = current->euid;
1061 if (suid != (uid_t) -1)
1062 current->suid = suid;
1064 key_fsuid_changed(current);
1065 proc_id_connector(current, PROC_EVENT_UID);
1067 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
1070 asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid)
1074 if (!(retval = put_user(current->uid, ruid)) &&
1075 !(retval = put_user(current->euid, euid)))
1076 retval = put_user(current->suid, suid);
1082 * Same as above, but for rgid, egid, sgid.
1084 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
1088 retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
1092 if (!capable(CAP_SETGID)) {
1093 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
1094 (rgid != current->egid) && (rgid != current->sgid))
1096 if ((egid != (gid_t) -1) && (egid != current->gid) &&
1097 (egid != current->egid) && (egid != current->sgid))
1099 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
1100 (sgid != current->egid) && (sgid != current->sgid))
1103 if (egid != (gid_t) -1) {
1104 if (egid != current->egid)
1106 current->mm->dumpable = suid_dumpable;
1109 current->egid = egid;
1111 current->fsgid = current->egid;
1112 if (rgid != (gid_t) -1)
1113 current->gid = rgid;
1114 if (sgid != (gid_t) -1)
1115 current->sgid = sgid;
1117 key_fsgid_changed(current);
1118 proc_id_connector(current, PROC_EVENT_GID);
1122 asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid)
1126 if (!(retval = put_user(current->gid, rgid)) &&
1127 !(retval = put_user(current->egid, egid)))
1128 retval = put_user(current->sgid, sgid);
1135 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
1136 * is used for "access()" and for the NFS daemon (letting nfsd stay at
1137 * whatever uid it wants to). It normally shadows "euid", except when
1138 * explicitly set by setfsuid() or for access..
1140 asmlinkage long sys_setfsuid(uid_t uid)
1144 old_fsuid = current->fsuid;
1145 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
1148 if (uid == current->uid || uid == current->euid ||
1149 uid == current->suid || uid == current->fsuid ||
1150 capable(CAP_SETUID))
1152 if (uid != old_fsuid)
1154 current->mm->dumpable = suid_dumpable;
1157 current->fsuid = uid;
1160 key_fsuid_changed(current);
1161 proc_id_connector(current, PROC_EVENT_UID);
1163 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
1169 * Samma på svenska..
1171 asmlinkage long sys_setfsgid(gid_t gid)
1175 old_fsgid = current->fsgid;
1176 if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
1179 if (gid == current->gid || gid == current->egid ||
1180 gid == current->sgid || gid == current->fsgid ||
1181 capable(CAP_SETGID))
1183 if (gid != old_fsgid)
1185 current->mm->dumpable = suid_dumpable;
1188 current->fsgid = gid;
1189 key_fsgid_changed(current);
1190 proc_id_connector(current, PROC_EVENT_GID);
1195 asmlinkage long sys_times(struct tms __user * tbuf)
1198 * In the SMP world we might just be unlucky and have one of
1199 * the times increment as we use it. Since the value is an
1200 * atomically safe type this is just fine. Conceptually its
1201 * as if the syscall took an instant longer to occur.
1205 cputime_t utime, stime, cutime, cstime;
1208 if (thread_group_empty(current)) {
1210 * Single thread case without the use of any locks.
1212 * We may race with release_task if two threads are
1213 * executing. However, release task first adds up the
1214 * counters (__exit_signal) before removing the task
1215 * from the process tasklist (__unhash_process).
1216 * __exit_signal also acquires and releases the
1217 * siglock which results in the proper memory ordering
1218 * so that the list modifications are always visible
1219 * after the counters have been updated.
1221 * If the counters have been updated by the second thread
1222 * but the thread has not yet been removed from the list
1223 * then the other branch will be executing which will
1224 * block on tasklist_lock until the exit handling of the
1225 * other task is finished.
1227 * This also implies that the sighand->siglock cannot
1228 * be held by another processor. So we can also
1229 * skip acquiring that lock.
1231 utime = cputime_add(current->signal->utime, current->utime);
1232 stime = cputime_add(current->signal->utime, current->stime);
1233 cutime = current->signal->cutime;
1234 cstime = current->signal->cstime;
1239 /* Process with multiple threads */
1240 struct task_struct *tsk = current;
1241 struct task_struct *t;
1243 read_lock(&tasklist_lock);
1244 utime = tsk->signal->utime;
1245 stime = tsk->signal->stime;
1248 utime = cputime_add(utime, t->utime);
1249 stime = cputime_add(stime, t->stime);
1254 * While we have tasklist_lock read-locked, no dying thread
1255 * can be updating current->signal->[us]time. Instead,
1256 * we got their counts included in the live thread loop.
1257 * However, another thread can come in right now and
1258 * do a wait call that updates current->signal->c[us]time.
1259 * To make sure we always see that pair updated atomically,
1260 * we take the siglock around fetching them.
1262 spin_lock_irq(&tsk->sighand->siglock);
1263 cutime = tsk->signal->cutime;
1264 cstime = tsk->signal->cstime;
1265 spin_unlock_irq(&tsk->sighand->siglock);
1266 read_unlock(&tasklist_lock);
1268 tmp.tms_utime = cputime_to_clock_t(utime);
1269 tmp.tms_stime = cputime_to_clock_t(stime);
1270 tmp.tms_cutime = cputime_to_clock_t(cutime);
1271 tmp.tms_cstime = cputime_to_clock_t(cstime);
1272 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
1275 return (long) jiffies_64_to_clock_t(get_jiffies_64());
1279 * This needs some heavy checking ...
1280 * I just haven't the stomach for it. I also don't fully
1281 * understand sessions/pgrp etc. Let somebody who does explain it.
1283 * OK, I think I have the protection semantics right.... this is really
1284 * only important on a multi-user system anyway, to make sure one user
1285 * can't send a signal to a process owned by another. -TYT, 12/12/91
1287 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
1291 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1293 struct task_struct *p;
1294 struct task_struct *group_leader = current->group_leader;
1298 pid = group_leader->pid;
1304 /* From this point forward we keep holding onto the tasklist lock
1305 * so that our parent does not change from under us. -DaveM
1307 write_lock_irq(&tasklist_lock);
1310 p = find_task_by_pid(pid);
1315 if (!thread_group_leader(p))
1318 if (p->real_parent == group_leader) {
1320 if (p->signal->session != group_leader->signal->session)
1327 if (p != group_leader)
1332 if (p->signal->leader)
1336 struct task_struct *p;
1338 do_each_task_pid(pgid, PIDTYPE_PGID, p) {
1339 if (p->signal->session == group_leader->signal->session)
1341 } while_each_task_pid(pgid, PIDTYPE_PGID, p);
1346 err = security_task_setpgid(p, pgid);
1350 if (process_group(p) != pgid) {
1351 detach_pid(p, PIDTYPE_PGID);
1352 p->signal->pgrp = pgid;
1353 attach_pid(p, PIDTYPE_PGID, pgid);
1358 /* All paths lead to here, thus we are safe. -DaveM */
1359 write_unlock_irq(&tasklist_lock);
1363 asmlinkage long sys_getpgid(pid_t pid)
1366 return process_group(current);
1369 struct task_struct *p;
1371 read_lock(&tasklist_lock);
1372 p = find_task_by_pid(pid);
1376 retval = security_task_getpgid(p);
1378 retval = process_group(p);
1380 read_unlock(&tasklist_lock);
1385 #ifdef __ARCH_WANT_SYS_GETPGRP
1387 asmlinkage long sys_getpgrp(void)
1389 /* SMP - assuming writes are word atomic this is fine */
1390 return process_group(current);
1395 asmlinkage long sys_getsid(pid_t pid)
1398 return current->signal->session;
1401 struct task_struct *p;
1403 read_lock(&tasklist_lock);
1404 p = find_task_by_pid(pid);
1408 retval = security_task_getsid(p);
1410 retval = p->signal->session;
1412 read_unlock(&tasklist_lock);
1417 asmlinkage long sys_setsid(void)
1419 struct task_struct *group_leader = current->group_leader;
1423 mutex_lock(&tty_mutex);
1424 write_lock_irq(&tasklist_lock);
1426 pid = find_pid(PIDTYPE_PGID, group_leader->pid);
1430 group_leader->signal->leader = 1;
1431 __set_special_pids(group_leader->pid, group_leader->pid);
1432 group_leader->signal->tty = NULL;
1433 group_leader->signal->tty_old_pgrp = 0;
1434 err = process_group(group_leader);
1436 write_unlock_irq(&tasklist_lock);
1437 mutex_unlock(&tty_mutex);
1442 * Supplementary group IDs
1445 /* init to 2 - one for init_task, one to ensure it is never freed */
1446 struct group_info init_groups = { .usage = ATOMIC_INIT(2) };
1448 struct group_info *groups_alloc(int gidsetsize)
1450 struct group_info *group_info;
1454 nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
1455 /* Make sure we always allocate at least one indirect block pointer */
1456 nblocks = nblocks ? : 1;
1457 group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);
1460 group_info->ngroups = gidsetsize;
1461 group_info->nblocks = nblocks;
1462 atomic_set(&group_info->usage, 1);
1464 if (gidsetsize <= NGROUPS_SMALL) {
1465 group_info->blocks[0] = group_info->small_block;
1467 for (i = 0; i < nblocks; i++) {
1469 b = (void *)__get_free_page(GFP_USER);
1471 goto out_undo_partial_alloc;
1472 group_info->blocks[i] = b;
1477 out_undo_partial_alloc:
1479 free_page((unsigned long)group_info->blocks[i]);
1485 EXPORT_SYMBOL(groups_alloc);
1487 void groups_free(struct group_info *group_info)
1489 if (group_info->blocks[0] != group_info->small_block) {
1491 for (i = 0; i < group_info->nblocks; i++)
1492 free_page((unsigned long)group_info->blocks[i]);
1497 EXPORT_SYMBOL(groups_free);
1499 /* export the group_info to a user-space array */
1500 static int groups_to_user(gid_t __user *grouplist,
1501 struct group_info *group_info)
1504 int count = group_info->ngroups;
1506 for (i = 0; i < group_info->nblocks; i++) {
1507 int cp_count = min(NGROUPS_PER_BLOCK, count);
1508 int off = i * NGROUPS_PER_BLOCK;
1509 int len = cp_count * sizeof(*grouplist);
1511 if (copy_to_user(grouplist+off, group_info->blocks[i], len))
1519 /* fill a group_info from a user-space array - it must be allocated already */
1520 static int groups_from_user(struct group_info *group_info,
1521 gid_t __user *grouplist)
1524 int count = group_info->ngroups;
1526 for (i = 0; i < group_info->nblocks; i++) {
1527 int cp_count = min(NGROUPS_PER_BLOCK, count);
1528 int off = i * NGROUPS_PER_BLOCK;
1529 int len = cp_count * sizeof(*grouplist);
1531 if (copy_from_user(group_info->blocks[i], grouplist+off, len))
1539 /* a simple Shell sort */
1540 static void groups_sort(struct group_info *group_info)
1542 int base, max, stride;
1543 int gidsetsize = group_info->ngroups;
1545 for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
1550 max = gidsetsize - stride;
1551 for (base = 0; base < max; base++) {
1553 int right = left + stride;
1554 gid_t tmp = GROUP_AT(group_info, right);
1556 while (left >= 0 && GROUP_AT(group_info, left) > tmp) {
1557 GROUP_AT(group_info, right) =
1558 GROUP_AT(group_info, left);
1562 GROUP_AT(group_info, right) = tmp;
1568 /* a simple bsearch */
1569 int groups_search(struct group_info *group_info, gid_t grp)
1571 unsigned int left, right;
1577 right = group_info->ngroups;
1578 while (left < right) {
1579 unsigned int mid = (left+right)/2;
1580 int cmp = grp - GROUP_AT(group_info, mid);
1591 /* validate and set current->group_info */
1592 int set_current_groups(struct group_info *group_info)
1595 struct group_info *old_info;
1597 retval = security_task_setgroups(group_info);
1601 groups_sort(group_info);
1602 get_group_info(group_info);
1605 old_info = current->group_info;
1606 current->group_info = group_info;
1607 task_unlock(current);
1609 put_group_info(old_info);
1614 EXPORT_SYMBOL(set_current_groups);
1616 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1621 * SMP: Nobody else can change our grouplist. Thus we are
1628 /* no need to grab task_lock here; it cannot change */
1629 i = current->group_info->ngroups;
1631 if (i > gidsetsize) {
1635 if (groups_to_user(grouplist, current->group_info)) {
1645 * SMP: Our groups are copy-on-write. We can set them safely
1646 * without another task interfering.
1649 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1651 struct group_info *group_info;
1654 if (!capable(CAP_SETGID))
1656 if ((unsigned)gidsetsize > NGROUPS_MAX)
1659 group_info = groups_alloc(gidsetsize);
1662 retval = groups_from_user(group_info, grouplist);
1664 put_group_info(group_info);
1668 retval = set_current_groups(group_info);
1669 put_group_info(group_info);
1675 * Check whether we're fsgid/egid or in the supplemental group..
1677 int in_group_p(gid_t grp)
1680 if (grp != current->fsgid) {
1681 retval = groups_search(current->group_info, grp);
1686 EXPORT_SYMBOL(in_group_p);
1688 int in_egroup_p(gid_t grp)
1691 if (grp != current->egid) {
1692 retval = groups_search(current->group_info, grp);
1697 EXPORT_SYMBOL(in_egroup_p);
1699 DECLARE_RWSEM(uts_sem);
1701 EXPORT_SYMBOL(uts_sem);
1703 asmlinkage long sys_newuname(struct new_utsname __user * name)
1707 down_read(&uts_sem);
1708 if (copy_to_user(name,&system_utsname,sizeof *name))
1714 asmlinkage long sys_sethostname(char __user *name, int len)
1717 char tmp[__NEW_UTS_LEN];
1719 if (!capable(CAP_SYS_ADMIN))
1721 if (len < 0 || len > __NEW_UTS_LEN)
1723 down_write(&uts_sem);
1725 if (!copy_from_user(tmp, name, len)) {
1726 memcpy(system_utsname.nodename, tmp, len);
1727 system_utsname.nodename[len] = 0;
1734 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1736 asmlinkage long sys_gethostname(char __user *name, int len)
1742 down_read(&uts_sem);
1743 i = 1 + strlen(system_utsname.nodename);
1747 if (copy_to_user(name, system_utsname.nodename, i))
1756 * Only setdomainname; getdomainname can be implemented by calling
1759 asmlinkage long sys_setdomainname(char __user *name, int len)
1762 char tmp[__NEW_UTS_LEN];
1764 if (!capable(CAP_SYS_ADMIN))
1766 if (len < 0 || len > __NEW_UTS_LEN)
1769 down_write(&uts_sem);
1771 if (!copy_from_user(tmp, name, len)) {
1772 memcpy(system_utsname.domainname, tmp, len);
1773 system_utsname.domainname[len] = 0;
1780 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1782 if (resource >= RLIM_NLIMITS)
1785 struct rlimit value;
1786 task_lock(current->group_leader);
1787 value = current->signal->rlim[resource];
1788 task_unlock(current->group_leader);
1789 return copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
1793 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1796 * Back compatibility for getrlimit. Needed for some apps.
1799 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1802 if (resource >= RLIM_NLIMITS)
1805 task_lock(current->group_leader);
1806 x = current->signal->rlim[resource];
1807 task_unlock(current->group_leader);
1808 if(x.rlim_cur > 0x7FFFFFFF)
1809 x.rlim_cur = 0x7FFFFFFF;
1810 if(x.rlim_max > 0x7FFFFFFF)
1811 x.rlim_max = 0x7FFFFFFF;
1812 return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1817 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1819 struct rlimit new_rlim, *old_rlim;
1820 unsigned long it_prof_secs;
1823 if (resource >= RLIM_NLIMITS)
1825 if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1827 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1829 old_rlim = current->signal->rlim + resource;
1830 if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
1831 !capable(CAP_SYS_RESOURCE))
1833 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
1836 retval = security_task_setrlimit(resource, &new_rlim);
1840 task_lock(current->group_leader);
1841 *old_rlim = new_rlim;
1842 task_unlock(current->group_leader);
1844 if (resource != RLIMIT_CPU)
1848 * RLIMIT_CPU handling. Note that the kernel fails to return an error
1849 * code if it rejected the user's attempt to set RLIMIT_CPU. This is a
1850 * very long-standing error, and fixing it now risks breakage of
1851 * applications, so we live with it
1853 if (new_rlim.rlim_cur == RLIM_INFINITY)
1856 it_prof_secs = cputime_to_secs(current->signal->it_prof_expires);
1857 if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) {
1858 unsigned long rlim_cur = new_rlim.rlim_cur;
1861 if (rlim_cur == 0) {
1863 * The caller is asking for an immediate RLIMIT_CPU
1864 * expiry. But we use the zero value to mean "it was
1865 * never set". So let's cheat and make it one second
1870 cputime = secs_to_cputime(rlim_cur);
1871 read_lock(&tasklist_lock);
1872 spin_lock_irq(¤t->sighand->siglock);
1873 set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
1874 spin_unlock_irq(¤t->sighand->siglock);
1875 read_unlock(&tasklist_lock);
1882 * It would make sense to put struct rusage in the task_struct,
1883 * except that would make the task_struct be *really big*. After
1884 * task_struct gets moved into malloc'ed memory, it would
1885 * make sense to do this. It will make moving the rest of the information
1886 * a lot simpler! (Which we're not doing right now because we're not
1887 * measuring them yet).
1889 * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
1890 * races with threads incrementing their own counters. But since word
1891 * reads are atomic, we either get new values or old values and we don't
1892 * care which for the sums. We always take the siglock to protect reading
1893 * the c* fields from p->signal from races with exit.c updating those
1894 * fields when reaping, so a sample either gets all the additions of a
1895 * given child after it's reaped, or none so this sample is before reaping.
1897 * tasklist_lock locking optimisation:
1898 * If we are current and single threaded, we do not need to take the tasklist
1899 * lock or the siglock. No one else can take our signal_struct away,
1900 * no one else can reap the children to update signal->c* counters, and
1901 * no one else can race with the signal-> fields.
1902 * If we do not take the tasklist_lock, the signal-> fields could be read
1903 * out of order while another thread was just exiting. So we place a
1904 * read memory barrier when we avoid the lock. On the writer side,
1905 * write memory barrier is implied in __exit_signal as __exit_signal releases
1906 * the siglock spinlock after updating the signal-> fields.
1908 * We don't really need the siglock when we access the non c* fields
1909 * of the signal_struct (for RUSAGE_SELF) even in multithreaded
1910 * case, since we take the tasklist lock for read and the non c* signal->
1911 * fields are updated only in __exit_signal, which is called with
1912 * tasklist_lock taken for write, hence these two threads cannot execute
1917 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1919 struct task_struct *t;
1920 unsigned long flags;
1921 cputime_t utime, stime;
1924 memset((char *) r, 0, sizeof *r);
1925 utime = stime = cputime_zero;
1927 if (p != current || !thread_group_empty(p))
1931 read_lock(&tasklist_lock);
1932 if (unlikely(!p->signal)) {
1933 read_unlock(&tasklist_lock);
1937 /* See locking comments above */
1942 case RUSAGE_CHILDREN:
1943 spin_lock_irqsave(&p->sighand->siglock, flags);
1944 utime = p->signal->cutime;
1945 stime = p->signal->cstime;
1946 r->ru_nvcsw = p->signal->cnvcsw;
1947 r->ru_nivcsw = p->signal->cnivcsw;
1948 r->ru_minflt = p->signal->cmin_flt;
1949 r->ru_majflt = p->signal->cmaj_flt;
1950 spin_unlock_irqrestore(&p->sighand->siglock, flags);
1952 if (who == RUSAGE_CHILDREN)
1956 utime = cputime_add(utime, p->signal->utime);
1957 stime = cputime_add(stime, p->signal->stime);
1958 r->ru_nvcsw += p->signal->nvcsw;
1959 r->ru_nivcsw += p->signal->nivcsw;
1960 r->ru_minflt += p->signal->min_flt;
1961 r->ru_majflt += p->signal->maj_flt;
1964 utime = cputime_add(utime, t->utime);
1965 stime = cputime_add(stime, t->stime);
1966 r->ru_nvcsw += t->nvcsw;
1967 r->ru_nivcsw += t->nivcsw;
1968 r->ru_minflt += t->min_flt;
1969 r->ru_majflt += t->maj_flt;
1979 read_unlock(&tasklist_lock);
1980 cputime_to_timeval(utime, &r->ru_utime);
1981 cputime_to_timeval(stime, &r->ru_stime);
1984 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1987 k_getrusage(p, who, &r);
1988 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1991 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1993 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1995 return getrusage(current, who, ru);
1998 asmlinkage long sys_umask(int mask)
2000 mask = xchg(¤t->fs->umask, mask & S_IRWXUGO);
2004 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
2005 unsigned long arg4, unsigned long arg5)
2009 error = security_task_prctl(option, arg2, arg3, arg4, arg5);
2014 case PR_SET_PDEATHSIG:
2015 if (!valid_signal(arg2)) {
2019 current->pdeath_signal = arg2;
2021 case PR_GET_PDEATHSIG:
2022 error = put_user(current->pdeath_signal, (int __user *)arg2);
2024 case PR_GET_DUMPABLE:
2025 error = current->mm->dumpable;
2027 case PR_SET_DUMPABLE:
2028 if (arg2 < 0 || arg2 > 2) {
2032 current->mm->dumpable = arg2;
2035 case PR_SET_UNALIGN:
2036 error = SET_UNALIGN_CTL(current, arg2);
2038 case PR_GET_UNALIGN:
2039 error = GET_UNALIGN_CTL(current, arg2);
2042 error = SET_FPEMU_CTL(current, arg2);
2045 error = GET_FPEMU_CTL(current, arg2);
2048 error = SET_FPEXC_CTL(current, arg2);
2051 error = GET_FPEXC_CTL(current, arg2);
2054 error = PR_TIMING_STATISTICAL;
2057 if (arg2 == PR_TIMING_STATISTICAL)
2063 case PR_GET_KEEPCAPS:
2064 if (current->keep_capabilities)
2067 case PR_SET_KEEPCAPS:
2068 if (arg2 != 0 && arg2 != 1) {
2072 current->keep_capabilities = arg2;
2075 struct task_struct *me = current;
2076 unsigned char ncomm[sizeof(me->comm)];
2078 ncomm[sizeof(me->comm)-1] = 0;
2079 if (strncpy_from_user(ncomm, (char __user *)arg2,
2080 sizeof(me->comm)-1) < 0)
2082 set_task_comm(me, ncomm);
2086 struct task_struct *me = current;
2087 unsigned char tcomm[sizeof(me->comm)];
2089 get_task_comm(tcomm, me);
2090 if (copy_to_user((char __user *)arg2, tcomm, sizeof(tcomm)))