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)
61 # define GET_ENDIAN(a,b) (-EINVAL)
64 # define SET_ENDIAN(a,b) (-EINVAL)
68 * this is where the system-wide overflow UID and GID are defined, for
69 * architectures that now have 32-bit UID/GID but didn't in the past
72 int overflowuid = DEFAULT_OVERFLOWUID;
73 int overflowgid = DEFAULT_OVERFLOWGID;
76 EXPORT_SYMBOL(overflowuid);
77 EXPORT_SYMBOL(overflowgid);
81 * the same as above, but for filesystems which can only store a 16-bit
82 * UID and GID. as such, this is needed on all architectures
85 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
86 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
88 EXPORT_SYMBOL(fs_overflowuid);
89 EXPORT_SYMBOL(fs_overflowgid);
92 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
99 * Notifier list for kernel code which wants to be called
100 * at shutdown. This is used to stop any idling DMA operations
104 static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
107 * Notifier chain core routines. The exported routines below
108 * are layered on top of these, with appropriate locking added.
111 static int notifier_chain_register(struct notifier_block **nl,
112 struct notifier_block *n)
114 while ((*nl) != NULL) {
115 if (n->priority > (*nl)->priority)
120 rcu_assign_pointer(*nl, n);
124 static int notifier_chain_unregister(struct notifier_block **nl,
125 struct notifier_block *n)
127 while ((*nl) != NULL) {
129 rcu_assign_pointer(*nl, n->next);
137 static int __kprobes notifier_call_chain(struct notifier_block **nl,
138 unsigned long val, void *v)
140 int ret = NOTIFY_DONE;
141 struct notifier_block *nb;
143 nb = rcu_dereference(*nl);
145 ret = nb->notifier_call(nb, val, v);
146 if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
148 nb = rcu_dereference(nb->next);
154 * Atomic notifier chain routines. Registration and unregistration
155 * use a mutex, and call_chain is synchronized by RCU (no locks).
159 * atomic_notifier_chain_register - Add notifier to an atomic notifier chain
160 * @nh: Pointer to head of the atomic notifier chain
161 * @n: New entry in notifier chain
163 * Adds a notifier to an atomic notifier chain.
165 * Currently always returns zero.
168 int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
169 struct notifier_block *n)
174 spin_lock_irqsave(&nh->lock, flags);
175 ret = notifier_chain_register(&nh->head, n);
176 spin_unlock_irqrestore(&nh->lock, flags);
180 EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
183 * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain
184 * @nh: Pointer to head of the atomic notifier chain
185 * @n: Entry to remove from notifier chain
187 * Removes a notifier from an atomic notifier chain.
189 * Returns zero on success or %-ENOENT on failure.
191 int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
192 struct notifier_block *n)
197 spin_lock_irqsave(&nh->lock, flags);
198 ret = notifier_chain_unregister(&nh->head, n);
199 spin_unlock_irqrestore(&nh->lock, flags);
204 EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
207 * atomic_notifier_call_chain - Call functions in an atomic notifier chain
208 * @nh: Pointer to head of the atomic notifier chain
209 * @val: Value passed unmodified to notifier function
210 * @v: Pointer passed unmodified to notifier function
212 * Calls each function in a notifier chain in turn. The functions
213 * run in an atomic context, so they must not block.
214 * This routine uses RCU to synchronize with changes to the chain.
216 * If the return value of the notifier can be and'ed
217 * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain
218 * will return immediately, with the return value of
219 * the notifier function which halted execution.
220 * Otherwise the return value is the return value
221 * of the last notifier function called.
224 int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
225 unsigned long val, void *v)
230 ret = notifier_call_chain(&nh->head, val, v);
235 EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
238 * Blocking notifier chain routines. All access to the chain is
239 * synchronized by an rwsem.
243 * blocking_notifier_chain_register - Add notifier to a blocking notifier chain
244 * @nh: Pointer to head of the blocking notifier chain
245 * @n: New entry in notifier chain
247 * Adds a notifier to a blocking notifier chain.
248 * Must be called in process context.
250 * Currently always returns zero.
253 int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
254 struct notifier_block *n)
259 * This code gets used during boot-up, when task switching is
260 * not yet working and interrupts must remain disabled. At
261 * such times we must not call down_write().
263 if (unlikely(system_state == SYSTEM_BOOTING))
264 return notifier_chain_register(&nh->head, n);
266 down_write(&nh->rwsem);
267 ret = notifier_chain_register(&nh->head, n);
268 up_write(&nh->rwsem);
272 EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
275 * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
276 * @nh: Pointer to head of the blocking notifier chain
277 * @n: Entry to remove from notifier chain
279 * Removes a notifier from a blocking notifier chain.
280 * Must be called from process context.
282 * Returns zero on success or %-ENOENT on failure.
284 int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
285 struct notifier_block *n)
290 * This code gets used during boot-up, when task switching is
291 * not yet working and interrupts must remain disabled. At
292 * such times we must not call down_write().
294 if (unlikely(system_state == SYSTEM_BOOTING))
295 return notifier_chain_unregister(&nh->head, n);
297 down_write(&nh->rwsem);
298 ret = notifier_chain_unregister(&nh->head, n);
299 up_write(&nh->rwsem);
303 EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
306 * blocking_notifier_call_chain - Call functions in a blocking notifier chain
307 * @nh: Pointer to head of the blocking notifier chain
308 * @val: Value passed unmodified to notifier function
309 * @v: Pointer passed unmodified to notifier function
311 * Calls each function in a notifier chain in turn. The functions
312 * run in a process context, so they are allowed to block.
314 * If the return value of the notifier can be and'ed
315 * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain
316 * will return immediately, with the return value of
317 * the notifier function which halted execution.
318 * Otherwise the return value is the return value
319 * of the last notifier function called.
322 int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
323 unsigned long val, void *v)
327 down_read(&nh->rwsem);
328 ret = notifier_call_chain(&nh->head, val, v);
333 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
336 * Raw notifier chain routines. There is no protection;
337 * the caller must provide it. Use at your own risk!
341 * raw_notifier_chain_register - Add notifier to a raw notifier chain
342 * @nh: Pointer to head of the raw notifier chain
343 * @n: New entry in notifier chain
345 * Adds a notifier to a raw notifier chain.
346 * All locking must be provided by the caller.
348 * Currently always returns zero.
351 int raw_notifier_chain_register(struct raw_notifier_head *nh,
352 struct notifier_block *n)
354 return notifier_chain_register(&nh->head, n);
357 EXPORT_SYMBOL_GPL(raw_notifier_chain_register);
360 * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain
361 * @nh: Pointer to head of the raw notifier chain
362 * @n: Entry to remove from notifier chain
364 * Removes a notifier from a raw notifier chain.
365 * All locking must be provided by the caller.
367 * Returns zero on success or %-ENOENT on failure.
369 int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
370 struct notifier_block *n)
372 return notifier_chain_unregister(&nh->head, n);
375 EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
378 * raw_notifier_call_chain - Call functions in a raw notifier chain
379 * @nh: Pointer to head of the raw notifier chain
380 * @val: Value passed unmodified to notifier function
381 * @v: Pointer passed unmodified to notifier function
383 * Calls each function in a notifier chain in turn. The functions
384 * run in an undefined context.
385 * All locking must be provided by the caller.
387 * If the return value of the notifier can be and'ed
388 * with %NOTIFY_STOP_MASK then raw_notifier_call_chain
389 * will return immediately, with the return value of
390 * the notifier function which halted execution.
391 * Otherwise the return value is the return value
392 * of the last notifier function called.
395 int raw_notifier_call_chain(struct raw_notifier_head *nh,
396 unsigned long val, void *v)
398 return notifier_call_chain(&nh->head, val, v);
401 EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
404 * register_reboot_notifier - Register function to be called at reboot time
405 * @nb: Info about notifier function to be called
407 * Registers a function with the list of functions
408 * to be called at reboot time.
410 * Currently always returns zero, as blocking_notifier_chain_register
411 * always returns zero.
414 int register_reboot_notifier(struct notifier_block * nb)
416 return blocking_notifier_chain_register(&reboot_notifier_list, nb);
419 EXPORT_SYMBOL(register_reboot_notifier);
422 * unregister_reboot_notifier - Unregister previously registered reboot notifier
423 * @nb: Hook to be unregistered
425 * Unregisters a previously registered reboot
428 * Returns zero on success, or %-ENOENT on failure.
431 int unregister_reboot_notifier(struct notifier_block * nb)
433 return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
436 EXPORT_SYMBOL(unregister_reboot_notifier);
438 static int set_one_prio(struct task_struct *p, int niceval, int error)
442 if (p->uid != current->euid &&
443 p->euid != current->euid && !capable(CAP_SYS_NICE)) {
447 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
451 no_nice = security_task_setnice(p, niceval);
458 set_user_nice(p, niceval);
463 asmlinkage long sys_setpriority(int which, int who, int niceval)
465 struct task_struct *g, *p;
466 struct user_struct *user;
469 if (which > 2 || which < 0)
472 /* normalize: avoid signed division (rounding problems) */
479 read_lock(&tasklist_lock);
484 p = find_task_by_pid(who);
486 error = set_one_prio(p, niceval, error);
490 who = process_group(current);
491 do_each_task_pid(who, PIDTYPE_PGID, p) {
492 error = set_one_prio(p, niceval, error);
493 } while_each_task_pid(who, PIDTYPE_PGID, p);
496 user = current->user;
500 if ((who != current->uid) && !(user = find_user(who)))
501 goto out_unlock; /* No processes for this user */
505 error = set_one_prio(p, niceval, error);
506 while_each_thread(g, p);
507 if (who != current->uid)
508 free_uid(user); /* For find_user() */
512 read_unlock(&tasklist_lock);
518 * Ugh. To avoid negative return values, "getpriority()" will
519 * not return the normal nice-value, but a negated value that
520 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
521 * to stay compatible.
523 asmlinkage long sys_getpriority(int which, int who)
525 struct task_struct *g, *p;
526 struct user_struct *user;
527 long niceval, retval = -ESRCH;
529 if (which > 2 || which < 0)
532 read_lock(&tasklist_lock);
537 p = find_task_by_pid(who);
539 niceval = 20 - task_nice(p);
540 if (niceval > retval)
546 who = process_group(current);
547 do_each_task_pid(who, PIDTYPE_PGID, p) {
548 niceval = 20 - task_nice(p);
549 if (niceval > retval)
551 } while_each_task_pid(who, PIDTYPE_PGID, p);
554 user = current->user;
558 if ((who != current->uid) && !(user = find_user(who)))
559 goto out_unlock; /* No processes for this user */
563 niceval = 20 - task_nice(p);
564 if (niceval > retval)
567 while_each_thread(g, p);
568 if (who != current->uid)
569 free_uid(user); /* for find_user() */
573 read_unlock(&tasklist_lock);
579 * emergency_restart - reboot the system
581 * Without shutting down any hardware or taking any locks
582 * reboot the system. This is called when we know we are in
583 * trouble so this is our best effort to reboot. This is
584 * safe to call in interrupt context.
586 void emergency_restart(void)
588 machine_emergency_restart();
590 EXPORT_SYMBOL_GPL(emergency_restart);
592 void kernel_restart_prepare(char *cmd)
594 blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
595 system_state = SYSTEM_RESTART;
600 * kernel_restart - reboot the system
601 * @cmd: pointer to buffer containing command to execute for restart
604 * Shutdown everything and perform a clean reboot.
605 * This is not safe to call in interrupt context.
607 void kernel_restart(char *cmd)
609 kernel_restart_prepare(cmd);
611 printk(KERN_EMERG "Restarting system.\n");
613 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
616 machine_restart(cmd);
618 EXPORT_SYMBOL_GPL(kernel_restart);
621 * kernel_kexec - reboot the system
623 * Move into place and start executing a preloaded standalone
624 * executable. If nothing was preloaded return an error.
626 void kernel_kexec(void)
629 struct kimage *image;
630 image = xchg(&kexec_image, NULL);
634 kernel_restart_prepare(NULL);
635 printk(KERN_EMERG "Starting new kernel\n");
637 machine_kexec(image);
640 EXPORT_SYMBOL_GPL(kernel_kexec);
642 void kernel_shutdown_prepare(enum system_states state)
644 blocking_notifier_call_chain(&reboot_notifier_list,
645 (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
646 system_state = state;
650 * kernel_halt - halt the system
652 * Shutdown everything and perform a clean system halt.
654 void kernel_halt(void)
656 kernel_shutdown_prepare(SYSTEM_HALT);
657 printk(KERN_EMERG "System halted.\n");
661 EXPORT_SYMBOL_GPL(kernel_halt);
664 * kernel_power_off - power_off the system
666 * Shutdown everything and perform a clean system power_off.
668 void kernel_power_off(void)
670 kernel_shutdown_prepare(SYSTEM_POWER_OFF);
671 printk(KERN_EMERG "Power down.\n");
674 EXPORT_SYMBOL_GPL(kernel_power_off);
676 * Reboot system call: for obvious reasons only root may call it,
677 * and even root needs to set up some magic numbers in the registers
678 * so that some mistake won't make this reboot the whole machine.
679 * You can also set the meaning of the ctrl-alt-del-key here.
681 * reboot doesn't sync: do that yourself before calling this.
683 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
687 /* We only trust the superuser with rebooting the system. */
688 if (!capable(CAP_SYS_BOOT))
691 /* For safety, we require "magic" arguments. */
692 if (magic1 != LINUX_REBOOT_MAGIC1 ||
693 (magic2 != LINUX_REBOOT_MAGIC2 &&
694 magic2 != LINUX_REBOOT_MAGIC2A &&
695 magic2 != LINUX_REBOOT_MAGIC2B &&
696 magic2 != LINUX_REBOOT_MAGIC2C))
699 /* Instead of trying to make the power_off code look like
700 * halt when pm_power_off is not set do it the easy way.
702 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
703 cmd = LINUX_REBOOT_CMD_HALT;
707 case LINUX_REBOOT_CMD_RESTART:
708 kernel_restart(NULL);
711 case LINUX_REBOOT_CMD_CAD_ON:
715 case LINUX_REBOOT_CMD_CAD_OFF:
719 case LINUX_REBOOT_CMD_HALT:
725 case LINUX_REBOOT_CMD_POWER_OFF:
731 case LINUX_REBOOT_CMD_RESTART2:
732 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
736 buffer[sizeof(buffer) - 1] = '\0';
738 kernel_restart(buffer);
741 case LINUX_REBOOT_CMD_KEXEC:
746 #ifdef CONFIG_SOFTWARE_SUSPEND
747 case LINUX_REBOOT_CMD_SW_SUSPEND:
749 int ret = software_suspend();
763 static void deferred_cad(void *dummy)
765 kernel_restart(NULL);
769 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
770 * As it's called within an interrupt, it may NOT sync: the only choice
771 * is whether to reboot at once, or just ignore the ctrl-alt-del.
773 void ctrl_alt_del(void)
775 static DECLARE_WORK(cad_work, deferred_cad, NULL);
778 schedule_work(&cad_work);
780 kill_proc(cad_pid, SIGINT, 1);
785 * Unprivileged users may change the real gid to the effective gid
786 * or vice versa. (BSD-style)
788 * If you set the real gid at all, or set the effective gid to a value not
789 * equal to the real gid, then the saved gid is set to the new effective gid.
791 * This makes it possible for a setgid program to completely drop its
792 * privileges, which is often a useful assertion to make when you are doing
793 * a security audit over a program.
795 * The general idea is that a program which uses just setregid() will be
796 * 100% compatible with BSD. A program which uses just setgid() will be
797 * 100% compatible with POSIX with saved IDs.
799 * SMP: There are not races, the GIDs are checked only by filesystem
800 * operations (as far as semantic preservation is concerned).
802 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
804 int old_rgid = current->gid;
805 int old_egid = current->egid;
806 int new_rgid = old_rgid;
807 int new_egid = old_egid;
810 retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
814 if (rgid != (gid_t) -1) {
815 if ((old_rgid == rgid) ||
816 (current->egid==rgid) ||
822 if (egid != (gid_t) -1) {
823 if ((old_rgid == egid) ||
824 (current->egid == egid) ||
825 (current->sgid == egid) ||
832 if (new_egid != old_egid)
834 current->mm->dumpable = suid_dumpable;
837 if (rgid != (gid_t) -1 ||
838 (egid != (gid_t) -1 && egid != old_rgid))
839 current->sgid = new_egid;
840 current->fsgid = new_egid;
841 current->egid = new_egid;
842 current->gid = new_rgid;
843 key_fsgid_changed(current);
844 proc_id_connector(current, PROC_EVENT_GID);
849 * setgid() is implemented like SysV w/ SAVED_IDS
851 * SMP: Same implicit races as above.
853 asmlinkage long sys_setgid(gid_t gid)
855 int old_egid = current->egid;
858 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
862 if (capable(CAP_SETGID))
866 current->mm->dumpable = suid_dumpable;
869 current->gid = current->egid = current->sgid = current->fsgid = gid;
871 else if ((gid == current->gid) || (gid == current->sgid))
875 current->mm->dumpable = suid_dumpable;
878 current->egid = current->fsgid = gid;
883 key_fsgid_changed(current);
884 proc_id_connector(current, PROC_EVENT_GID);
888 static int set_user(uid_t new_ruid, int dumpclear)
890 struct user_struct *new_user;
892 new_user = alloc_uid(new_ruid);
896 if (atomic_read(&new_user->processes) >=
897 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
898 new_user != &root_user) {
903 switch_uid(new_user);
907 current->mm->dumpable = suid_dumpable;
910 current->uid = new_ruid;
915 * Unprivileged users may change the real uid to the effective uid
916 * or vice versa. (BSD-style)
918 * If you set the real uid at all, or set the effective uid to a value not
919 * equal to the real uid, then the saved uid is set to the new effective uid.
921 * This makes it possible for a setuid program to completely drop its
922 * privileges, which is often a useful assertion to make when you are doing
923 * a security audit over a program.
925 * The general idea is that a program which uses just setreuid() will be
926 * 100% compatible with BSD. A program which uses just setuid() will be
927 * 100% compatible with POSIX with saved IDs.
929 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
931 int old_ruid, old_euid, old_suid, new_ruid, new_euid;
934 retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
938 new_ruid = old_ruid = current->uid;
939 new_euid = old_euid = current->euid;
940 old_suid = current->suid;
942 if (ruid != (uid_t) -1) {
944 if ((old_ruid != ruid) &&
945 (current->euid != ruid) &&
946 !capable(CAP_SETUID))
950 if (euid != (uid_t) -1) {
952 if ((old_ruid != euid) &&
953 (current->euid != euid) &&
954 (current->suid != euid) &&
955 !capable(CAP_SETUID))
959 if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
962 if (new_euid != old_euid)
964 current->mm->dumpable = suid_dumpable;
967 current->fsuid = current->euid = new_euid;
968 if (ruid != (uid_t) -1 ||
969 (euid != (uid_t) -1 && euid != old_ruid))
970 current->suid = current->euid;
971 current->fsuid = current->euid;
973 key_fsuid_changed(current);
974 proc_id_connector(current, PROC_EVENT_UID);
976 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
982 * setuid() is implemented like SysV with SAVED_IDS
984 * Note that SAVED_ID's is deficient in that a setuid root program
985 * like sendmail, for example, cannot set its uid to be a normal
986 * user and then switch back, because if you're root, setuid() sets
987 * the saved uid too. If you don't like this, blame the bright people
988 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
989 * will allow a root program to temporarily drop privileges and be able to
990 * regain them by swapping the real and effective uid.
992 asmlinkage long sys_setuid(uid_t uid)
994 int old_euid = current->euid;
995 int old_ruid, old_suid, new_ruid, new_suid;
998 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
1002 old_ruid = new_ruid = current->uid;
1003 old_suid = current->suid;
1004 new_suid = old_suid;
1006 if (capable(CAP_SETUID)) {
1007 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
1010 } else if ((uid != current->uid) && (uid != new_suid))
1013 if (old_euid != uid)
1015 current->mm->dumpable = suid_dumpable;
1018 current->fsuid = current->euid = uid;
1019 current->suid = new_suid;
1021 key_fsuid_changed(current);
1022 proc_id_connector(current, PROC_EVENT_UID);
1024 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
1029 * This function implements a generic ability to update ruid, euid,
1030 * and suid. This allows you to implement the 4.4 compatible seteuid().
1032 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
1034 int old_ruid = current->uid;
1035 int old_euid = current->euid;
1036 int old_suid = current->suid;
1039 retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
1043 if (!capable(CAP_SETUID)) {
1044 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
1045 (ruid != current->euid) && (ruid != current->suid))
1047 if ((euid != (uid_t) -1) && (euid != current->uid) &&
1048 (euid != current->euid) && (euid != current->suid))
1050 if ((suid != (uid_t) -1) && (suid != current->uid) &&
1051 (suid != current->euid) && (suid != current->suid))
1054 if (ruid != (uid_t) -1) {
1055 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
1058 if (euid != (uid_t) -1) {
1059 if (euid != current->euid)
1061 current->mm->dumpable = suid_dumpable;
1064 current->euid = euid;
1066 current->fsuid = current->euid;
1067 if (suid != (uid_t) -1)
1068 current->suid = suid;
1070 key_fsuid_changed(current);
1071 proc_id_connector(current, PROC_EVENT_UID);
1073 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
1076 asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid)
1080 if (!(retval = put_user(current->uid, ruid)) &&
1081 !(retval = put_user(current->euid, euid)))
1082 retval = put_user(current->suid, suid);
1088 * Same as above, but for rgid, egid, sgid.
1090 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
1094 retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
1098 if (!capable(CAP_SETGID)) {
1099 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
1100 (rgid != current->egid) && (rgid != current->sgid))
1102 if ((egid != (gid_t) -1) && (egid != current->gid) &&
1103 (egid != current->egid) && (egid != current->sgid))
1105 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
1106 (sgid != current->egid) && (sgid != current->sgid))
1109 if (egid != (gid_t) -1) {
1110 if (egid != current->egid)
1112 current->mm->dumpable = suid_dumpable;
1115 current->egid = egid;
1117 current->fsgid = current->egid;
1118 if (rgid != (gid_t) -1)
1119 current->gid = rgid;
1120 if (sgid != (gid_t) -1)
1121 current->sgid = sgid;
1123 key_fsgid_changed(current);
1124 proc_id_connector(current, PROC_EVENT_GID);
1128 asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid)
1132 if (!(retval = put_user(current->gid, rgid)) &&
1133 !(retval = put_user(current->egid, egid)))
1134 retval = put_user(current->sgid, sgid);
1141 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
1142 * is used for "access()" and for the NFS daemon (letting nfsd stay at
1143 * whatever uid it wants to). It normally shadows "euid", except when
1144 * explicitly set by setfsuid() or for access..
1146 asmlinkage long sys_setfsuid(uid_t uid)
1150 old_fsuid = current->fsuid;
1151 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
1154 if (uid == current->uid || uid == current->euid ||
1155 uid == current->suid || uid == current->fsuid ||
1156 capable(CAP_SETUID))
1158 if (uid != old_fsuid)
1160 current->mm->dumpable = suid_dumpable;
1163 current->fsuid = uid;
1166 key_fsuid_changed(current);
1167 proc_id_connector(current, PROC_EVENT_UID);
1169 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
1175 * Samma på svenska..
1177 asmlinkage long sys_setfsgid(gid_t gid)
1181 old_fsgid = current->fsgid;
1182 if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
1185 if (gid == current->gid || gid == current->egid ||
1186 gid == current->sgid || gid == current->fsgid ||
1187 capable(CAP_SETGID))
1189 if (gid != old_fsgid)
1191 current->mm->dumpable = suid_dumpable;
1194 current->fsgid = gid;
1195 key_fsgid_changed(current);
1196 proc_id_connector(current, PROC_EVENT_GID);
1201 asmlinkage long sys_times(struct tms __user * tbuf)
1204 * In the SMP world we might just be unlucky and have one of
1205 * the times increment as we use it. Since the value is an
1206 * atomically safe type this is just fine. Conceptually its
1207 * as if the syscall took an instant longer to occur.
1211 struct task_struct *tsk = current;
1212 struct task_struct *t;
1213 cputime_t utime, stime, cutime, cstime;
1215 spin_lock_irq(&tsk->sighand->siglock);
1216 utime = tsk->signal->utime;
1217 stime = tsk->signal->stime;
1220 utime = cputime_add(utime, t->utime);
1221 stime = cputime_add(stime, t->stime);
1225 cutime = tsk->signal->cutime;
1226 cstime = tsk->signal->cstime;
1227 spin_unlock_irq(&tsk->sighand->siglock);
1229 tmp.tms_utime = cputime_to_clock_t(utime);
1230 tmp.tms_stime = cputime_to_clock_t(stime);
1231 tmp.tms_cutime = cputime_to_clock_t(cutime);
1232 tmp.tms_cstime = cputime_to_clock_t(cstime);
1233 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
1236 return (long) jiffies_64_to_clock_t(get_jiffies_64());
1240 * This needs some heavy checking ...
1241 * I just haven't the stomach for it. I also don't fully
1242 * understand sessions/pgrp etc. Let somebody who does explain it.
1244 * OK, I think I have the protection semantics right.... this is really
1245 * only important on a multi-user system anyway, to make sure one user
1246 * can't send a signal to a process owned by another. -TYT, 12/12/91
1248 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
1252 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1254 struct task_struct *p;
1255 struct task_struct *group_leader = current->group_leader;
1259 pid = group_leader->pid;
1265 /* From this point forward we keep holding onto the tasklist lock
1266 * so that our parent does not change from under us. -DaveM
1268 write_lock_irq(&tasklist_lock);
1271 p = find_task_by_pid(pid);
1276 if (!thread_group_leader(p))
1279 if (p->real_parent == group_leader) {
1281 if (p->signal->session != group_leader->signal->session)
1288 if (p != group_leader)
1293 if (p->signal->leader)
1297 struct task_struct *p;
1299 do_each_task_pid(pgid, PIDTYPE_PGID, p) {
1300 if (p->signal->session == group_leader->signal->session)
1302 } while_each_task_pid(pgid, PIDTYPE_PGID, p);
1307 err = security_task_setpgid(p, pgid);
1311 if (process_group(p) != pgid) {
1312 detach_pid(p, PIDTYPE_PGID);
1313 p->signal->pgrp = pgid;
1314 attach_pid(p, PIDTYPE_PGID, pgid);
1319 /* All paths lead to here, thus we are safe. -DaveM */
1320 write_unlock_irq(&tasklist_lock);
1324 asmlinkage long sys_getpgid(pid_t pid)
1327 return process_group(current);
1330 struct task_struct *p;
1332 read_lock(&tasklist_lock);
1333 p = find_task_by_pid(pid);
1337 retval = security_task_getpgid(p);
1339 retval = process_group(p);
1341 read_unlock(&tasklist_lock);
1346 #ifdef __ARCH_WANT_SYS_GETPGRP
1348 asmlinkage long sys_getpgrp(void)
1350 /* SMP - assuming writes are word atomic this is fine */
1351 return process_group(current);
1356 asmlinkage long sys_getsid(pid_t pid)
1359 return current->signal->session;
1362 struct task_struct *p;
1364 read_lock(&tasklist_lock);
1365 p = find_task_by_pid(pid);
1369 retval = security_task_getsid(p);
1371 retval = p->signal->session;
1373 read_unlock(&tasklist_lock);
1378 asmlinkage long sys_setsid(void)
1380 struct task_struct *group_leader = current->group_leader;
1384 mutex_lock(&tty_mutex);
1385 write_lock_irq(&tasklist_lock);
1387 /* Fail if I am already a session leader */
1388 if (group_leader->signal->leader)
1391 session = group_leader->pid;
1392 /* Fail if a process group id already exists that equals the
1393 * proposed session id.
1395 * Don't check if session id == 1 because kernel threads use this
1396 * session id and so the check will always fail and make it so
1397 * init cannot successfully call setsid.
1399 if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
1402 group_leader->signal->leader = 1;
1403 __set_special_pids(session, session);
1404 group_leader->signal->tty = NULL;
1405 group_leader->signal->tty_old_pgrp = 0;
1406 err = process_group(group_leader);
1408 write_unlock_irq(&tasklist_lock);
1409 mutex_unlock(&tty_mutex);
1414 * Supplementary group IDs
1417 /* init to 2 - one for init_task, one to ensure it is never freed */
1418 struct group_info init_groups = { .usage = ATOMIC_INIT(2) };
1420 struct group_info *groups_alloc(int gidsetsize)
1422 struct group_info *group_info;
1426 nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
1427 /* Make sure we always allocate at least one indirect block pointer */
1428 nblocks = nblocks ? : 1;
1429 group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);
1432 group_info->ngroups = gidsetsize;
1433 group_info->nblocks = nblocks;
1434 atomic_set(&group_info->usage, 1);
1436 if (gidsetsize <= NGROUPS_SMALL) {
1437 group_info->blocks[0] = group_info->small_block;
1439 for (i = 0; i < nblocks; i++) {
1441 b = (void *)__get_free_page(GFP_USER);
1443 goto out_undo_partial_alloc;
1444 group_info->blocks[i] = b;
1449 out_undo_partial_alloc:
1451 free_page((unsigned long)group_info->blocks[i]);
1457 EXPORT_SYMBOL(groups_alloc);
1459 void groups_free(struct group_info *group_info)
1461 if (group_info->blocks[0] != group_info->small_block) {
1463 for (i = 0; i < group_info->nblocks; i++)
1464 free_page((unsigned long)group_info->blocks[i]);
1469 EXPORT_SYMBOL(groups_free);
1471 /* export the group_info to a user-space array */
1472 static int groups_to_user(gid_t __user *grouplist,
1473 struct group_info *group_info)
1476 int count = group_info->ngroups;
1478 for (i = 0; i < group_info->nblocks; i++) {
1479 int cp_count = min(NGROUPS_PER_BLOCK, count);
1480 int off = i * NGROUPS_PER_BLOCK;
1481 int len = cp_count * sizeof(*grouplist);
1483 if (copy_to_user(grouplist+off, group_info->blocks[i], len))
1491 /* fill a group_info from a user-space array - it must be allocated already */
1492 static int groups_from_user(struct group_info *group_info,
1493 gid_t __user *grouplist)
1496 int count = group_info->ngroups;
1498 for (i = 0; i < group_info->nblocks; i++) {
1499 int cp_count = min(NGROUPS_PER_BLOCK, count);
1500 int off = i * NGROUPS_PER_BLOCK;
1501 int len = cp_count * sizeof(*grouplist);
1503 if (copy_from_user(group_info->blocks[i], grouplist+off, len))
1511 /* a simple Shell sort */
1512 static void groups_sort(struct group_info *group_info)
1514 int base, max, stride;
1515 int gidsetsize = group_info->ngroups;
1517 for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
1522 max = gidsetsize - stride;
1523 for (base = 0; base < max; base++) {
1525 int right = left + stride;
1526 gid_t tmp = GROUP_AT(group_info, right);
1528 while (left >= 0 && GROUP_AT(group_info, left) > tmp) {
1529 GROUP_AT(group_info, right) =
1530 GROUP_AT(group_info, left);
1534 GROUP_AT(group_info, right) = tmp;
1540 /* a simple bsearch */
1541 int groups_search(struct group_info *group_info, gid_t grp)
1543 unsigned int left, right;
1549 right = group_info->ngroups;
1550 while (left < right) {
1551 unsigned int mid = (left+right)/2;
1552 int cmp = grp - GROUP_AT(group_info, mid);
1563 /* validate and set current->group_info */
1564 int set_current_groups(struct group_info *group_info)
1567 struct group_info *old_info;
1569 retval = security_task_setgroups(group_info);
1573 groups_sort(group_info);
1574 get_group_info(group_info);
1577 old_info = current->group_info;
1578 current->group_info = group_info;
1579 task_unlock(current);
1581 put_group_info(old_info);
1586 EXPORT_SYMBOL(set_current_groups);
1588 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1593 * SMP: Nobody else can change our grouplist. Thus we are
1600 /* no need to grab task_lock here; it cannot change */
1601 i = current->group_info->ngroups;
1603 if (i > gidsetsize) {
1607 if (groups_to_user(grouplist, current->group_info)) {
1617 * SMP: Our groups are copy-on-write. We can set them safely
1618 * without another task interfering.
1621 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1623 struct group_info *group_info;
1626 if (!capable(CAP_SETGID))
1628 if ((unsigned)gidsetsize > NGROUPS_MAX)
1631 group_info = groups_alloc(gidsetsize);
1634 retval = groups_from_user(group_info, grouplist);
1636 put_group_info(group_info);
1640 retval = set_current_groups(group_info);
1641 put_group_info(group_info);
1647 * Check whether we're fsgid/egid or in the supplemental group..
1649 int in_group_p(gid_t grp)
1652 if (grp != current->fsgid) {
1653 retval = groups_search(current->group_info, grp);
1658 EXPORT_SYMBOL(in_group_p);
1660 int in_egroup_p(gid_t grp)
1663 if (grp != current->egid) {
1664 retval = groups_search(current->group_info, grp);
1669 EXPORT_SYMBOL(in_egroup_p);
1671 DECLARE_RWSEM(uts_sem);
1673 EXPORT_SYMBOL(uts_sem);
1675 asmlinkage long sys_newuname(struct new_utsname __user * name)
1679 down_read(&uts_sem);
1680 if (copy_to_user(name,&system_utsname,sizeof *name))
1686 asmlinkage long sys_sethostname(char __user *name, int len)
1689 char tmp[__NEW_UTS_LEN];
1691 if (!capable(CAP_SYS_ADMIN))
1693 if (len < 0 || len > __NEW_UTS_LEN)
1695 down_write(&uts_sem);
1697 if (!copy_from_user(tmp, name, len)) {
1698 memcpy(system_utsname.nodename, tmp, len);
1699 system_utsname.nodename[len] = 0;
1706 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1708 asmlinkage long sys_gethostname(char __user *name, int len)
1714 down_read(&uts_sem);
1715 i = 1 + strlen(system_utsname.nodename);
1719 if (copy_to_user(name, system_utsname.nodename, i))
1728 * Only setdomainname; getdomainname can be implemented by calling
1731 asmlinkage long sys_setdomainname(char __user *name, int len)
1734 char tmp[__NEW_UTS_LEN];
1736 if (!capable(CAP_SYS_ADMIN))
1738 if (len < 0 || len > __NEW_UTS_LEN)
1741 down_write(&uts_sem);
1743 if (!copy_from_user(tmp, name, len)) {
1744 memcpy(system_utsname.domainname, tmp, len);
1745 system_utsname.domainname[len] = 0;
1752 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1754 if (resource >= RLIM_NLIMITS)
1757 struct rlimit value;
1758 task_lock(current->group_leader);
1759 value = current->signal->rlim[resource];
1760 task_unlock(current->group_leader);
1761 return copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
1765 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1768 * Back compatibility for getrlimit. Needed for some apps.
1771 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1774 if (resource >= RLIM_NLIMITS)
1777 task_lock(current->group_leader);
1778 x = current->signal->rlim[resource];
1779 task_unlock(current->group_leader);
1780 if(x.rlim_cur > 0x7FFFFFFF)
1781 x.rlim_cur = 0x7FFFFFFF;
1782 if(x.rlim_max > 0x7FFFFFFF)
1783 x.rlim_max = 0x7FFFFFFF;
1784 return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1789 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1791 struct rlimit new_rlim, *old_rlim;
1792 unsigned long it_prof_secs;
1795 if (resource >= RLIM_NLIMITS)
1797 if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1799 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1801 old_rlim = current->signal->rlim + resource;
1802 if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
1803 !capable(CAP_SYS_RESOURCE))
1805 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
1808 retval = security_task_setrlimit(resource, &new_rlim);
1812 task_lock(current->group_leader);
1813 *old_rlim = new_rlim;
1814 task_unlock(current->group_leader);
1816 if (resource != RLIMIT_CPU)
1820 * RLIMIT_CPU handling. Note that the kernel fails to return an error
1821 * code if it rejected the user's attempt to set RLIMIT_CPU. This is a
1822 * very long-standing error, and fixing it now risks breakage of
1823 * applications, so we live with it
1825 if (new_rlim.rlim_cur == RLIM_INFINITY)
1828 it_prof_secs = cputime_to_secs(current->signal->it_prof_expires);
1829 if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) {
1830 unsigned long rlim_cur = new_rlim.rlim_cur;
1833 if (rlim_cur == 0) {
1835 * The caller is asking for an immediate RLIMIT_CPU
1836 * expiry. But we use the zero value to mean "it was
1837 * never set". So let's cheat and make it one second
1842 cputime = secs_to_cputime(rlim_cur);
1843 read_lock(&tasklist_lock);
1844 spin_lock_irq(¤t->sighand->siglock);
1845 set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
1846 spin_unlock_irq(¤t->sighand->siglock);
1847 read_unlock(&tasklist_lock);
1854 * It would make sense to put struct rusage in the task_struct,
1855 * except that would make the task_struct be *really big*. After
1856 * task_struct gets moved into malloc'ed memory, it would
1857 * make sense to do this. It will make moving the rest of the information
1858 * a lot simpler! (Which we're not doing right now because we're not
1859 * measuring them yet).
1861 * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
1862 * races with threads incrementing their own counters. But since word
1863 * reads are atomic, we either get new values or old values and we don't
1864 * care which for the sums. We always take the siglock to protect reading
1865 * the c* fields from p->signal from races with exit.c updating those
1866 * fields when reaping, so a sample either gets all the additions of a
1867 * given child after it's reaped, or none so this sample is before reaping.
1870 * We need to take the siglock for CHILDEREN, SELF and BOTH
1871 * for the cases current multithreaded, non-current single threaded
1872 * non-current multithreaded. Thread traversal is now safe with
1874 * Strictly speaking, we donot need to take the siglock if we are current and
1875 * single threaded, as no one else can take our signal_struct away, no one
1876 * else can reap the children to update signal->c* counters, and no one else
1877 * can race with the signal-> fields. If we do not take any lock, the
1878 * signal-> fields could be read out of order while another thread was just
1879 * exiting. So we should place a read memory barrier when we avoid the lock.
1880 * On the writer side, write memory barrier is implied in __exit_signal
1881 * as __exit_signal releases the siglock spinlock after updating the signal->
1882 * fields. But we don't do this yet to keep things simple.
1886 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1888 struct task_struct *t;
1889 unsigned long flags;
1890 cputime_t utime, stime;
1892 memset((char *) r, 0, sizeof *r);
1893 utime = stime = cputime_zero;
1896 if (!lock_task_sighand(p, &flags)) {
1903 case RUSAGE_CHILDREN:
1904 utime = p->signal->cutime;
1905 stime = p->signal->cstime;
1906 r->ru_nvcsw = p->signal->cnvcsw;
1907 r->ru_nivcsw = p->signal->cnivcsw;
1908 r->ru_minflt = p->signal->cmin_flt;
1909 r->ru_majflt = p->signal->cmaj_flt;
1911 if (who == RUSAGE_CHILDREN)
1915 utime = cputime_add(utime, p->signal->utime);
1916 stime = cputime_add(stime, p->signal->stime);
1917 r->ru_nvcsw += p->signal->nvcsw;
1918 r->ru_nivcsw += p->signal->nivcsw;
1919 r->ru_minflt += p->signal->min_flt;
1920 r->ru_majflt += p->signal->maj_flt;
1923 utime = cputime_add(utime, t->utime);
1924 stime = cputime_add(stime, t->stime);
1925 r->ru_nvcsw += t->nvcsw;
1926 r->ru_nivcsw += t->nivcsw;
1927 r->ru_minflt += t->min_flt;
1928 r->ru_majflt += t->maj_flt;
1937 unlock_task_sighand(p, &flags);
1940 cputime_to_timeval(utime, &r->ru_utime);
1941 cputime_to_timeval(stime, &r->ru_stime);
1944 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1947 k_getrusage(p, who, &r);
1948 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1951 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1953 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1955 return getrusage(current, who, ru);
1958 asmlinkage long sys_umask(int mask)
1960 mask = xchg(¤t->fs->umask, mask & S_IRWXUGO);
1964 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1965 unsigned long arg4, unsigned long arg5)
1969 error = security_task_prctl(option, arg2, arg3, arg4, arg5);
1974 case PR_SET_PDEATHSIG:
1975 if (!valid_signal(arg2)) {
1979 current->pdeath_signal = arg2;
1981 case PR_GET_PDEATHSIG:
1982 error = put_user(current->pdeath_signal, (int __user *)arg2);
1984 case PR_GET_DUMPABLE:
1985 error = current->mm->dumpable;
1987 case PR_SET_DUMPABLE:
1988 if (arg2 < 0 || arg2 > 2) {
1992 current->mm->dumpable = arg2;
1995 case PR_SET_UNALIGN:
1996 error = SET_UNALIGN_CTL(current, arg2);
1998 case PR_GET_UNALIGN:
1999 error = GET_UNALIGN_CTL(current, arg2);
2002 error = SET_FPEMU_CTL(current, arg2);
2005 error = GET_FPEMU_CTL(current, arg2);
2008 error = SET_FPEXC_CTL(current, arg2);
2011 error = GET_FPEXC_CTL(current, arg2);
2014 error = PR_TIMING_STATISTICAL;
2017 if (arg2 == PR_TIMING_STATISTICAL)
2023 case PR_GET_KEEPCAPS:
2024 if (current->keep_capabilities)
2027 case PR_SET_KEEPCAPS:
2028 if (arg2 != 0 && arg2 != 1) {
2032 current->keep_capabilities = arg2;
2035 struct task_struct *me = current;
2036 unsigned char ncomm[sizeof(me->comm)];
2038 ncomm[sizeof(me->comm)-1] = 0;
2039 if (strncpy_from_user(ncomm, (char __user *)arg2,
2040 sizeof(me->comm)-1) < 0)
2042 set_task_comm(me, ncomm);
2046 struct task_struct *me = current;
2047 unsigned char tcomm[sizeof(me->comm)];
2049 get_task_comm(tcomm, me);
2050 if (copy_to_user((char __user *)arg2, tcomm, sizeof(tcomm)))
2055 error = GET_ENDIAN(current, arg2);
2058 error = SET_ENDIAN(current, arg2);