4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/module.h>
9 #include <linux/utsname.h>
10 #include <linux/mman.h>
11 #include <linux/smp_lock.h>
12 #include <linux/notifier.h>
13 #include <linux/kmod.h>
14 #include <linux/reboot.h>
15 #include <linux/prctl.h>
16 #include <linux/highuid.h>
18 #include <linux/kernel.h>
19 #include <linux/kexec.h>
20 #include <linux/workqueue.h>
21 #include <linux/capability.h>
22 #include <linux/device.h>
23 #include <linux/key.h>
24 #include <linux/times.h>
25 #include <linux/posix-timers.h>
26 #include <linux/security.h>
27 #include <linux/dcookies.h>
28 #include <linux/suspend.h>
29 #include <linux/tty.h>
30 #include <linux/signal.h>
31 #include <linux/cn_proc.h>
32 #include <linux/vs_base.h>
33 #include <linux/vs_cvirt.h>
35 #include <linux/compat.h>
36 #include <linux/syscalls.h>
37 #include <linux/kprobes.h>
39 #include <asm/uaccess.h>
41 #include <asm/unistd.h>
43 #ifndef SET_UNALIGN_CTL
44 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
46 #ifndef GET_UNALIGN_CTL
47 # define GET_UNALIGN_CTL(a,b) (-EINVAL)
50 # define SET_FPEMU_CTL(a,b) (-EINVAL)
53 # define GET_FPEMU_CTL(a,b) (-EINVAL)
56 # define SET_FPEXC_CTL(a,b) (-EINVAL)
59 # define GET_FPEXC_CTL(a,b) (-EINVAL)
62 # define GET_ENDIAN(a,b) (-EINVAL)
65 # define SET_ENDIAN(a,b) (-EINVAL)
69 * this is where the system-wide overflow UID and GID are defined, for
70 * architectures that now have 32-bit UID/GID but didn't in the past
73 int overflowuid = DEFAULT_OVERFLOWUID;
74 int overflowgid = DEFAULT_OVERFLOWGID;
77 EXPORT_SYMBOL(overflowuid);
78 EXPORT_SYMBOL(overflowgid);
82 * the same as above, but for filesystems which can only store a 16-bit
83 * UID and GID. as such, this is needed on all architectures
86 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
87 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
89 EXPORT_SYMBOL(fs_overflowuid);
90 EXPORT_SYMBOL(fs_overflowgid);
93 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
100 * Notifier list for kernel code which wants to be called
101 * at shutdown. This is used to stop any idling DMA operations
105 static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
108 * Notifier chain core routines. The exported routines below
109 * are layered on top of these, with appropriate locking added.
112 static int notifier_chain_register(struct notifier_block **nl,
113 struct notifier_block *n)
115 while ((*nl) != NULL) {
116 if (n->priority > (*nl)->priority)
121 rcu_assign_pointer(*nl, n);
125 static int notifier_chain_unregister(struct notifier_block **nl,
126 struct notifier_block *n)
128 while ((*nl) != NULL) {
130 rcu_assign_pointer(*nl, n->next);
138 static int __kprobes notifier_call_chain(struct notifier_block **nl,
139 unsigned long val, void *v)
141 int ret = NOTIFY_DONE;
142 struct notifier_block *nb, *next_nb;
144 nb = rcu_dereference(*nl);
146 next_nb = rcu_dereference(nb->next);
147 ret = nb->notifier_call(nb, val, v);
148 if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
156 * Atomic notifier chain routines. Registration and unregistration
157 * use a mutex, and call_chain is synchronized by RCU (no locks).
161 * atomic_notifier_chain_register - Add notifier to an atomic notifier chain
162 * @nh: Pointer to head of the atomic notifier chain
163 * @n: New entry in notifier chain
165 * Adds a notifier to an atomic notifier chain.
167 * Currently always returns zero.
170 int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
171 struct notifier_block *n)
176 spin_lock_irqsave(&nh->lock, flags);
177 ret = notifier_chain_register(&nh->head, n);
178 spin_unlock_irqrestore(&nh->lock, flags);
182 EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
185 * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain
186 * @nh: Pointer to head of the atomic notifier chain
187 * @n: Entry to remove from notifier chain
189 * Removes a notifier from an atomic notifier chain.
191 * Returns zero on success or %-ENOENT on failure.
193 int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
194 struct notifier_block *n)
199 spin_lock_irqsave(&nh->lock, flags);
200 ret = notifier_chain_unregister(&nh->head, n);
201 spin_unlock_irqrestore(&nh->lock, flags);
206 EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
209 * atomic_notifier_call_chain - Call functions in an atomic notifier chain
210 * @nh: Pointer to head of the atomic notifier chain
211 * @val: Value passed unmodified to notifier function
212 * @v: Pointer passed unmodified to notifier function
214 * Calls each function in a notifier chain in turn. The functions
215 * run in an atomic context, so they must not block.
216 * This routine uses RCU to synchronize with changes to the chain.
218 * If the return value of the notifier can be and'ed
219 * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain
220 * will return immediately, with the return value of
221 * the notifier function which halted execution.
222 * Otherwise the return value is the return value
223 * of the last notifier function called.
226 int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
227 unsigned long val, void *v)
232 ret = notifier_call_chain(&nh->head, val, v);
237 EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
240 * Blocking notifier chain routines. All access to the chain is
241 * synchronized by an rwsem.
245 * blocking_notifier_chain_register - Add notifier to a blocking notifier chain
246 * @nh: Pointer to head of the blocking notifier chain
247 * @n: New entry in notifier chain
249 * Adds a notifier to a blocking notifier chain.
250 * Must be called in process context.
252 * Currently always returns zero.
255 int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
256 struct notifier_block *n)
261 * This code gets used during boot-up, when task switching is
262 * not yet working and interrupts must remain disabled. At
263 * such times we must not call down_write().
265 if (unlikely(system_state == SYSTEM_BOOTING))
266 return notifier_chain_register(&nh->head, n);
268 down_write(&nh->rwsem);
269 ret = notifier_chain_register(&nh->head, n);
270 up_write(&nh->rwsem);
274 EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
277 * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
278 * @nh: Pointer to head of the blocking notifier chain
279 * @n: Entry to remove from notifier chain
281 * Removes a notifier from a blocking notifier chain.
282 * Must be called from process context.
284 * Returns zero on success or %-ENOENT on failure.
286 int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
287 struct notifier_block *n)
292 * This code gets used during boot-up, when task switching is
293 * not yet working and interrupts must remain disabled. At
294 * such times we must not call down_write().
296 if (unlikely(system_state == SYSTEM_BOOTING))
297 return notifier_chain_unregister(&nh->head, n);
299 down_write(&nh->rwsem);
300 ret = notifier_chain_unregister(&nh->head, n);
301 up_write(&nh->rwsem);
305 EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
308 * blocking_notifier_call_chain - Call functions in a blocking notifier chain
309 * @nh: Pointer to head of the blocking notifier chain
310 * @val: Value passed unmodified to notifier function
311 * @v: Pointer passed unmodified to notifier function
313 * Calls each function in a notifier chain in turn. The functions
314 * run in a process context, so they are allowed to block.
316 * If the return value of the notifier can be and'ed
317 * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain
318 * will return immediately, with the return value of
319 * the notifier function which halted execution.
320 * Otherwise the return value is the return value
321 * of the last notifier function called.
324 int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
325 unsigned long val, void *v)
329 down_read(&nh->rwsem);
330 ret = notifier_call_chain(&nh->head, val, v);
335 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
338 * Raw notifier chain routines. There is no protection;
339 * the caller must provide it. Use at your own risk!
343 * raw_notifier_chain_register - Add notifier to a raw notifier chain
344 * @nh: Pointer to head of the raw notifier chain
345 * @n: New entry in notifier chain
347 * Adds a notifier to a raw notifier chain.
348 * All locking must be provided by the caller.
350 * Currently always returns zero.
353 int raw_notifier_chain_register(struct raw_notifier_head *nh,
354 struct notifier_block *n)
356 return notifier_chain_register(&nh->head, n);
359 EXPORT_SYMBOL_GPL(raw_notifier_chain_register);
362 * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain
363 * @nh: Pointer to head of the raw notifier chain
364 * @n: Entry to remove from notifier chain
366 * Removes a notifier from a raw notifier chain.
367 * All locking must be provided by the caller.
369 * Returns zero on success or %-ENOENT on failure.
371 int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
372 struct notifier_block *n)
374 return notifier_chain_unregister(&nh->head, n);
377 EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
380 * raw_notifier_call_chain - Call functions in a raw notifier chain
381 * @nh: Pointer to head of the raw notifier chain
382 * @val: Value passed unmodified to notifier function
383 * @v: Pointer passed unmodified to notifier function
385 * Calls each function in a notifier chain in turn. The functions
386 * run in an undefined context.
387 * All locking must be provided by the caller.
389 * If the return value of the notifier can be and'ed
390 * with %NOTIFY_STOP_MASK then raw_notifier_call_chain
391 * will return immediately, with the return value of
392 * the notifier function which halted execution.
393 * Otherwise the return value is the return value
394 * of the last notifier function called.
397 int raw_notifier_call_chain(struct raw_notifier_head *nh,
398 unsigned long val, void *v)
400 return notifier_call_chain(&nh->head, val, v);
403 EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
406 * register_reboot_notifier - Register function to be called at reboot time
407 * @nb: Info about notifier function to be called
409 * Registers a function with the list of functions
410 * to be called at reboot time.
412 * Currently always returns zero, as blocking_notifier_chain_register
413 * always returns zero.
416 int register_reboot_notifier(struct notifier_block * nb)
418 return blocking_notifier_chain_register(&reboot_notifier_list, nb);
421 EXPORT_SYMBOL(register_reboot_notifier);
424 * unregister_reboot_notifier - Unregister previously registered reboot notifier
425 * @nb: Hook to be unregistered
427 * Unregisters a previously registered reboot
430 * Returns zero on success, or %-ENOENT on failure.
433 int unregister_reboot_notifier(struct notifier_block * nb)
435 return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
438 EXPORT_SYMBOL(unregister_reboot_notifier);
440 static int set_one_prio(struct task_struct *p, int niceval, int error)
444 if (p->uid != current->euid &&
445 p->euid != current->euid && !capable(CAP_SYS_NICE)) {
449 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
450 if (vx_flags(VXF_IGNEG_NICE, 0))
456 no_nice = security_task_setnice(p, niceval);
463 set_user_nice(p, niceval);
468 asmlinkage long sys_setpriority(int which, int who, int niceval)
470 struct task_struct *g, *p;
471 struct user_struct *user;
474 if (which > 2 || which < 0)
477 /* normalize: avoid signed division (rounding problems) */
484 read_lock(&tasklist_lock);
489 p = find_task_by_pid(who);
491 error = set_one_prio(p, niceval, error);
495 who = process_group(current);
496 do_each_task_pid(who, PIDTYPE_PGID, p) {
497 error = set_one_prio(p, niceval, error);
498 } while_each_task_pid(who, PIDTYPE_PGID, p);
501 user = current->user;
505 if ((who != current->uid) &&
506 !(user = find_user(vx_current_xid(), who)))
507 goto out_unlock; /* No processes for this user */
511 error = set_one_prio(p, niceval, error);
512 while_each_thread(g, p);
513 if (who != current->uid)
514 free_uid(user); /* For find_user() */
518 read_unlock(&tasklist_lock);
524 * Ugh. To avoid negative return values, "getpriority()" will
525 * not return the normal nice-value, but a negated value that
526 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
527 * to stay compatible.
529 asmlinkage long sys_getpriority(int which, int who)
531 struct task_struct *g, *p;
532 struct user_struct *user;
533 long niceval, retval = -ESRCH;
535 if (which > 2 || which < 0)
538 read_lock(&tasklist_lock);
543 p = find_task_by_pid(who);
545 niceval = 20 - task_nice(p);
546 if (niceval > retval)
552 who = process_group(current);
553 do_each_task_pid(who, PIDTYPE_PGID, p) {
554 niceval = 20 - task_nice(p);
555 if (niceval > retval)
557 } while_each_task_pid(who, PIDTYPE_PGID, p);
560 user = current->user;
564 if ((who != current->uid) &&
565 !(user = find_user(vx_current_xid(), who)))
566 goto out_unlock; /* No processes for this user */
570 niceval = 20 - task_nice(p);
571 if (niceval > retval)
574 while_each_thread(g, p);
575 if (who != current->uid)
576 free_uid(user); /* for find_user() */
580 read_unlock(&tasklist_lock);
586 * emergency_restart - reboot the system
588 * Without shutting down any hardware or taking any locks
589 * reboot the system. This is called when we know we are in
590 * trouble so this is our best effort to reboot. This is
591 * safe to call in interrupt context.
593 void emergency_restart(void)
595 machine_emergency_restart();
597 EXPORT_SYMBOL_GPL(emergency_restart);
599 static void kernel_restart_prepare(char *cmd)
601 blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
602 system_state = SYSTEM_RESTART;
607 * kernel_restart - reboot the system
608 * @cmd: pointer to buffer containing command to execute for restart
611 * Shutdown everything and perform a clean reboot.
612 * This is not safe to call in interrupt context.
614 void kernel_restart(char *cmd)
616 kernel_restart_prepare(cmd);
618 printk(KERN_EMERG "Restarting system.\n");
620 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
623 machine_restart(cmd);
625 EXPORT_SYMBOL_GPL(kernel_restart);
628 * kernel_kexec - reboot the system
630 * Move into place and start executing a preloaded standalone
631 * executable. If nothing was preloaded return an error.
633 static void kernel_kexec(void)
636 struct kimage *image;
637 image = xchg(&kexec_image, NULL);
641 kernel_restart_prepare(NULL);
642 printk(KERN_EMERG "Starting new kernel\n");
644 machine_kexec(image);
648 void kernel_shutdown_prepare(enum system_states state)
650 blocking_notifier_call_chain(&reboot_notifier_list,
651 (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
652 system_state = state;
656 * kernel_halt - halt the system
658 * Shutdown everything and perform a clean system halt.
660 void kernel_halt(void)
662 kernel_shutdown_prepare(SYSTEM_HALT);
663 printk(KERN_EMERG "System halted.\n");
667 EXPORT_SYMBOL_GPL(kernel_halt);
670 * kernel_power_off - power_off the system
672 * Shutdown everything and perform a clean system power_off.
674 void kernel_power_off(void)
676 kernel_shutdown_prepare(SYSTEM_POWER_OFF);
677 printk(KERN_EMERG "Power down.\n");
680 EXPORT_SYMBOL_GPL(kernel_power_off);
682 long vs_reboot(unsigned int, void __user *);
685 * Reboot system call: for obvious reasons only root may call it,
686 * and even root needs to set up some magic numbers in the registers
687 * so that some mistake won't make this reboot the whole machine.
688 * You can also set the meaning of the ctrl-alt-del-key here.
690 * reboot doesn't sync: do that yourself before calling this.
692 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
696 /* We only trust the superuser with rebooting the system. */
697 if (!capable(CAP_SYS_BOOT))
700 /* For safety, we require "magic" arguments. */
701 if (magic1 != LINUX_REBOOT_MAGIC1 ||
702 (magic2 != LINUX_REBOOT_MAGIC2 &&
703 magic2 != LINUX_REBOOT_MAGIC2A &&
704 magic2 != LINUX_REBOOT_MAGIC2B &&
705 magic2 != LINUX_REBOOT_MAGIC2C))
708 /* Instead of trying to make the power_off code look like
709 * halt when pm_power_off is not set do it the easy way.
711 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
712 cmd = LINUX_REBOOT_CMD_HALT;
714 if (!vx_check(0, VX_ADMIN|VX_WATCH))
715 return vs_reboot(cmd, arg);
719 case LINUX_REBOOT_CMD_RESTART:
720 kernel_restart(NULL);
723 case LINUX_REBOOT_CMD_CAD_ON:
727 case LINUX_REBOOT_CMD_CAD_OFF:
731 case LINUX_REBOOT_CMD_HALT:
737 case LINUX_REBOOT_CMD_POWER_OFF:
743 case LINUX_REBOOT_CMD_RESTART2:
744 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
748 buffer[sizeof(buffer) - 1] = '\0';
750 kernel_restart(buffer);
753 case LINUX_REBOOT_CMD_KEXEC:
758 #ifdef CONFIG_SOFTWARE_SUSPEND
759 case LINUX_REBOOT_CMD_SW_SUSPEND:
761 int ret = software_suspend();
775 static void deferred_cad(void *dummy)
777 kernel_restart(NULL);
781 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
782 * As it's called within an interrupt, it may NOT sync: the only choice
783 * is whether to reboot at once, or just ignore the ctrl-alt-del.
785 void ctrl_alt_del(void)
787 static DECLARE_WORK(cad_work, deferred_cad, NULL);
790 schedule_work(&cad_work);
792 kill_proc(cad_pid, SIGINT, 1);
797 * Unprivileged users may change the real gid to the effective gid
798 * or vice versa. (BSD-style)
800 * If you set the real gid at all, or set the effective gid to a value not
801 * equal to the real gid, then the saved gid is set to the new effective gid.
803 * This makes it possible for a setgid program to completely drop its
804 * privileges, which is often a useful assertion to make when you are doing
805 * a security audit over a program.
807 * The general idea is that a program which uses just setregid() will be
808 * 100% compatible with BSD. A program which uses just setgid() will be
809 * 100% compatible with POSIX with saved IDs.
811 * SMP: There are not races, the GIDs are checked only by filesystem
812 * operations (as far as semantic preservation is concerned).
814 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
816 int old_rgid = current->gid;
817 int old_egid = current->egid;
818 int new_rgid = old_rgid;
819 int new_egid = old_egid;
822 retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
826 if (rgid != (gid_t) -1) {
827 if ((old_rgid == rgid) ||
828 (current->egid==rgid) ||
834 if (egid != (gid_t) -1) {
835 if ((old_rgid == egid) ||
836 (current->egid == egid) ||
837 (current->sgid == egid) ||
844 if (new_egid != old_egid)
846 current->mm->dumpable = suid_dumpable;
849 if (rgid != (gid_t) -1 ||
850 (egid != (gid_t) -1 && egid != old_rgid))
851 current->sgid = new_egid;
852 current->fsgid = new_egid;
853 current->egid = new_egid;
854 current->gid = new_rgid;
855 key_fsgid_changed(current);
856 proc_id_connector(current, PROC_EVENT_GID);
861 * setgid() is implemented like SysV w/ SAVED_IDS
863 * SMP: Same implicit races as above.
865 asmlinkage long sys_setgid(gid_t gid)
867 int old_egid = current->egid;
870 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
874 if (capable(CAP_SETGID))
878 current->mm->dumpable = suid_dumpable;
881 current->gid = current->egid = current->sgid = current->fsgid = gid;
883 else if ((gid == current->gid) || (gid == current->sgid))
887 current->mm->dumpable = suid_dumpable;
890 current->egid = current->fsgid = gid;
895 key_fsgid_changed(current);
896 proc_id_connector(current, PROC_EVENT_GID);
900 static int set_user(uid_t new_ruid, int dumpclear)
902 struct user_struct *new_user;
904 new_user = alloc_uid(vx_current_xid(), new_ruid);
908 if (atomic_read(&new_user->processes) >=
909 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
910 new_user != &root_user) {
915 switch_uid(new_user);
919 current->mm->dumpable = suid_dumpable;
922 current->uid = new_ruid;
927 * Unprivileged users may change the real uid to the effective uid
928 * or vice versa. (BSD-style)
930 * If you set the real uid at all, or set the effective uid to a value not
931 * equal to the real uid, then the saved uid is set to the new effective uid.
933 * This makes it possible for a setuid program to completely drop its
934 * privileges, which is often a useful assertion to make when you are doing
935 * a security audit over a program.
937 * The general idea is that a program which uses just setreuid() will be
938 * 100% compatible with BSD. A program which uses just setuid() will be
939 * 100% compatible with POSIX with saved IDs.
941 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
943 int old_ruid, old_euid, old_suid, new_ruid, new_euid;
946 retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
950 new_ruid = old_ruid = current->uid;
951 new_euid = old_euid = current->euid;
952 old_suid = current->suid;
954 if (ruid != (uid_t) -1) {
956 if ((old_ruid != ruid) &&
957 (current->euid != ruid) &&
958 !capable(CAP_SETUID))
962 if (euid != (uid_t) -1) {
964 if ((old_ruid != euid) &&
965 (current->euid != euid) &&
966 (current->suid != euid) &&
967 !capable(CAP_SETUID))
971 if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
974 if (new_euid != old_euid)
976 current->mm->dumpable = suid_dumpable;
979 current->fsuid = current->euid = new_euid;
980 if (ruid != (uid_t) -1 ||
981 (euid != (uid_t) -1 && euid != old_ruid))
982 current->suid = current->euid;
983 current->fsuid = current->euid;
985 key_fsuid_changed(current);
986 proc_id_connector(current, PROC_EVENT_UID);
988 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
994 * setuid() is implemented like SysV with SAVED_IDS
996 * Note that SAVED_ID's is deficient in that a setuid root program
997 * like sendmail, for example, cannot set its uid to be a normal
998 * user and then switch back, because if you're root, setuid() sets
999 * the saved uid too. If you don't like this, blame the bright people
1000 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
1001 * will allow a root program to temporarily drop privileges and be able to
1002 * regain them by swapping the real and effective uid.
1004 asmlinkage long sys_setuid(uid_t uid)
1006 int old_euid = current->euid;
1007 int old_ruid, old_suid, new_ruid, new_suid;
1010 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
1014 old_ruid = new_ruid = current->uid;
1015 old_suid = current->suid;
1016 new_suid = old_suid;
1018 if (capable(CAP_SETUID)) {
1019 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
1022 } else if ((uid != current->uid) && (uid != new_suid))
1025 if (old_euid != uid)
1027 current->mm->dumpable = suid_dumpable;
1030 current->fsuid = current->euid = uid;
1031 current->suid = new_suid;
1033 key_fsuid_changed(current);
1034 proc_id_connector(current, PROC_EVENT_UID);
1036 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
1041 * This function implements a generic ability to update ruid, euid,
1042 * and suid. This allows you to implement the 4.4 compatible seteuid().
1044 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
1046 int old_ruid = current->uid;
1047 int old_euid = current->euid;
1048 int old_suid = current->suid;
1051 retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
1055 if (!capable(CAP_SETUID)) {
1056 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
1057 (ruid != current->euid) && (ruid != current->suid))
1059 if ((euid != (uid_t) -1) && (euid != current->uid) &&
1060 (euid != current->euid) && (euid != current->suid))
1062 if ((suid != (uid_t) -1) && (suid != current->uid) &&
1063 (suid != current->euid) && (suid != current->suid))
1066 if (ruid != (uid_t) -1) {
1067 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
1070 if (euid != (uid_t) -1) {
1071 if (euid != current->euid)
1073 current->mm->dumpable = suid_dumpable;
1076 current->euid = euid;
1078 current->fsuid = current->euid;
1079 if (suid != (uid_t) -1)
1080 current->suid = suid;
1082 key_fsuid_changed(current);
1083 proc_id_connector(current, PROC_EVENT_UID);
1085 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
1088 asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid)
1092 if (!(retval = put_user(current->uid, ruid)) &&
1093 !(retval = put_user(current->euid, euid)))
1094 retval = put_user(current->suid, suid);
1100 * Same as above, but for rgid, egid, sgid.
1102 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
1106 retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
1110 if (!capable(CAP_SETGID)) {
1111 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
1112 (rgid != current->egid) && (rgid != current->sgid))
1114 if ((egid != (gid_t) -1) && (egid != current->gid) &&
1115 (egid != current->egid) && (egid != current->sgid))
1117 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
1118 (sgid != current->egid) && (sgid != current->sgid))
1121 if (egid != (gid_t) -1) {
1122 if (egid != current->egid)
1124 current->mm->dumpable = suid_dumpable;
1127 current->egid = egid;
1129 current->fsgid = current->egid;
1130 if (rgid != (gid_t) -1)
1131 current->gid = rgid;
1132 if (sgid != (gid_t) -1)
1133 current->sgid = sgid;
1135 key_fsgid_changed(current);
1136 proc_id_connector(current, PROC_EVENT_GID);
1140 asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid)
1144 if (!(retval = put_user(current->gid, rgid)) &&
1145 !(retval = put_user(current->egid, egid)))
1146 retval = put_user(current->sgid, sgid);
1153 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
1154 * is used for "access()" and for the NFS daemon (letting nfsd stay at
1155 * whatever uid it wants to). It normally shadows "euid", except when
1156 * explicitly set by setfsuid() or for access..
1158 asmlinkage long sys_setfsuid(uid_t uid)
1162 old_fsuid = current->fsuid;
1163 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
1166 if (uid == current->uid || uid == current->euid ||
1167 uid == current->suid || uid == current->fsuid ||
1168 capable(CAP_SETUID))
1170 if (uid != old_fsuid)
1172 current->mm->dumpable = suid_dumpable;
1175 current->fsuid = uid;
1178 key_fsuid_changed(current);
1179 proc_id_connector(current, PROC_EVENT_UID);
1181 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
1187 * Samma på svenska..
1189 asmlinkage long sys_setfsgid(gid_t gid)
1193 old_fsgid = current->fsgid;
1194 if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
1197 if (gid == current->gid || gid == current->egid ||
1198 gid == current->sgid || gid == current->fsgid ||
1199 capable(CAP_SETGID))
1201 if (gid != old_fsgid)
1203 current->mm->dumpable = suid_dumpable;
1206 current->fsgid = gid;
1207 key_fsgid_changed(current);
1208 proc_id_connector(current, PROC_EVENT_GID);
1213 asmlinkage long sys_times(struct tms __user * tbuf)
1216 * In the SMP world we might just be unlucky and have one of
1217 * the times increment as we use it. Since the value is an
1218 * atomically safe type this is just fine. Conceptually its
1219 * as if the syscall took an instant longer to occur.
1223 struct task_struct *tsk = current;
1224 struct task_struct *t;
1225 cputime_t utime, stime, cutime, cstime;
1227 spin_lock_irq(&tsk->sighand->siglock);
1228 utime = tsk->signal->utime;
1229 stime = tsk->signal->stime;
1232 utime = cputime_add(utime, t->utime);
1233 stime = cputime_add(stime, t->stime);
1237 cutime = tsk->signal->cutime;
1238 cstime = tsk->signal->cstime;
1239 spin_unlock_irq(&tsk->sighand->siglock);
1241 tmp.tms_utime = cputime_to_clock_t(utime);
1242 tmp.tms_stime = cputime_to_clock_t(stime);
1243 tmp.tms_cutime = cputime_to_clock_t(cutime);
1244 tmp.tms_cstime = cputime_to_clock_t(cstime);
1245 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
1248 return (long) jiffies_64_to_clock_t(get_jiffies_64());
1252 * This needs some heavy checking ...
1253 * I just haven't the stomach for it. I also don't fully
1254 * understand sessions/pgrp etc. Let somebody who does explain it.
1256 * OK, I think I have the protection semantics right.... this is really
1257 * only important on a multi-user system anyway, to make sure one user
1258 * can't send a signal to a process owned by another. -TYT, 12/12/91
1260 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
1264 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1266 struct task_struct *p;
1267 struct task_struct *group_leader = current->group_leader;
1272 pid = vx_map_pid(group_leader->pid);
1278 rpgid = vx_rmap_pid(pgid);
1280 /* From this point forward we keep holding onto the tasklist lock
1281 * so that our parent does not change from under us. -DaveM
1283 write_lock_irq(&tasklist_lock);
1286 p = find_task_by_pid(pid);
1291 if (!thread_group_leader(p))
1294 if (p->parent == group_leader) {
1296 if (p->signal->session != group_leader->signal->session)
1303 if (p != group_leader)
1308 if (p->signal->leader)
1312 struct task_struct *p;
1314 do_each_task_pid(rpgid, PIDTYPE_PGID, p) {
1315 if (p->signal->session == group_leader->signal->session)
1317 } while_each_task_pid(rpgid, PIDTYPE_PGID, p);
1322 err = security_task_setpgid(p, rpgid);
1326 if (process_group(p) != rpgid) {
1327 detach_pid(p, PIDTYPE_PGID);
1328 p->signal->pgrp = rpgid;
1329 attach_pid(p, PIDTYPE_PGID, rpgid);
1334 /* All paths lead to here, thus we are safe. -DaveM */
1335 write_unlock_irq(&tasklist_lock);
1339 asmlinkage long sys_getpgid(pid_t pid)
1342 return vx_rmap_pid(process_group(current));
1345 struct task_struct *p;
1347 read_lock(&tasklist_lock);
1348 p = find_task_by_pid(pid);
1352 retval = security_task_getpgid(p);
1354 retval = vx_rmap_pid(process_group(p));
1356 read_unlock(&tasklist_lock);
1361 #ifdef __ARCH_WANT_SYS_GETPGRP
1363 asmlinkage long sys_getpgrp(void)
1365 /* SMP - assuming writes are word atomic this is fine */
1366 return process_group(current);
1371 asmlinkage long sys_getsid(pid_t pid)
1374 return current->signal->session;
1377 struct task_struct *p;
1379 read_lock(&tasklist_lock);
1380 p = find_task_by_pid(pid);
1384 retval = security_task_getsid(p);
1386 retval = p->signal->session;
1388 read_unlock(&tasklist_lock);
1393 asmlinkage long sys_setsid(void)
1395 struct task_struct *group_leader = current->group_leader;
1399 write_lock_irq(&tasklist_lock);
1401 /* Fail if I am already a session leader */
1402 if (group_leader->signal->leader)
1405 session = group_leader->pid;
1406 /* Fail if a process group id already exists that equals the
1407 * proposed session id.
1409 * Don't check if session id == 1 because kernel threads use this
1410 * session id and so the check will always fail and make it so
1411 * init cannot successfully call setsid.
1413 if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
1416 group_leader->signal->leader = 1;
1417 __set_special_pids(session, session);
1419 spin_lock(&group_leader->sighand->siglock);
1420 group_leader->signal->tty = NULL;
1421 group_leader->signal->tty_old_pgrp = 0;
1422 spin_unlock(&group_leader->sighand->siglock);
1424 err = process_group(group_leader);
1426 write_unlock_irq(&tasklist_lock);
1431 * Supplementary group IDs
1434 /* init to 2 - one for init_task, one to ensure it is never freed */
1435 struct group_info init_groups = { .usage = ATOMIC_INIT(2) };
1437 struct group_info *groups_alloc(int gidsetsize)
1439 struct group_info *group_info;
1443 nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
1444 /* Make sure we always allocate at least one indirect block pointer */
1445 nblocks = nblocks ? : 1;
1446 group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);
1449 group_info->ngroups = gidsetsize;
1450 group_info->nblocks = nblocks;
1451 atomic_set(&group_info->usage, 1);
1453 if (gidsetsize <= NGROUPS_SMALL) {
1454 group_info->blocks[0] = group_info->small_block;
1456 for (i = 0; i < nblocks; i++) {
1458 b = (void *)__get_free_page(GFP_USER);
1460 goto out_undo_partial_alloc;
1461 group_info->blocks[i] = b;
1466 out_undo_partial_alloc:
1468 free_page((unsigned long)group_info->blocks[i]);
1474 EXPORT_SYMBOL(groups_alloc);
1476 void groups_free(struct group_info *group_info)
1478 if (group_info->blocks[0] != group_info->small_block) {
1480 for (i = 0; i < group_info->nblocks; i++)
1481 free_page((unsigned long)group_info->blocks[i]);
1486 EXPORT_SYMBOL(groups_free);
1488 /* export the group_info to a user-space array */
1489 static int groups_to_user(gid_t __user *grouplist,
1490 struct group_info *group_info)
1493 int count = group_info->ngroups;
1495 for (i = 0; i < group_info->nblocks; i++) {
1496 int cp_count = min(NGROUPS_PER_BLOCK, count);
1497 int off = i * NGROUPS_PER_BLOCK;
1498 int len = cp_count * sizeof(*grouplist);
1500 if (copy_to_user(grouplist+off, group_info->blocks[i], len))
1508 /* fill a group_info from a user-space array - it must be allocated already */
1509 static int groups_from_user(struct group_info *group_info,
1510 gid_t __user *grouplist)
1513 int count = group_info->ngroups;
1515 for (i = 0; i < group_info->nblocks; i++) {
1516 int cp_count = min(NGROUPS_PER_BLOCK, count);
1517 int off = i * NGROUPS_PER_BLOCK;
1518 int len = cp_count * sizeof(*grouplist);
1520 if (copy_from_user(group_info->blocks[i], grouplist+off, len))
1528 /* a simple Shell sort */
1529 static void groups_sort(struct group_info *group_info)
1531 int base, max, stride;
1532 int gidsetsize = group_info->ngroups;
1534 for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
1539 max = gidsetsize - stride;
1540 for (base = 0; base < max; base++) {
1542 int right = left + stride;
1543 gid_t tmp = GROUP_AT(group_info, right);
1545 while (left >= 0 && GROUP_AT(group_info, left) > tmp) {
1546 GROUP_AT(group_info, right) =
1547 GROUP_AT(group_info, left);
1551 GROUP_AT(group_info, right) = tmp;
1557 /* a simple bsearch */
1558 int groups_search(struct group_info *group_info, gid_t grp)
1560 unsigned int left, right;
1566 right = group_info->ngroups;
1567 while (left < right) {
1568 unsigned int mid = (left+right)/2;
1569 int cmp = grp - GROUP_AT(group_info, mid);
1580 /* validate and set current->group_info */
1581 int set_current_groups(struct group_info *group_info)
1584 struct group_info *old_info;
1586 retval = security_task_setgroups(group_info);
1590 groups_sort(group_info);
1591 get_group_info(group_info);
1594 old_info = current->group_info;
1595 current->group_info = group_info;
1596 task_unlock(current);
1598 put_group_info(old_info);
1603 EXPORT_SYMBOL(set_current_groups);
1605 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1610 * SMP: Nobody else can change our grouplist. Thus we are
1617 /* no need to grab task_lock here; it cannot change */
1618 i = current->group_info->ngroups;
1620 if (i > gidsetsize) {
1624 if (groups_to_user(grouplist, current->group_info)) {
1634 * SMP: Our groups are copy-on-write. We can set them safely
1635 * without another task interfering.
1638 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1640 struct group_info *group_info;
1643 if (!capable(CAP_SETGID))
1645 if ((unsigned)gidsetsize > NGROUPS_MAX)
1648 group_info = groups_alloc(gidsetsize);
1651 retval = groups_from_user(group_info, grouplist);
1653 put_group_info(group_info);
1657 retval = set_current_groups(group_info);
1658 put_group_info(group_info);
1664 * Check whether we're fsgid/egid or in the supplemental group..
1666 int in_group_p(gid_t grp)
1669 if (grp != current->fsgid) {
1670 retval = groups_search(current->group_info, grp);
1675 EXPORT_SYMBOL(in_group_p);
1677 int in_egroup_p(gid_t grp)
1680 if (grp != current->egid) {
1681 retval = groups_search(current->group_info, grp);
1686 EXPORT_SYMBOL(in_egroup_p);
1688 DECLARE_RWSEM(uts_sem);
1690 EXPORT_SYMBOL(uts_sem);
1692 asmlinkage long sys_newuname(struct new_utsname __user * name)
1696 down_read(&uts_sem);
1697 if (copy_to_user(name, vx_new_utsname(), sizeof *name))
1703 asmlinkage long sys_sethostname(char __user *name, int len)
1706 char tmp[__NEW_UTS_LEN];
1708 if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
1710 if (len < 0 || len > __NEW_UTS_LEN)
1712 down_write(&uts_sem);
1714 if (!copy_from_user(tmp, name, len)) {
1715 char *ptr = vx_new_uts(nodename);
1717 memcpy(ptr, tmp, len);
1725 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1727 asmlinkage long sys_gethostname(char __user *name, int len)
1734 down_read(&uts_sem);
1735 ptr = vx_new_uts(nodename);
1736 i = 1 + strlen(ptr);
1740 if (copy_to_user(name, ptr, i))
1749 * Only setdomainname; getdomainname can be implemented by calling
1752 asmlinkage long sys_setdomainname(char __user *name, int len)
1755 char tmp[__NEW_UTS_LEN];
1757 if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
1759 if (len < 0 || len > __NEW_UTS_LEN)
1762 down_write(&uts_sem);
1764 if (!copy_from_user(tmp, name, len)) {
1765 char *ptr = vx_new_uts(domainname);
1767 memcpy(ptr, tmp, len);
1775 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1777 if (resource >= RLIM_NLIMITS)
1780 struct rlimit value;
1781 task_lock(current->group_leader);
1782 value = current->signal->rlim[resource];
1783 task_unlock(current->group_leader);
1784 return copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
1788 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1791 * Back compatibility for getrlimit. Needed for some apps.
1794 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1797 if (resource >= RLIM_NLIMITS)
1800 task_lock(current->group_leader);
1801 x = current->signal->rlim[resource];
1802 task_unlock(current->group_leader);
1803 if(x.rlim_cur > 0x7FFFFFFF)
1804 x.rlim_cur = 0x7FFFFFFF;
1805 if(x.rlim_max > 0x7FFFFFFF)
1806 x.rlim_max = 0x7FFFFFFF;
1807 return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1812 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1814 struct rlimit new_rlim, *old_rlim;
1815 unsigned long it_prof_secs;
1818 if (resource >= RLIM_NLIMITS)
1820 if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1822 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1824 old_rlim = current->signal->rlim + resource;
1825 if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
1826 !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
1828 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
1831 retval = security_task_setrlimit(resource, &new_rlim);
1835 task_lock(current->group_leader);
1836 *old_rlim = new_rlim;
1837 task_unlock(current->group_leader);
1839 if (resource != RLIMIT_CPU)
1843 * RLIMIT_CPU handling. Note that the kernel fails to return an error
1844 * code if it rejected the user's attempt to set RLIMIT_CPU. This is a
1845 * very long-standing error, and fixing it now risks breakage of
1846 * applications, so we live with it
1848 if (new_rlim.rlim_cur == RLIM_INFINITY)
1851 it_prof_secs = cputime_to_secs(current->signal->it_prof_expires);
1852 if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) {
1853 unsigned long rlim_cur = new_rlim.rlim_cur;
1856 if (rlim_cur == 0) {
1858 * The caller is asking for an immediate RLIMIT_CPU
1859 * expiry. But we use the zero value to mean "it was
1860 * never set". So let's cheat and make it one second
1865 cputime = secs_to_cputime(rlim_cur);
1866 read_lock(&tasklist_lock);
1867 spin_lock_irq(¤t->sighand->siglock);
1868 set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
1869 spin_unlock_irq(¤t->sighand->siglock);
1870 read_unlock(&tasklist_lock);
1877 * It would make sense to put struct rusage in the task_struct,
1878 * except that would make the task_struct be *really big*. After
1879 * task_struct gets moved into malloc'ed memory, it would
1880 * make sense to do this. It will make moving the rest of the information
1881 * a lot simpler! (Which we're not doing right now because we're not
1882 * measuring them yet).
1884 * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
1885 * races with threads incrementing their own counters. But since word
1886 * reads are atomic, we either get new values or old values and we don't
1887 * care which for the sums. We always take the siglock to protect reading
1888 * the c* fields from p->signal from races with exit.c updating those
1889 * fields when reaping, so a sample either gets all the additions of a
1890 * given child after it's reaped, or none so this sample is before reaping.
1893 * We need to take the siglock for CHILDEREN, SELF and BOTH
1894 * for the cases current multithreaded, non-current single threaded
1895 * non-current multithreaded. Thread traversal is now safe with
1897 * Strictly speaking, we donot need to take the siglock if we are current and
1898 * single threaded, as no one else can take our signal_struct away, no one
1899 * else can reap the children to update signal->c* counters, and no one else
1900 * can race with the signal-> fields. If we do not take any lock, the
1901 * signal-> fields could be read out of order while another thread was just
1902 * exiting. So we should place a read memory barrier when we avoid the lock.
1903 * On the writer side, write memory barrier is implied in __exit_signal
1904 * as __exit_signal releases the siglock spinlock after updating the signal->
1905 * fields. But we don't do this yet to keep things simple.
1909 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1911 struct task_struct *t;
1912 unsigned long flags;
1913 cputime_t utime, stime;
1915 memset((char *) r, 0, sizeof *r);
1916 utime = stime = cputime_zero;
1919 if (!lock_task_sighand(p, &flags)) {
1926 case RUSAGE_CHILDREN:
1927 utime = p->signal->cutime;
1928 stime = p->signal->cstime;
1929 r->ru_nvcsw = p->signal->cnvcsw;
1930 r->ru_nivcsw = p->signal->cnivcsw;
1931 r->ru_minflt = p->signal->cmin_flt;
1932 r->ru_majflt = p->signal->cmaj_flt;
1934 if (who == RUSAGE_CHILDREN)
1938 utime = cputime_add(utime, p->signal->utime);
1939 stime = cputime_add(stime, p->signal->stime);
1940 r->ru_nvcsw += p->signal->nvcsw;
1941 r->ru_nivcsw += p->signal->nivcsw;
1942 r->ru_minflt += p->signal->min_flt;
1943 r->ru_majflt += p->signal->maj_flt;
1946 utime = cputime_add(utime, t->utime);
1947 stime = cputime_add(stime, t->stime);
1948 r->ru_nvcsw += t->nvcsw;
1949 r->ru_nivcsw += t->nivcsw;
1950 r->ru_minflt += t->min_flt;
1951 r->ru_majflt += t->maj_flt;
1960 unlock_task_sighand(p, &flags);
1963 cputime_to_timeval(utime, &r->ru_utime);
1964 cputime_to_timeval(stime, &r->ru_stime);
1967 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1970 k_getrusage(p, who, &r);
1971 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1974 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1976 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1978 return getrusage(current, who, ru);
1981 asmlinkage long sys_umask(int mask)
1983 mask = xchg(¤t->fs->umask, mask & S_IRWXUGO);
1987 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1988 unsigned long arg4, unsigned long arg5)
1992 error = security_task_prctl(option, arg2, arg3, arg4, arg5);
1997 case PR_SET_PDEATHSIG:
1998 if (!valid_signal(arg2)) {
2002 current->pdeath_signal = arg2;
2004 case PR_GET_PDEATHSIG:
2005 error = put_user(current->pdeath_signal, (int __user *)arg2);
2007 case PR_GET_DUMPABLE:
2008 error = current->mm->dumpable;
2010 case PR_SET_DUMPABLE:
2011 if (arg2 < 0 || arg2 > 1) {
2015 current->mm->dumpable = arg2;
2018 case PR_SET_UNALIGN:
2019 error = SET_UNALIGN_CTL(current, arg2);
2021 case PR_GET_UNALIGN:
2022 error = GET_UNALIGN_CTL(current, arg2);
2025 error = SET_FPEMU_CTL(current, arg2);
2028 error = GET_FPEMU_CTL(current, arg2);
2031 error = SET_FPEXC_CTL(current, arg2);
2034 error = GET_FPEXC_CTL(current, arg2);
2037 error = PR_TIMING_STATISTICAL;
2040 if (arg2 == PR_TIMING_STATISTICAL)
2046 case PR_GET_KEEPCAPS:
2047 if (current->keep_capabilities)
2050 case PR_SET_KEEPCAPS:
2051 if (arg2 != 0 && arg2 != 1) {
2055 current->keep_capabilities = arg2;
2058 struct task_struct *me = current;
2059 unsigned char ncomm[sizeof(me->comm)];
2061 ncomm[sizeof(me->comm)-1] = 0;
2062 if (strncpy_from_user(ncomm, (char __user *)arg2,
2063 sizeof(me->comm)-1) < 0)
2065 set_task_comm(me, ncomm);
2069 struct task_struct *me = current;
2070 unsigned char tcomm[sizeof(me->comm)];
2072 get_task_comm(tcomm, me);
2073 if (copy_to_user((char __user *)arg2, tcomm, sizeof(tcomm)))
2078 error = GET_ENDIAN(current, arg2);
2081 error = SET_ENDIAN(current, arg2);