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/kmod.h>
15 #include <linux/reboot.h>
16 #include <linux/prctl.h>
17 #include <linux/init.h>
18 #include <linux/highuid.h>
20 #include <linux/kernel.h>
21 #include <linux/kexec.h>
22 #include <linux/workqueue.h>
23 #include <linux/capability.h>
24 #include <linux/device.h>
25 #include <linux/key.h>
26 #include <linux/times.h>
27 #include <linux/posix-timers.h>
28 #include <linux/security.h>
29 #include <linux/dcookies.h>
30 #include <linux/suspend.h>
31 #include <linux/tty.h>
32 #include <linux/signal.h>
33 #include <linux/cn_proc.h>
34 #include <linux/vs_cvirt.h>
36 #include <linux/compat.h>
37 #include <linux/syscalls.h>
38 #include <linux/kprobes.h>
40 #include <asm/uaccess.h>
42 #include <asm/unistd.h>
44 #ifndef SET_UNALIGN_CTL
45 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
47 #ifndef GET_UNALIGN_CTL
48 # define GET_UNALIGN_CTL(a,b) (-EINVAL)
51 # define SET_FPEMU_CTL(a,b) (-EINVAL)
54 # define GET_FPEMU_CTL(a,b) (-EINVAL)
57 # define SET_FPEXC_CTL(a,b) (-EINVAL)
60 # define GET_FPEXC_CTL(a,b) (-EINVAL)
64 * this is where the system-wide overflow UID and GID are defined, for
65 * architectures that now have 32-bit UID/GID but didn't in the past
68 int overflowuid = DEFAULT_OVERFLOWUID;
69 int overflowgid = DEFAULT_OVERFLOWGID;
72 EXPORT_SYMBOL(overflowuid);
73 EXPORT_SYMBOL(overflowgid);
77 * the same as above, but for filesystems which can only store a 16-bit
78 * UID and GID. as such, this is needed on all architectures
81 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
82 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
84 EXPORT_SYMBOL(fs_overflowuid);
85 EXPORT_SYMBOL(fs_overflowgid);
88 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
95 * Notifier list for kernel code which wants to be called
96 * at shutdown. This is used to stop any idling DMA operations
100 static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
103 * Notifier chain core routines. The exported routines below
104 * are layered on top of these, with appropriate locking added.
107 static int notifier_chain_register(struct notifier_block **nl,
108 struct notifier_block *n)
110 while ((*nl) != NULL) {
111 if (n->priority > (*nl)->priority)
116 rcu_assign_pointer(*nl, n);
120 static int notifier_chain_unregister(struct notifier_block **nl,
121 struct notifier_block *n)
123 while ((*nl) != NULL) {
125 rcu_assign_pointer(*nl, n->next);
133 static int __kprobes notifier_call_chain(struct notifier_block **nl,
134 unsigned long val, void *v)
136 int ret = NOTIFY_DONE;
137 struct notifier_block *nb;
139 nb = rcu_dereference(*nl);
141 ret = nb->notifier_call(nb, val, v);
142 if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
144 nb = rcu_dereference(nb->next);
150 * Atomic notifier chain routines. Registration and unregistration
151 * use a mutex, and call_chain is synchronized by RCU (no locks).
155 * atomic_notifier_chain_register - Add notifier to an atomic notifier chain
156 * @nh: Pointer to head of the atomic notifier chain
157 * @n: New entry in notifier chain
159 * Adds a notifier to an atomic notifier chain.
161 * Currently always returns zero.
164 int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
165 struct notifier_block *n)
170 spin_lock_irqsave(&nh->lock, flags);
171 ret = notifier_chain_register(&nh->head, n);
172 spin_unlock_irqrestore(&nh->lock, flags);
176 EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
179 * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain
180 * @nh: Pointer to head of the atomic notifier chain
181 * @n: Entry to remove from notifier chain
183 * Removes a notifier from an atomic notifier chain.
185 * Returns zero on success or %-ENOENT on failure.
187 int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
188 struct notifier_block *n)
193 spin_lock_irqsave(&nh->lock, flags);
194 ret = notifier_chain_unregister(&nh->head, n);
195 spin_unlock_irqrestore(&nh->lock, flags);
200 EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
203 * atomic_notifier_call_chain - Call functions in an atomic notifier chain
204 * @nh: Pointer to head of the atomic notifier chain
205 * @val: Value passed unmodified to notifier function
206 * @v: Pointer passed unmodified to notifier function
208 * Calls each function in a notifier chain in turn. The functions
209 * run in an atomic context, so they must not block.
210 * This routine uses RCU to synchronize with changes to the chain.
212 * If the return value of the notifier can be and'ed
213 * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain
214 * will return immediately, with the return value of
215 * the notifier function which halted execution.
216 * Otherwise the return value is the return value
217 * of the last notifier function called.
220 int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
221 unsigned long val, void *v)
226 ret = notifier_call_chain(&nh->head, val, v);
231 EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
234 * Blocking notifier chain routines. All access to the chain is
235 * synchronized by an rwsem.
239 * blocking_notifier_chain_register - Add notifier to a blocking notifier chain
240 * @nh: Pointer to head of the blocking notifier chain
241 * @n: New entry in notifier chain
243 * Adds a notifier to a blocking notifier chain.
244 * Must be called in process context.
246 * Currently always returns zero.
249 int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
250 struct notifier_block *n)
255 * This code gets used during boot-up, when task switching is
256 * not yet working and interrupts must remain disabled. At
257 * such times we must not call down_write().
259 if (unlikely(system_state == SYSTEM_BOOTING))
260 return notifier_chain_register(&nh->head, n);
262 down_write(&nh->rwsem);
263 ret = notifier_chain_register(&nh->head, n);
264 up_write(&nh->rwsem);
268 EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
271 * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
272 * @nh: Pointer to head of the blocking notifier chain
273 * @n: Entry to remove from notifier chain
275 * Removes a notifier from a blocking notifier chain.
276 * Must be called from process context.
278 * Returns zero on success or %-ENOENT on failure.
280 int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
281 struct notifier_block *n)
286 * This code gets used during boot-up, when task switching is
287 * not yet working and interrupts must remain disabled. At
288 * such times we must not call down_write().
290 if (unlikely(system_state == SYSTEM_BOOTING))
291 return notifier_chain_unregister(&nh->head, n);
293 down_write(&nh->rwsem);
294 ret = notifier_chain_unregister(&nh->head, n);
295 up_write(&nh->rwsem);
299 EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
302 * blocking_notifier_call_chain - Call functions in a blocking notifier chain
303 * @nh: Pointer to head of the blocking notifier chain
304 * @val: Value passed unmodified to notifier function
305 * @v: Pointer passed unmodified to notifier function
307 * Calls each function in a notifier chain in turn. The functions
308 * run in a process context, so they are allowed to block.
310 * If the return value of the notifier can be and'ed
311 * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain
312 * will return immediately, with the return value of
313 * the notifier function which halted execution.
314 * Otherwise the return value is the return value
315 * of the last notifier function called.
318 int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
319 unsigned long val, void *v)
323 down_read(&nh->rwsem);
324 ret = notifier_call_chain(&nh->head, val, v);
329 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
332 * Raw notifier chain routines. There is no protection;
333 * the caller must provide it. Use at your own risk!
337 * raw_notifier_chain_register - Add notifier to a raw notifier chain
338 * @nh: Pointer to head of the raw notifier chain
339 * @n: New entry in notifier chain
341 * Adds a notifier to a raw notifier chain.
342 * All locking must be provided by the caller.
344 * Currently always returns zero.
347 int raw_notifier_chain_register(struct raw_notifier_head *nh,
348 struct notifier_block *n)
350 return notifier_chain_register(&nh->head, n);
353 EXPORT_SYMBOL_GPL(raw_notifier_chain_register);
356 * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain
357 * @nh: Pointer to head of the raw notifier chain
358 * @n: Entry to remove from notifier chain
360 * Removes a notifier from a raw notifier chain.
361 * All locking must be provided by the caller.
363 * Returns zero on success or %-ENOENT on failure.
365 int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
366 struct notifier_block *n)
368 return notifier_chain_unregister(&nh->head, n);
371 EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
374 * raw_notifier_call_chain - Call functions in a raw notifier chain
375 * @nh: Pointer to head of the raw notifier chain
376 * @val: Value passed unmodified to notifier function
377 * @v: Pointer passed unmodified to notifier function
379 * Calls each function in a notifier chain in turn. The functions
380 * run in an undefined context.
381 * All locking must be provided by the caller.
383 * If the return value of the notifier can be and'ed
384 * with %NOTIFY_STOP_MASK then raw_notifier_call_chain
385 * will return immediately, with the return value of
386 * the notifier function which halted execution.
387 * Otherwise the return value is the return value
388 * of the last notifier function called.
391 int raw_notifier_call_chain(struct raw_notifier_head *nh,
392 unsigned long val, void *v)
394 return notifier_call_chain(&nh->head, val, v);
397 EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
400 * register_reboot_notifier - Register function to be called at reboot time
401 * @nb: Info about notifier function to be called
403 * Registers a function with the list of functions
404 * to be called at reboot time.
406 * Currently always returns zero, as blocking_notifier_chain_register
407 * always returns zero.
410 int register_reboot_notifier(struct notifier_block * nb)
412 return blocking_notifier_chain_register(&reboot_notifier_list, nb);
415 EXPORT_SYMBOL(register_reboot_notifier);
418 * unregister_reboot_notifier - Unregister previously registered reboot notifier
419 * @nb: Hook to be unregistered
421 * Unregisters a previously registered reboot
424 * Returns zero on success, or %-ENOENT on failure.
427 int unregister_reboot_notifier(struct notifier_block * nb)
429 return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
432 EXPORT_SYMBOL(unregister_reboot_notifier);
434 static int set_one_prio(struct task_struct *p, int niceval, int error)
438 if (p->uid != current->euid &&
439 p->euid != current->euid && !capable(CAP_SYS_NICE)) {
443 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
444 if (vx_flags(VXF_IGNEG_NICE, 0))
450 no_nice = security_task_setnice(p, niceval);
457 set_user_nice(p, niceval);
462 asmlinkage long sys_setpriority(int which, int who, int niceval)
464 struct task_struct *g, *p;
465 struct user_struct *user;
468 if (which > 2 || which < 0)
471 /* normalize: avoid signed division (rounding problems) */
478 read_lock(&tasklist_lock);
483 p = find_task_by_pid(who);
485 error = set_one_prio(p, niceval, error);
489 who = process_group(current);
490 do_each_task_pid(who, PIDTYPE_PGID, p) {
491 error = set_one_prio(p, niceval, error);
492 } while_each_task_pid(who, PIDTYPE_PGID, p);
495 user = current->user;
499 if ((who != current->uid) &&
500 !(user = find_user(vx_current_xid(), 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) &&
559 !(user = find_user(vx_current_xid(), who)))
560 goto out_unlock; /* No processes for this user */
564 niceval = 20 - task_nice(p);
565 if (niceval > retval)
568 while_each_thread(g, p);
569 if (who != current->uid)
570 free_uid(user); /* for find_user() */
574 read_unlock(&tasklist_lock);
580 * emergency_restart - reboot the system
582 * Without shutting down any hardware or taking any locks
583 * reboot the system. This is called when we know we are in
584 * trouble so this is our best effort to reboot. This is
585 * safe to call in interrupt context.
587 void emergency_restart(void)
589 machine_emergency_restart();
591 EXPORT_SYMBOL_GPL(emergency_restart);
593 void kernel_restart_prepare(char *cmd)
595 blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
596 system_state = SYSTEM_RESTART;
601 * kernel_restart - reboot the system
602 * @cmd: pointer to buffer containing command to execute for restart
605 * Shutdown everything and perform a clean reboot.
606 * This is not safe to call in interrupt context.
608 void kernel_restart(char *cmd)
610 kernel_restart_prepare(cmd);
612 printk(KERN_EMERG "Restarting system.\n");
614 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
617 machine_restart(cmd);
619 EXPORT_SYMBOL_GPL(kernel_restart);
622 * kernel_kexec - reboot the system
624 * Move into place and start executing a preloaded standalone
625 * executable. If nothing was preloaded return an error.
627 void kernel_kexec(void)
630 struct kimage *image;
631 image = xchg(&kexec_image, NULL);
635 kernel_restart_prepare(NULL);
636 printk(KERN_EMERG "Starting new kernel\n");
638 machine_kexec(image);
641 EXPORT_SYMBOL_GPL(kernel_kexec);
643 void kernel_shutdown_prepare(enum system_states state)
645 blocking_notifier_call_chain(&reboot_notifier_list,
646 (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
647 system_state = state;
651 * kernel_halt - halt the system
653 * Shutdown everything and perform a clean system halt.
655 void kernel_halt(void)
657 kernel_shutdown_prepare(SYSTEM_HALT);
658 printk(KERN_EMERG "System halted.\n");
662 EXPORT_SYMBOL_GPL(kernel_halt);
665 * kernel_power_off - power_off the system
667 * Shutdown everything and perform a clean system power_off.
669 void kernel_power_off(void)
671 kernel_shutdown_prepare(SYSTEM_POWER_OFF);
672 printk(KERN_EMERG "Power down.\n");
675 EXPORT_SYMBOL_GPL(kernel_power_off);
677 long vs_reboot(unsigned int, void __user *);
680 * Reboot system call: for obvious reasons only root may call it,
681 * and even root needs to set up some magic numbers in the registers
682 * so that some mistake won't make this reboot the whole machine.
683 * You can also set the meaning of the ctrl-alt-del-key here.
685 * reboot doesn't sync: do that yourself before calling this.
687 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
691 /* We only trust the superuser with rebooting the system. */
692 if (!capable(CAP_SYS_BOOT))
695 /* For safety, we require "magic" arguments. */
696 if (magic1 != LINUX_REBOOT_MAGIC1 ||
697 (magic2 != LINUX_REBOOT_MAGIC2 &&
698 magic2 != LINUX_REBOOT_MAGIC2A &&
699 magic2 != LINUX_REBOOT_MAGIC2B &&
700 magic2 != LINUX_REBOOT_MAGIC2C))
703 /* Instead of trying to make the power_off code look like
704 * halt when pm_power_off is not set do it the easy way.
706 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
707 cmd = LINUX_REBOOT_CMD_HALT;
709 if (!vx_check(0, VX_ADMIN|VX_WATCH))
710 return vs_reboot(cmd, arg);
714 case LINUX_REBOOT_CMD_RESTART:
715 kernel_restart(NULL);
718 case LINUX_REBOOT_CMD_CAD_ON:
722 case LINUX_REBOOT_CMD_CAD_OFF:
726 case LINUX_REBOOT_CMD_HALT:
732 case LINUX_REBOOT_CMD_POWER_OFF:
738 case LINUX_REBOOT_CMD_RESTART2:
739 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
743 buffer[sizeof(buffer) - 1] = '\0';
745 kernel_restart(buffer);
748 case LINUX_REBOOT_CMD_KEXEC:
753 #ifdef CONFIG_SOFTWARE_SUSPEND
754 case LINUX_REBOOT_CMD_SW_SUSPEND:
756 int ret = software_suspend();
770 static void deferred_cad(void *dummy)
772 kernel_restart(NULL);
776 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
777 * As it's called within an interrupt, it may NOT sync: the only choice
778 * is whether to reboot at once, or just ignore the ctrl-alt-del.
780 void ctrl_alt_del(void)
782 static DECLARE_WORK(cad_work, deferred_cad, NULL);
785 schedule_work(&cad_work);
787 kill_proc(cad_pid, SIGINT, 1);
792 * Unprivileged users may change the real gid to the effective gid
793 * or vice versa. (BSD-style)
795 * If you set the real gid at all, or set the effective gid to a value not
796 * equal to the real gid, then the saved gid is set to the new effective gid.
798 * This makes it possible for a setgid program to completely drop its
799 * privileges, which is often a useful assertion to make when you are doing
800 * a security audit over a program.
802 * The general idea is that a program which uses just setregid() will be
803 * 100% compatible with BSD. A program which uses just setgid() will be
804 * 100% compatible with POSIX with saved IDs.
806 * SMP: There are not races, the GIDs are checked only by filesystem
807 * operations (as far as semantic preservation is concerned).
809 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
811 int old_rgid = current->gid;
812 int old_egid = current->egid;
813 int new_rgid = old_rgid;
814 int new_egid = old_egid;
817 retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
821 if (rgid != (gid_t) -1) {
822 if ((old_rgid == rgid) ||
823 (current->egid==rgid) ||
829 if (egid != (gid_t) -1) {
830 if ((old_rgid == egid) ||
831 (current->egid == egid) ||
832 (current->sgid == egid) ||
839 if (new_egid != old_egid)
841 current->mm->dumpable = suid_dumpable;
844 if (rgid != (gid_t) -1 ||
845 (egid != (gid_t) -1 && egid != old_rgid))
846 current->sgid = new_egid;
847 current->fsgid = new_egid;
848 current->egid = new_egid;
849 current->gid = new_rgid;
850 key_fsgid_changed(current);
851 proc_id_connector(current, PROC_EVENT_GID);
856 * setgid() is implemented like SysV w/ SAVED_IDS
858 * SMP: Same implicit races as above.
860 asmlinkage long sys_setgid(gid_t gid)
862 int old_egid = current->egid;
865 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
869 if (capable(CAP_SETGID))
873 current->mm->dumpable = suid_dumpable;
876 current->gid = current->egid = current->sgid = current->fsgid = gid;
878 else if ((gid == current->gid) || (gid == current->sgid))
882 current->mm->dumpable = suid_dumpable;
885 current->egid = current->fsgid = gid;
890 key_fsgid_changed(current);
891 proc_id_connector(current, PROC_EVENT_GID);
895 static int set_user(uid_t new_ruid, int dumpclear)
897 struct user_struct *new_user;
899 new_user = alloc_uid(vx_current_xid(), new_ruid);
903 if (atomic_read(&new_user->processes) >=
904 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
905 new_user != &root_user) {
910 switch_uid(new_user);
914 current->mm->dumpable = suid_dumpable;
917 current->uid = new_ruid;
922 * Unprivileged users may change the real uid to the effective uid
923 * or vice versa. (BSD-style)
925 * If you set the real uid at all, or set the effective uid to a value not
926 * equal to the real uid, then the saved uid is set to the new effective uid.
928 * This makes it possible for a setuid program to completely drop its
929 * privileges, which is often a useful assertion to make when you are doing
930 * a security audit over a program.
932 * The general idea is that a program which uses just setreuid() will be
933 * 100% compatible with BSD. A program which uses just setuid() will be
934 * 100% compatible with POSIX with saved IDs.
936 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
938 int old_ruid, old_euid, old_suid, new_ruid, new_euid;
941 retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
945 new_ruid = old_ruid = current->uid;
946 new_euid = old_euid = current->euid;
947 old_suid = current->suid;
949 if (ruid != (uid_t) -1) {
951 if ((old_ruid != ruid) &&
952 (current->euid != ruid) &&
953 !capable(CAP_SETUID))
957 if (euid != (uid_t) -1) {
959 if ((old_ruid != euid) &&
960 (current->euid != euid) &&
961 (current->suid != euid) &&
962 !capable(CAP_SETUID))
966 if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
969 if (new_euid != old_euid)
971 current->mm->dumpable = suid_dumpable;
974 current->fsuid = current->euid = new_euid;
975 if (ruid != (uid_t) -1 ||
976 (euid != (uid_t) -1 && euid != old_ruid))
977 current->suid = current->euid;
978 current->fsuid = current->euid;
980 key_fsuid_changed(current);
981 proc_id_connector(current, PROC_EVENT_UID);
983 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
989 * setuid() is implemented like SysV with SAVED_IDS
991 * Note that SAVED_ID's is deficient in that a setuid root program
992 * like sendmail, for example, cannot set its uid to be a normal
993 * user and then switch back, because if you're root, setuid() sets
994 * the saved uid too. If you don't like this, blame the bright people
995 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
996 * will allow a root program to temporarily drop privileges and be able to
997 * regain them by swapping the real and effective uid.
999 asmlinkage long sys_setuid(uid_t uid)
1001 int old_euid = current->euid;
1002 int old_ruid, old_suid, new_ruid, new_suid;
1005 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
1009 old_ruid = new_ruid = current->uid;
1010 old_suid = current->suid;
1011 new_suid = old_suid;
1013 if (capable(CAP_SETUID)) {
1014 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
1017 } else if ((uid != current->uid) && (uid != new_suid))
1020 if (old_euid != uid)
1022 current->mm->dumpable = suid_dumpable;
1025 current->fsuid = current->euid = uid;
1026 current->suid = new_suid;
1028 key_fsuid_changed(current);
1029 proc_id_connector(current, PROC_EVENT_UID);
1031 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
1036 * This function implements a generic ability to update ruid, euid,
1037 * and suid. This allows you to implement the 4.4 compatible seteuid().
1039 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
1041 int old_ruid = current->uid;
1042 int old_euid = current->euid;
1043 int old_suid = current->suid;
1046 retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
1050 if (!capable(CAP_SETUID)) {
1051 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
1052 (ruid != current->euid) && (ruid != current->suid))
1054 if ((euid != (uid_t) -1) && (euid != current->uid) &&
1055 (euid != current->euid) && (euid != current->suid))
1057 if ((suid != (uid_t) -1) && (suid != current->uid) &&
1058 (suid != current->euid) && (suid != current->suid))
1061 if (ruid != (uid_t) -1) {
1062 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
1065 if (euid != (uid_t) -1) {
1066 if (euid != current->euid)
1068 current->mm->dumpable = suid_dumpable;
1071 current->euid = euid;
1073 current->fsuid = current->euid;
1074 if (suid != (uid_t) -1)
1075 current->suid = suid;
1077 key_fsuid_changed(current);
1078 proc_id_connector(current, PROC_EVENT_UID);
1080 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
1083 asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid)
1087 if (!(retval = put_user(current->uid, ruid)) &&
1088 !(retval = put_user(current->euid, euid)))
1089 retval = put_user(current->suid, suid);
1095 * Same as above, but for rgid, egid, sgid.
1097 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
1101 retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
1105 if (!capable(CAP_SETGID)) {
1106 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
1107 (rgid != current->egid) && (rgid != current->sgid))
1109 if ((egid != (gid_t) -1) && (egid != current->gid) &&
1110 (egid != current->egid) && (egid != current->sgid))
1112 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
1113 (sgid != current->egid) && (sgid != current->sgid))
1116 if (egid != (gid_t) -1) {
1117 if (egid != current->egid)
1119 current->mm->dumpable = suid_dumpable;
1122 current->egid = egid;
1124 current->fsgid = current->egid;
1125 if (rgid != (gid_t) -1)
1126 current->gid = rgid;
1127 if (sgid != (gid_t) -1)
1128 current->sgid = sgid;
1130 key_fsgid_changed(current);
1131 proc_id_connector(current, PROC_EVENT_GID);
1135 asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid)
1139 if (!(retval = put_user(current->gid, rgid)) &&
1140 !(retval = put_user(current->egid, egid)))
1141 retval = put_user(current->sgid, sgid);
1148 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
1149 * is used for "access()" and for the NFS daemon (letting nfsd stay at
1150 * whatever uid it wants to). It normally shadows "euid", except when
1151 * explicitly set by setfsuid() or for access..
1153 asmlinkage long sys_setfsuid(uid_t uid)
1157 old_fsuid = current->fsuid;
1158 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
1161 if (uid == current->uid || uid == current->euid ||
1162 uid == current->suid || uid == current->fsuid ||
1163 capable(CAP_SETUID))
1165 if (uid != old_fsuid)
1167 current->mm->dumpable = suid_dumpable;
1170 current->fsuid = uid;
1173 key_fsuid_changed(current);
1174 proc_id_connector(current, PROC_EVENT_UID);
1176 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
1182 * Samma på svenska..
1184 asmlinkage long sys_setfsgid(gid_t gid)
1188 old_fsgid = current->fsgid;
1189 if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
1192 if (gid == current->gid || gid == current->egid ||
1193 gid == current->sgid || gid == current->fsgid ||
1194 capable(CAP_SETGID))
1196 if (gid != old_fsgid)
1198 current->mm->dumpable = suid_dumpable;
1201 current->fsgid = gid;
1202 key_fsgid_changed(current);
1203 proc_id_connector(current, PROC_EVENT_GID);
1208 asmlinkage long sys_times(struct tms __user * tbuf)
1211 * In the SMP world we might just be unlucky and have one of
1212 * the times increment as we use it. Since the value is an
1213 * atomically safe type this is just fine. Conceptually its
1214 * as if the syscall took an instant longer to occur.
1218 struct task_struct *tsk = current;
1219 struct task_struct *t;
1220 cputime_t utime, stime, cutime, cstime;
1222 spin_lock_irq(&tsk->sighand->siglock);
1223 utime = tsk->signal->utime;
1224 stime = tsk->signal->stime;
1227 utime = cputime_add(utime, t->utime);
1228 stime = cputime_add(stime, t->stime);
1232 cutime = tsk->signal->cutime;
1233 cstime = tsk->signal->cstime;
1234 spin_unlock_irq(&tsk->sighand->siglock);
1236 tmp.tms_utime = cputime_to_clock_t(utime);
1237 tmp.tms_stime = cputime_to_clock_t(stime);
1238 tmp.tms_cutime = cputime_to_clock_t(cutime);
1239 tmp.tms_cstime = cputime_to_clock_t(cstime);
1240 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
1243 return (long) jiffies_64_to_clock_t(get_jiffies_64());
1247 * This needs some heavy checking ...
1248 * I just haven't the stomach for it. I also don't fully
1249 * understand sessions/pgrp etc. Let somebody who does explain it.
1251 * OK, I think I have the protection semantics right.... this is really
1252 * only important on a multi-user system anyway, to make sure one user
1253 * can't send a signal to a process owned by another. -TYT, 12/12/91
1255 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
1259 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1261 struct task_struct *p;
1262 struct task_struct *group_leader = current->group_leader;
1267 pid = vx_map_pid(group_leader->pid);
1273 rpgid = vx_rmap_pid(pgid);
1275 /* From this point forward we keep holding onto the tasklist lock
1276 * so that our parent does not change from under us. -DaveM
1278 write_lock_irq(&tasklist_lock);
1281 p = find_task_by_pid(pid);
1286 if (!thread_group_leader(p))
1289 if (p->real_parent == group_leader) {
1291 if (p->signal->session != group_leader->signal->session)
1298 if (p != group_leader)
1303 if (p->signal->leader)
1307 struct task_struct *p;
1309 do_each_task_pid(rpgid, PIDTYPE_PGID, p) {
1310 if (p->signal->session == group_leader->signal->session)
1312 } while_each_task_pid(rpgid, PIDTYPE_PGID, p);
1317 err = security_task_setpgid(p, rpgid);
1321 if (process_group(p) != rpgid) {
1322 detach_pid(p, PIDTYPE_PGID);
1323 p->signal->pgrp = rpgid;
1324 attach_pid(p, PIDTYPE_PGID, rpgid);
1329 /* All paths lead to here, thus we are safe. -DaveM */
1330 write_unlock_irq(&tasklist_lock);
1334 asmlinkage long sys_getpgid(pid_t pid)
1337 return vx_rmap_pid(process_group(current));
1340 struct task_struct *p;
1342 read_lock(&tasklist_lock);
1343 p = find_task_by_pid(pid);
1347 retval = security_task_getpgid(p);
1349 retval = vx_rmap_pid(process_group(p));
1351 read_unlock(&tasklist_lock);
1356 #ifdef __ARCH_WANT_SYS_GETPGRP
1358 asmlinkage long sys_getpgrp(void)
1360 /* SMP - assuming writes are word atomic this is fine */
1361 return process_group(current);
1366 asmlinkage long sys_getsid(pid_t pid)
1369 return current->signal->session;
1372 struct task_struct *p;
1374 read_lock(&tasklist_lock);
1375 p = find_task_by_pid(pid);
1379 retval = security_task_getsid(p);
1381 retval = p->signal->session;
1383 read_unlock(&tasklist_lock);
1388 asmlinkage long sys_setsid(void)
1390 struct task_struct *group_leader = current->group_leader;
1394 mutex_lock(&tty_mutex);
1395 write_lock_irq(&tasklist_lock);
1397 /* Fail if I am already a session leader */
1398 if (group_leader->signal->leader)
1401 session = group_leader->pid;
1402 /* Fail if a process group id already exists that equals the
1403 * proposed session id.
1405 * Don't check if session id == 1 because kernel threads use this
1406 * session id and so the check will always fail and make it so
1407 * init cannot successfully call setsid.
1409 if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
1412 group_leader->signal->leader = 1;
1413 __set_special_pids(session, session);
1414 group_leader->signal->tty = NULL;
1415 group_leader->signal->tty_old_pgrp = 0;
1416 err = process_group(group_leader);
1418 write_unlock_irq(&tasklist_lock);
1419 mutex_unlock(&tty_mutex);
1424 * Supplementary group IDs
1427 /* init to 2 - one for init_task, one to ensure it is never freed */
1428 struct group_info init_groups = { .usage = ATOMIC_INIT(2) };
1430 struct group_info *groups_alloc(int gidsetsize)
1432 struct group_info *group_info;
1436 nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
1437 /* Make sure we always allocate at least one indirect block pointer */
1438 nblocks = nblocks ? : 1;
1439 group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);
1442 group_info->ngroups = gidsetsize;
1443 group_info->nblocks = nblocks;
1444 atomic_set(&group_info->usage, 1);
1446 if (gidsetsize <= NGROUPS_SMALL) {
1447 group_info->blocks[0] = group_info->small_block;
1449 for (i = 0; i < nblocks; i++) {
1451 b = (void *)__get_free_page(GFP_USER);
1453 goto out_undo_partial_alloc;
1454 group_info->blocks[i] = b;
1459 out_undo_partial_alloc:
1461 free_page((unsigned long)group_info->blocks[i]);
1467 EXPORT_SYMBOL(groups_alloc);
1469 void groups_free(struct group_info *group_info)
1471 if (group_info->blocks[0] != group_info->small_block) {
1473 for (i = 0; i < group_info->nblocks; i++)
1474 free_page((unsigned long)group_info->blocks[i]);
1479 EXPORT_SYMBOL(groups_free);
1481 /* export the group_info to a user-space array */
1482 static int groups_to_user(gid_t __user *grouplist,
1483 struct group_info *group_info)
1486 int count = group_info->ngroups;
1488 for (i = 0; i < group_info->nblocks; i++) {
1489 int cp_count = min(NGROUPS_PER_BLOCK, count);
1490 int off = i * NGROUPS_PER_BLOCK;
1491 int len = cp_count * sizeof(*grouplist);
1493 if (copy_to_user(grouplist+off, group_info->blocks[i], len))
1501 /* fill a group_info from a user-space array - it must be allocated already */
1502 static int groups_from_user(struct group_info *group_info,
1503 gid_t __user *grouplist)
1506 int count = group_info->ngroups;
1508 for (i = 0; i < group_info->nblocks; i++) {
1509 int cp_count = min(NGROUPS_PER_BLOCK, count);
1510 int off = i * NGROUPS_PER_BLOCK;
1511 int len = cp_count * sizeof(*grouplist);
1513 if (copy_from_user(group_info->blocks[i], grouplist+off, len))
1521 /* a simple Shell sort */
1522 static void groups_sort(struct group_info *group_info)
1524 int base, max, stride;
1525 int gidsetsize = group_info->ngroups;
1527 for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
1532 max = gidsetsize - stride;
1533 for (base = 0; base < max; base++) {
1535 int right = left + stride;
1536 gid_t tmp = GROUP_AT(group_info, right);
1538 while (left >= 0 && GROUP_AT(group_info, left) > tmp) {
1539 GROUP_AT(group_info, right) =
1540 GROUP_AT(group_info, left);
1544 GROUP_AT(group_info, right) = tmp;
1550 /* a simple bsearch */
1551 int groups_search(struct group_info *group_info, gid_t grp)
1553 unsigned int left, right;
1559 right = group_info->ngroups;
1560 while (left < right) {
1561 unsigned int mid = (left+right)/2;
1562 int cmp = grp - GROUP_AT(group_info, mid);
1573 /* validate and set current->group_info */
1574 int set_current_groups(struct group_info *group_info)
1577 struct group_info *old_info;
1579 retval = security_task_setgroups(group_info);
1583 groups_sort(group_info);
1584 get_group_info(group_info);
1587 old_info = current->group_info;
1588 current->group_info = group_info;
1589 task_unlock(current);
1591 put_group_info(old_info);
1596 EXPORT_SYMBOL(set_current_groups);
1598 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1603 * SMP: Nobody else can change our grouplist. Thus we are
1610 /* no need to grab task_lock here; it cannot change */
1611 i = current->group_info->ngroups;
1613 if (i > gidsetsize) {
1617 if (groups_to_user(grouplist, current->group_info)) {
1627 * SMP: Our groups are copy-on-write. We can set them safely
1628 * without another task interfering.
1631 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1633 struct group_info *group_info;
1636 if (!capable(CAP_SETGID))
1638 if ((unsigned)gidsetsize > NGROUPS_MAX)
1641 group_info = groups_alloc(gidsetsize);
1644 retval = groups_from_user(group_info, grouplist);
1646 put_group_info(group_info);
1650 retval = set_current_groups(group_info);
1651 put_group_info(group_info);
1657 * Check whether we're fsgid/egid or in the supplemental group..
1659 int in_group_p(gid_t grp)
1662 if (grp != current->fsgid) {
1663 retval = groups_search(current->group_info, grp);
1668 EXPORT_SYMBOL(in_group_p);
1670 int in_egroup_p(gid_t grp)
1673 if (grp != current->egid) {
1674 retval = groups_search(current->group_info, grp);
1679 EXPORT_SYMBOL(in_egroup_p);
1681 DECLARE_RWSEM(uts_sem);
1683 EXPORT_SYMBOL(uts_sem);
1685 asmlinkage long sys_newuname(struct new_utsname __user * name)
1689 down_read(&uts_sem);
1690 if (copy_to_user(name, vx_new_utsname(), sizeof *name))
1696 asmlinkage long sys_sethostname(char __user *name, int len)
1699 char tmp[__NEW_UTS_LEN];
1701 if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
1703 if (len < 0 || len > __NEW_UTS_LEN)
1705 down_write(&uts_sem);
1707 if (!copy_from_user(tmp, name, len)) {
1708 char *ptr = vx_new_uts(nodename);
1710 memcpy(ptr, tmp, len);
1718 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1720 asmlinkage long sys_gethostname(char __user *name, int len)
1727 down_read(&uts_sem);
1728 ptr = vx_new_uts(nodename);
1729 i = 1 + strlen(ptr);
1733 if (copy_to_user(name, ptr, i))
1742 * Only setdomainname; getdomainname can be implemented by calling
1745 asmlinkage long sys_setdomainname(char __user *name, int len)
1748 char tmp[__NEW_UTS_LEN];
1750 if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
1752 if (len < 0 || len > __NEW_UTS_LEN)
1755 down_write(&uts_sem);
1757 if (!copy_from_user(tmp, name, len)) {
1758 char *ptr = vx_new_uts(domainname);
1760 memcpy(ptr, tmp, len);
1768 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1770 if (resource >= RLIM_NLIMITS)
1773 struct rlimit value;
1774 task_lock(current->group_leader);
1775 value = current->signal->rlim[resource];
1776 task_unlock(current->group_leader);
1777 return copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
1781 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1784 * Back compatibility for getrlimit. Needed for some apps.
1787 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1790 if (resource >= RLIM_NLIMITS)
1793 task_lock(current->group_leader);
1794 x = current->signal->rlim[resource];
1795 task_unlock(current->group_leader);
1796 if(x.rlim_cur > 0x7FFFFFFF)
1797 x.rlim_cur = 0x7FFFFFFF;
1798 if(x.rlim_max > 0x7FFFFFFF)
1799 x.rlim_max = 0x7FFFFFFF;
1800 return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1805 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1807 struct rlimit new_rlim, *old_rlim;
1808 unsigned long it_prof_secs;
1811 if (resource >= RLIM_NLIMITS)
1813 if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1815 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1817 old_rlim = current->signal->rlim + resource;
1818 if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
1819 !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
1821 if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
1824 retval = security_task_setrlimit(resource, &new_rlim);
1828 task_lock(current->group_leader);
1829 *old_rlim = new_rlim;
1830 task_unlock(current->group_leader);
1832 if (resource != RLIMIT_CPU)
1836 * RLIMIT_CPU handling. Note that the kernel fails to return an error
1837 * code if it rejected the user's attempt to set RLIMIT_CPU. This is a
1838 * very long-standing error, and fixing it now risks breakage of
1839 * applications, so we live with it
1841 if (new_rlim.rlim_cur == RLIM_INFINITY)
1844 it_prof_secs = cputime_to_secs(current->signal->it_prof_expires);
1845 if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) {
1846 unsigned long rlim_cur = new_rlim.rlim_cur;
1849 if (rlim_cur == 0) {
1851 * The caller is asking for an immediate RLIMIT_CPU
1852 * expiry. But we use the zero value to mean "it was
1853 * never set". So let's cheat and make it one second
1858 cputime = secs_to_cputime(rlim_cur);
1859 read_lock(&tasklist_lock);
1860 spin_lock_irq(¤t->sighand->siglock);
1861 set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
1862 spin_unlock_irq(¤t->sighand->siglock);
1863 read_unlock(&tasklist_lock);
1870 * It would make sense to put struct rusage in the task_struct,
1871 * except that would make the task_struct be *really big*. After
1872 * task_struct gets moved into malloc'ed memory, it would
1873 * make sense to do this. It will make moving the rest of the information
1874 * a lot simpler! (Which we're not doing right now because we're not
1875 * measuring them yet).
1877 * When sampling multiple threads for RUSAGE_SELF, under SMP we might have
1878 * races with threads incrementing their own counters. But since word
1879 * reads are atomic, we either get new values or old values and we don't
1880 * care which for the sums. We always take the siglock to protect reading
1881 * the c* fields from p->signal from races with exit.c updating those
1882 * fields when reaping, so a sample either gets all the additions of a
1883 * given child after it's reaped, or none so this sample is before reaping.
1885 * tasklist_lock locking optimisation:
1886 * If we are current and single threaded, we do not need to take the tasklist
1887 * lock or the siglock. No one else can take our signal_struct away,
1888 * no one else can reap the children to update signal->c* counters, and
1889 * no one else can race with the signal-> fields.
1890 * If we do not take the tasklist_lock, the signal-> fields could be read
1891 * out of order while another thread was just exiting. So we place a
1892 * read memory barrier when we avoid the lock. On the writer side,
1893 * write memory barrier is implied in __exit_signal as __exit_signal releases
1894 * the siglock spinlock after updating the signal-> fields.
1896 * We don't really need the siglock when we access the non c* fields
1897 * of the signal_struct (for RUSAGE_SELF) even in multithreaded
1898 * case, since we take the tasklist lock for read and the non c* signal->
1899 * fields are updated only in __exit_signal, which is called with
1900 * tasklist_lock taken for write, hence these two threads cannot execute
1905 static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1907 struct task_struct *t;
1908 unsigned long flags;
1909 cputime_t utime, stime;
1912 memset((char *) r, 0, sizeof *r);
1913 utime = stime = cputime_zero;
1915 if (p != current || !thread_group_empty(p))
1919 read_lock(&tasklist_lock);
1920 if (unlikely(!p->signal)) {
1921 read_unlock(&tasklist_lock);
1925 /* See locking comments above */
1930 case RUSAGE_CHILDREN:
1931 spin_lock_irqsave(&p->sighand->siglock, flags);
1932 utime = p->signal->cutime;
1933 stime = p->signal->cstime;
1934 r->ru_nvcsw = p->signal->cnvcsw;
1935 r->ru_nivcsw = p->signal->cnivcsw;
1936 r->ru_minflt = p->signal->cmin_flt;
1937 r->ru_majflt = p->signal->cmaj_flt;
1938 spin_unlock_irqrestore(&p->sighand->siglock, flags);
1940 if (who == RUSAGE_CHILDREN)
1944 utime = cputime_add(utime, p->signal->utime);
1945 stime = cputime_add(stime, p->signal->stime);
1946 r->ru_nvcsw += p->signal->nvcsw;
1947 r->ru_nivcsw += p->signal->nivcsw;
1948 r->ru_minflt += p->signal->min_flt;
1949 r->ru_majflt += p->signal->maj_flt;
1952 utime = cputime_add(utime, t->utime);
1953 stime = cputime_add(stime, t->stime);
1954 r->ru_nvcsw += t->nvcsw;
1955 r->ru_nivcsw += t->nivcsw;
1956 r->ru_minflt += t->min_flt;
1957 r->ru_majflt += t->maj_flt;
1967 read_unlock(&tasklist_lock);
1968 cputime_to_timeval(utime, &r->ru_utime);
1969 cputime_to_timeval(stime, &r->ru_stime);
1972 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1975 k_getrusage(p, who, &r);
1976 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1979 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1981 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1983 return getrusage(current, who, ru);
1986 asmlinkage long sys_umask(int mask)
1988 mask = xchg(¤t->fs->umask, mask & S_IRWXUGO);
1992 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1993 unsigned long arg4, unsigned long arg5)
1997 error = security_task_prctl(option, arg2, arg3, arg4, arg5);
2002 case PR_SET_PDEATHSIG:
2003 if (!valid_signal(arg2)) {
2007 current->pdeath_signal = arg2;
2009 case PR_GET_PDEATHSIG:
2010 error = put_user(current->pdeath_signal, (int __user *)arg2);
2012 case PR_GET_DUMPABLE:
2013 error = current->mm->dumpable;
2015 case PR_SET_DUMPABLE:
2016 if (arg2 < 0 || arg2 > 1) {
2020 current->mm->dumpable = arg2;
2023 case PR_SET_UNALIGN:
2024 error = SET_UNALIGN_CTL(current, arg2);
2026 case PR_GET_UNALIGN:
2027 error = GET_UNALIGN_CTL(current, arg2);
2030 error = SET_FPEMU_CTL(current, arg2);
2033 error = GET_FPEMU_CTL(current, arg2);
2036 error = SET_FPEXC_CTL(current, arg2);
2039 error = GET_FPEXC_CTL(current, arg2);
2042 error = PR_TIMING_STATISTICAL;
2045 if (arg2 == PR_TIMING_STATISTICAL)
2051 case PR_GET_KEEPCAPS:
2052 if (current->keep_capabilities)
2055 case PR_SET_KEEPCAPS:
2056 if (arg2 != 0 && arg2 != 1) {
2060 current->keep_capabilities = arg2;
2063 struct task_struct *me = current;
2064 unsigned char ncomm[sizeof(me->comm)];
2066 ncomm[sizeof(me->comm)-1] = 0;
2067 if (strncpy_from_user(ncomm, (char __user *)arg2,
2068 sizeof(me->comm)-1) < 0)
2070 set_task_comm(me, ncomm);
2074 struct task_struct *me = current;
2075 unsigned char tcomm[sizeof(me->comm)];
2077 get_task_comm(tcomm, me);
2078 if (copy_to_user((char __user *)arg2, tcomm, sizeof(tcomm)))