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/workqueue.h>
20 #include <linux/device.h>
21 #include <linux/times.h>
22 #include <linux/security.h>
23 #include <linux/dcookies.h>
24 #include <linux/suspend.h>
26 #include <asm/uaccess.h>
28 #include <asm/unistd.h>
30 #ifndef SET_UNALIGN_CTL
31 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
33 #ifndef GET_UNALIGN_CTL
34 # define GET_UNALIGN_CTL(a,b) (-EINVAL)
37 # define SET_FPEMU_CTL(a,b) (-EINVAL)
40 # define GET_FPEMU_CTL(a,b) (-EINVAL)
43 # define SET_FPEXC_CTL(a,b) (-EINVAL)
46 # define GET_FPEXC_CTL(a,b) (-EINVAL)
50 * this is where the system-wide overflow UID and GID are defined, for
51 * architectures that now have 32-bit UID/GID but didn't in the past
54 int overflowuid = DEFAULT_OVERFLOWUID;
55 int overflowgid = DEFAULT_OVERFLOWGID;
58 * the same as above, but for filesystems which can only store a 16-bit
59 * UID and GID. as such, this is needed on all architectures
62 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
63 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
66 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
72 extern int system_running;
75 * Notifier list for kernel code which wants to be called
76 * at shutdown. This is used to stop any idling DMA operations
80 static struct notifier_block *reboot_notifier_list;
81 rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
84 * notifier_chain_register - Add notifier to a notifier chain
85 * @list: Pointer to root list pointer
86 * @n: New entry in notifier chain
88 * Adds a notifier to a notifier chain.
90 * Currently always returns zero.
93 int notifier_chain_register(struct notifier_block **list, struct notifier_block *n)
95 write_lock(¬ifier_lock);
98 if(n->priority > (*list)->priority)
100 list= &((*list)->next);
104 write_unlock(¬ifier_lock);
109 * notifier_chain_unregister - Remove notifier from a notifier chain
110 * @nl: Pointer to root list pointer
111 * @n: New entry in notifier chain
113 * Removes a notifier from a notifier chain.
115 * Returns zero on success, or %-ENOENT on failure.
118 int notifier_chain_unregister(struct notifier_block **nl, struct notifier_block *n)
120 write_lock(¬ifier_lock);
126 write_unlock(¬ifier_lock);
131 write_unlock(¬ifier_lock);
136 * notifier_call_chain - Call functions in a notifier chain
137 * @n: Pointer to root pointer of notifier chain
138 * @val: Value passed unmodified to notifier function
139 * @v: Pointer passed unmodified to notifier function
141 * Calls each function in a notifier chain in turn.
143 * If the return value of the notifier can be and'd
144 * with %NOTIFY_STOP_MASK, then notifier_call_chain
145 * will return immediately, with the return value of
146 * the notifier function which halted execution.
147 * Otherwise, the return value is the return value
148 * of the last notifier function called.
151 int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v)
154 struct notifier_block *nb = *n;
158 ret=nb->notifier_call(nb,val,v);
159 if(ret&NOTIFY_STOP_MASK)
169 * register_reboot_notifier - Register function to be called at reboot time
170 * @nb: Info about notifier function to be called
172 * Registers a function with the list of functions
173 * to be called at reboot time.
175 * Currently always returns zero, as notifier_chain_register
176 * always returns zero.
179 int register_reboot_notifier(struct notifier_block * nb)
181 return notifier_chain_register(&reboot_notifier_list, nb);
185 * unregister_reboot_notifier - Unregister previously registered reboot notifier
186 * @nb: Hook to be unregistered
188 * Unregisters a previously registered reboot
191 * Returns zero on success, or %-ENOENT on failure.
194 int unregister_reboot_notifier(struct notifier_block * nb)
196 return notifier_chain_unregister(&reboot_notifier_list, nb);
199 asmlinkage long sys_ni_syscall(void)
204 cond_syscall(sys_nfsservctl)
205 cond_syscall(sys_quotactl)
206 cond_syscall(sys_acct)
207 cond_syscall(sys_lookup_dcookie)
208 cond_syscall(sys_swapon)
209 cond_syscall(sys_swapoff)
210 cond_syscall(sys_init_module)
211 cond_syscall(sys_delete_module)
212 cond_syscall(sys_socketpair)
213 cond_syscall(sys_bind)
214 cond_syscall(sys_listen)
215 cond_syscall(sys_accept)
216 cond_syscall(sys_connect)
217 cond_syscall(sys_getsockname)
218 cond_syscall(sys_getpeername)
219 cond_syscall(sys_sendto)
220 cond_syscall(sys_send)
221 cond_syscall(sys_recvfrom)
222 cond_syscall(sys_recv)
223 cond_syscall(sys_setsockopt)
224 cond_syscall(sys_getsockopt)
225 cond_syscall(sys_shutdown)
226 cond_syscall(sys_sendmsg)
227 cond_syscall(sys_recvmsg)
228 cond_syscall(sys_socketcall)
230 static int set_one_prio(struct task_struct *p, int niceval, int error)
234 if (p->uid != current->euid &&
235 p->uid != current->uid && !capable(CAP_SYS_NICE)) {
239 if (niceval < task_nice(p) && !capable(CAP_SYS_NICE)) {
243 no_nice = security_task_setnice(p, niceval);
250 set_user_nice(p, niceval);
255 asmlinkage long sys_setpriority(int which, int who, int niceval)
257 struct task_struct *g, *p;
258 struct user_struct *user;
263 if (which > 2 || which < 0)
266 /* normalize: avoid signed division (rounding problems) */
273 read_lock(&tasklist_lock);
278 p = find_task_by_pid(who);
280 error = set_one_prio(p, niceval, error);
285 for_each_task_pid(who, PIDTYPE_PGID, p, l, pid)
286 error = set_one_prio(p, niceval, error);
290 user = current->user;
292 user = find_user(who);
299 error = set_one_prio(p, niceval, error);
300 while_each_thread(g, p);
304 read_unlock(&tasklist_lock);
310 * Ugh. To avoid negative return values, "getpriority()" will
311 * not return the normal nice-value, but a negated value that
312 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
313 * to stay compatible.
315 asmlinkage long sys_getpriority(int which, int who)
317 struct task_struct *g, *p;
320 struct user_struct *user;
321 long niceval, retval = -ESRCH;
323 if (which > 2 || which < 0)
326 read_lock(&tasklist_lock);
331 p = find_task_by_pid(who);
333 niceval = 20 - task_nice(p);
334 if (niceval > retval)
341 for_each_task_pid(who, PIDTYPE_PGID, p, l, pid) {
342 niceval = 20 - task_nice(p);
343 if (niceval > retval)
349 user = current->user;
351 user = find_user(who);
358 niceval = 20 - task_nice(p);
359 if (niceval > retval)
362 while_each_thread(g, p);
366 read_unlock(&tasklist_lock);
373 * Reboot system call: for obvious reasons only root may call it,
374 * and even root needs to set up some magic numbers in the registers
375 * so that some mistake won't make this reboot the whole machine.
376 * You can also set the meaning of the ctrl-alt-del-key here.
378 * reboot doesn't sync: do that yourself before calling this.
380 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
384 /* We only trust the superuser with rebooting the system. */
385 if (!capable(CAP_SYS_BOOT))
388 /* For safety, we require "magic" arguments. */
389 if (magic1 != LINUX_REBOOT_MAGIC1 ||
390 (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&
391 magic2 != LINUX_REBOOT_MAGIC2B))
396 case LINUX_REBOOT_CMD_RESTART:
397 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
400 printk(KERN_EMERG "Restarting system.\n");
401 machine_restart(NULL);
404 case LINUX_REBOOT_CMD_CAD_ON:
408 case LINUX_REBOOT_CMD_CAD_OFF:
412 case LINUX_REBOOT_CMD_HALT:
413 notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
416 printk(KERN_EMERG "System halted.\n");
422 case LINUX_REBOOT_CMD_POWER_OFF:
423 notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
426 printk(KERN_EMERG "Power down.\n");
432 case LINUX_REBOOT_CMD_RESTART2:
433 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
437 buffer[sizeof(buffer) - 1] = '\0';
439 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
442 printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
443 machine_restart(buffer);
446 #ifdef CONFIG_SOFTWARE_SUSPEND
447 case LINUX_REBOOT_CMD_SW_SUSPEND:
448 if (!software_suspend_enabled) {
465 static void deferred_cad(void *dummy)
467 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
468 machine_restart(NULL);
472 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
473 * As it's called within an interrupt, it may NOT sync: the only choice
474 * is whether to reboot at once, or just ignore the ctrl-alt-del.
476 void ctrl_alt_del(void)
478 static DECLARE_WORK(cad_work, deferred_cad, NULL);
481 schedule_work(&cad_work);
483 kill_proc(cad_pid, SIGINT, 1);
488 * Unprivileged users may change the real gid to the effective gid
489 * or vice versa. (BSD-style)
491 * If you set the real gid at all, or set the effective gid to a value not
492 * equal to the real gid, then the saved gid is set to the new effective gid.
494 * This makes it possible for a setgid program to completely drop its
495 * privileges, which is often a useful assertion to make when you are doing
496 * a security audit over a program.
498 * The general idea is that a program which uses just setregid() will be
499 * 100% compatible with BSD. A program which uses just setgid() will be
500 * 100% compatible with POSIX with saved IDs.
502 * SMP: There are not races, the GIDs are checked only by filesystem
503 * operations (as far as semantic preservation is concerned).
505 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
507 int old_rgid = current->gid;
508 int old_egid = current->egid;
509 int new_rgid = old_rgid;
510 int new_egid = old_egid;
513 retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
517 if (rgid != (gid_t) -1) {
518 if ((old_rgid == rgid) ||
519 (current->egid==rgid) ||
525 if (egid != (gid_t) -1) {
526 if ((old_rgid == egid) ||
527 (current->egid == egid) ||
528 (current->sgid == egid) ||
535 if (new_egid != old_egid)
537 current->mm->dumpable = 0;
540 if (rgid != (gid_t) -1 ||
541 (egid != (gid_t) -1 && egid != old_rgid))
542 current->sgid = new_egid;
543 current->fsgid = new_egid;
544 current->egid = new_egid;
545 current->gid = new_rgid;
550 * setgid() is implemented like SysV w/ SAVED_IDS
552 * SMP: Same implicit races as above.
554 asmlinkage long sys_setgid(gid_t gid)
556 int old_egid = current->egid;
559 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
563 if (capable(CAP_SETGID))
567 current->mm->dumpable=0;
570 current->gid = current->egid = current->sgid = current->fsgid = gid;
572 else if ((gid == current->gid) || (gid == current->sgid))
576 current->mm->dumpable=0;
579 current->egid = current->fsgid = gid;
586 static int set_user(uid_t new_ruid, int dumpclear)
588 struct user_struct *new_user;
590 new_user = alloc_uid(new_ruid);
593 switch_uid(new_user);
597 current->mm->dumpable = 0;
600 current->uid = new_ruid;
605 * Unprivileged users may change the real uid to the effective uid
606 * or vice versa. (BSD-style)
608 * If you set the real uid at all, or set the effective uid to a value not
609 * equal to the real uid, then the saved uid is set to the new effective uid.
611 * This makes it possible for a setuid program to completely drop its
612 * privileges, which is often a useful assertion to make when you are doing
613 * a security audit over a program.
615 * The general idea is that a program which uses just setreuid() will be
616 * 100% compatible with BSD. A program which uses just setuid() will be
617 * 100% compatible with POSIX with saved IDs.
619 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
621 int old_ruid, old_euid, old_suid, new_ruid, new_euid;
624 retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
628 new_ruid = old_ruid = current->uid;
629 new_euid = old_euid = current->euid;
630 old_suid = current->suid;
632 if (ruid != (uid_t) -1) {
634 if ((old_ruid != ruid) &&
635 (current->euid != ruid) &&
636 !capable(CAP_SETUID))
640 if (euid != (uid_t) -1) {
642 if ((old_ruid != euid) &&
643 (current->euid != euid) &&
644 (current->suid != euid) &&
645 !capable(CAP_SETUID))
649 if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
652 if (new_euid != old_euid)
654 current->mm->dumpable=0;
657 current->fsuid = current->euid = new_euid;
658 if (ruid != (uid_t) -1 ||
659 (euid != (uid_t) -1 && euid != old_ruid))
660 current->suid = current->euid;
661 current->fsuid = current->euid;
663 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
669 * setuid() is implemented like SysV with SAVED_IDS
671 * Note that SAVED_ID's is deficient in that a setuid root program
672 * like sendmail, for example, cannot set its uid to be a normal
673 * user and then switch back, because if you're root, setuid() sets
674 * the saved uid too. If you don't like this, blame the bright people
675 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
676 * will allow a root program to temporarily drop privileges and be able to
677 * regain them by swapping the real and effective uid.
679 asmlinkage long sys_setuid(uid_t uid)
681 int old_euid = current->euid;
682 int old_ruid, old_suid, new_ruid, new_suid;
685 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
689 old_ruid = new_ruid = current->uid;
690 old_suid = current->suid;
693 if (capable(CAP_SETUID)) {
694 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
697 } else if ((uid != current->uid) && (uid != new_suid))
702 current->mm->dumpable = 0;
705 current->fsuid = current->euid = uid;
706 current->suid = new_suid;
708 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
713 * This function implements a generic ability to update ruid, euid,
714 * and suid. This allows you to implement the 4.4 compatible seteuid().
716 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
718 int old_ruid = current->uid;
719 int old_euid = current->euid;
720 int old_suid = current->suid;
723 retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
727 if (!capable(CAP_SETUID)) {
728 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
729 (ruid != current->euid) && (ruid != current->suid))
731 if ((euid != (uid_t) -1) && (euid != current->uid) &&
732 (euid != current->euid) && (euid != current->suid))
734 if ((suid != (uid_t) -1) && (suid != current->uid) &&
735 (suid != current->euid) && (suid != current->suid))
738 if (ruid != (uid_t) -1) {
739 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
742 if (euid != (uid_t) -1) {
743 if (euid != current->euid)
745 current->mm->dumpable = 0;
748 current->euid = euid;
750 current->fsuid = current->euid;
751 if (suid != (uid_t) -1)
752 current->suid = suid;
754 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
757 asmlinkage long sys_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
761 if (!(retval = put_user(current->uid, ruid)) &&
762 !(retval = put_user(current->euid, euid)))
763 retval = put_user(current->suid, suid);
769 * Same as above, but for rgid, egid, sgid.
771 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
775 retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
779 if (!capable(CAP_SETGID)) {
780 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
781 (rgid != current->egid) && (rgid != current->sgid))
783 if ((egid != (gid_t) -1) && (egid != current->gid) &&
784 (egid != current->egid) && (egid != current->sgid))
786 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
787 (sgid != current->egid) && (sgid != current->sgid))
790 if (egid != (gid_t) -1) {
791 if (egid != current->egid)
793 current->mm->dumpable = 0;
796 current->egid = egid;
798 current->fsgid = current->egid;
799 if (rgid != (gid_t) -1)
801 if (sgid != (gid_t) -1)
802 current->sgid = sgid;
806 asmlinkage long sys_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
810 if (!(retval = put_user(current->gid, rgid)) &&
811 !(retval = put_user(current->egid, egid)))
812 retval = put_user(current->sgid, sgid);
819 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
820 * is used for "access()" and for the NFS daemon (letting nfsd stay at
821 * whatever uid it wants to). It normally shadows "euid", except when
822 * explicitly set by setfsuid() or for access..
824 asmlinkage long sys_setfsuid(uid_t uid)
829 retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
833 old_fsuid = current->fsuid;
834 if (uid == current->uid || uid == current->euid ||
835 uid == current->suid || uid == current->fsuid ||
838 if (uid != old_fsuid)
840 current->mm->dumpable = 0;
843 current->fsuid = uid;
846 retval = security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
854 * Samma på svenska..
856 asmlinkage long sys_setfsgid(gid_t gid)
861 retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS);
865 old_fsgid = current->fsgid;
866 if (gid == current->gid || gid == current->egid ||
867 gid == current->sgid || gid == current->fsgid ||
870 if (gid != old_fsgid)
872 current->mm->dumpable = 0;
875 current->fsgid = gid;
880 asmlinkage long sys_times(struct tms __user * tbuf)
883 * In the SMP world we might just be unlucky and have one of
884 * the times increment as we use it. Since the value is an
885 * atomically safe type this is just fine. Conceptually its
886 * as if the syscall took an instant longer to occur.
890 tmp.tms_utime = jiffies_to_clock_t(current->utime);
891 tmp.tms_stime = jiffies_to_clock_t(current->stime);
892 tmp.tms_cutime = jiffies_to_clock_t(current->cutime);
893 tmp.tms_cstime = jiffies_to_clock_t(current->cstime);
894 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
897 return (long) jiffies_64_to_clock_t(get_jiffies_64());
901 * This needs some heavy checking ...
902 * I just haven't the stomach for it. I also don't fully
903 * understand sessions/pgrp etc. Let somebody who does explain it.
905 * OK, I think I have the protection semantics right.... this is really
906 * only important on a multi-user system anyway, to make sure one user
907 * can't send a signal to a process owned by another. -TYT, 12/12/91
909 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
913 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
915 struct task_struct *p;
925 /* From this point forward we keep holding onto the tasklist lock
926 * so that our parent does not change from under us. -DaveM
928 write_lock_irq(&tasklist_lock);
931 p = find_task_by_pid(pid);
936 if (!thread_group_leader(p))
939 if (p->parent == current || p->real_parent == current) {
941 if (p->session != current->session)
957 struct task_struct *p;
961 for_each_task_pid(pgid, PIDTYPE_PGID, p, l, pid)
962 if (p->session == current->session)
968 err = security_task_setpgid(p, pgid);
972 if (p->pgrp != pgid) {
973 detach_pid(p, PIDTYPE_PGID);
975 attach_pid(p, PIDTYPE_PGID, pgid);
979 /* All paths lead to here, thus we are safe. -DaveM */
980 write_unlock_irq(&tasklist_lock);
984 asmlinkage long sys_getpgid(pid_t pid)
987 return current->pgrp;
990 struct task_struct *p;
992 read_lock(&tasklist_lock);
993 p = find_task_by_pid(pid);
997 retval = security_task_getpgid(p);
1001 read_unlock(&tasklist_lock);
1006 asmlinkage long sys_getpgrp(void)
1008 /* SMP - assuming writes are word atomic this is fine */
1009 return current->pgrp;
1012 asmlinkage long sys_getsid(pid_t pid)
1015 return current->session;
1018 struct task_struct *p;
1020 read_lock(&tasklist_lock);
1021 p = find_task_by_pid(pid);
1025 retval = security_task_getsid(p);
1027 retval = p->session;
1029 read_unlock(&tasklist_lock);
1034 asmlinkage long sys_setsid(void)
1039 if (!thread_group_leader(current))
1042 write_lock_irq(&tasklist_lock);
1044 pid = find_pid(PIDTYPE_PGID, current->pid);
1048 current->leader = 1;
1049 __set_special_pids(current->pid, current->pid);
1050 current->tty = NULL;
1051 current->tty_old_pgrp = 0;
1052 err = current->pgrp;
1054 write_unlock_irq(&tasklist_lock);
1059 * Supplementary group IDs
1061 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1066 * SMP: Nobody else can change our grouplist. Thus we are
1072 i = current->ngroups;
1076 if (copy_to_user(grouplist, current->groups, sizeof(gid_t)*i))
1083 * SMP: Our groups are not shared. We can copy to/from them safely
1084 * without another task interfering.
1087 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1089 gid_t groups[NGROUPS];
1092 if (!capable(CAP_SETGID))
1094 if ((unsigned) gidsetsize > NGROUPS)
1096 if (copy_from_user(groups, grouplist, gidsetsize * sizeof(gid_t)))
1098 retval = security_task_setgroups(gidsetsize, groups);
1101 memcpy(current->groups, groups, gidsetsize * sizeof(gid_t));
1102 current->ngroups = gidsetsize;
1106 static int supplemental_group_member(gid_t grp)
1108 int i = current->ngroups;
1111 gid_t *groups = current->groups;
1123 * Check whether we're fsgid/egid or in the supplemental group..
1125 int in_group_p(gid_t grp)
1128 if (grp != current->fsgid)
1129 retval = supplemental_group_member(grp);
1133 int in_egroup_p(gid_t grp)
1136 if (grp != current->egid)
1137 retval = supplemental_group_member(grp);
1141 DECLARE_RWSEM(uts_sem);
1143 asmlinkage long sys_newuname(struct new_utsname __user * name)
1147 down_read(&uts_sem);
1148 if (copy_to_user(name,&system_utsname,sizeof *name))
1154 asmlinkage long sys_sethostname(char __user *name, int len)
1158 if (!capable(CAP_SYS_ADMIN))
1160 if (len < 0 || len > __NEW_UTS_LEN)
1162 down_write(&uts_sem);
1164 if (!copy_from_user(system_utsname.nodename, name, len)) {
1165 system_utsname.nodename[len] = 0;
1172 asmlinkage long sys_gethostname(char __user *name, int len)
1178 down_read(&uts_sem);
1179 i = 1 + strlen(system_utsname.nodename);
1183 if (copy_to_user(name, system_utsname.nodename, i))
1190 * Only setdomainname; getdomainname can be implemented by calling
1193 asmlinkage long sys_setdomainname(char __user *name, int len)
1197 if (!capable(CAP_SYS_ADMIN))
1199 if (len < 0 || len > __NEW_UTS_LEN)
1202 down_write(&uts_sem);
1204 if (!copy_from_user(system_utsname.domainname, name, len)) {
1206 system_utsname.domainname[len] = 0;
1212 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1214 if (resource >= RLIM_NLIMITS)
1217 return copy_to_user(rlim, current->rlim + resource, sizeof(*rlim))
1221 #if (!defined(__ia64__) && !defined(CONFIG_V850)) || defined(CONFIG_COMPAT)
1224 * Back compatibility for getrlimit. Needed for some apps.
1227 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1230 if (resource >= RLIM_NLIMITS)
1233 memcpy(&x, current->rlim + resource, sizeof(*rlim));
1234 if(x.rlim_cur > 0x7FFFFFFF)
1235 x.rlim_cur = 0x7FFFFFFF;
1236 if(x.rlim_max > 0x7FFFFFFF)
1237 x.rlim_max = 0x7FFFFFFF;
1238 return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1243 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1245 struct rlimit new_rlim, *old_rlim;
1248 if (resource >= RLIM_NLIMITS)
1250 if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1252 if (new_rlim.rlim_cur > new_rlim.rlim_max)
1254 old_rlim = current->rlim + resource;
1255 if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
1256 (new_rlim.rlim_max > old_rlim->rlim_max)) &&
1257 !capable(CAP_SYS_RESOURCE))
1259 if (resource == RLIMIT_NOFILE) {
1260 if (new_rlim.rlim_cur > NR_OPEN || new_rlim.rlim_max > NR_OPEN)
1264 retval = security_task_setrlimit(resource, &new_rlim);
1268 *old_rlim = new_rlim;
1273 * It would make sense to put struct rusage in the task_struct,
1274 * except that would make the task_struct be *really big*. After
1275 * task_struct gets moved into malloc'ed memory, it would
1276 * make sense to do this. It will make moving the rest of the information
1277 * a lot simpler! (Which we're not doing right now because we're not
1278 * measuring them yet).
1280 * This is SMP safe. Either we are called from sys_getrusage on ourselves
1281 * below (we know we aren't going to exit/disappear and only we change our
1282 * rusage counters), or we are called from wait4() on a process which is
1283 * either stopped or zombied. In the zombied case the task won't get
1284 * reaped till shortly after the call to getrusage(), in both cases the
1285 * task being examined is in a frozen state so the counters won't change.
1287 * FIXME! Get the fault counts properly!
1289 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1293 memset((char *) &r, 0, sizeof(r));
1296 jiffies_to_timeval(p->utime, &r.ru_utime);
1297 jiffies_to_timeval(p->stime, &r.ru_stime);
1298 r.ru_minflt = p->min_flt;
1299 r.ru_majflt = p->maj_flt;
1300 r.ru_nswap = p->nswap;
1302 case RUSAGE_CHILDREN:
1303 jiffies_to_timeval(p->cutime, &r.ru_utime);
1304 jiffies_to_timeval(p->cstime, &r.ru_stime);
1305 r.ru_minflt = p->cmin_flt;
1306 r.ru_majflt = p->cmaj_flt;
1307 r.ru_nswap = p->cnswap;
1310 jiffies_to_timeval(p->utime + p->cutime, &r.ru_utime);
1311 jiffies_to_timeval(p->stime + p->cstime, &r.ru_stime);
1312 r.ru_minflt = p->min_flt + p->cmin_flt;
1313 r.ru_majflt = p->maj_flt + p->cmaj_flt;
1314 r.ru_nswap = p->nswap + p->cnswap;
1317 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1320 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1322 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1324 return getrusage(current, who, ru);
1327 asmlinkage long sys_umask(int mask)
1329 mask = xchg(¤t->fs->umask, mask & S_IRWXUGO);
1333 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1334 unsigned long arg4, unsigned long arg5)
1339 error = security_task_prctl(option, arg2, arg3, arg4, arg5);
1344 case PR_SET_PDEATHSIG:
1346 if (sig < 0 || sig > _NSIG) {
1350 current->pdeath_signal = sig;
1352 case PR_GET_PDEATHSIG:
1353 error = put_user(current->pdeath_signal, (int __user *)arg2);
1355 case PR_GET_DUMPABLE:
1356 if (current->mm->dumpable)
1359 case PR_SET_DUMPABLE:
1360 if (arg2 != 0 && arg2 != 1) {
1364 current->mm->dumpable = arg2;
1367 case PR_SET_UNALIGN:
1368 error = SET_UNALIGN_CTL(current, arg2);
1370 case PR_GET_UNALIGN:
1371 error = GET_UNALIGN_CTL(current, arg2);
1374 error = SET_FPEMU_CTL(current, arg2);
1377 error = GET_FPEMU_CTL(current, arg2);
1380 error = SET_FPEXC_CTL(current, arg2);
1383 error = GET_FPEXC_CTL(current, arg2);
1387 case PR_GET_KEEPCAPS:
1388 if (current->keep_capabilities)
1391 case PR_SET_KEEPCAPS:
1392 if (arg2 != 0 && arg2 != 1) {
1396 current->keep_capabilities = arg2;
1405 EXPORT_SYMBOL(notifier_chain_register);
1406 EXPORT_SYMBOL(notifier_chain_unregister);
1407 EXPORT_SYMBOL(notifier_call_chain);
1408 EXPORT_SYMBOL(register_reboot_notifier);
1409 EXPORT_SYMBOL(unregister_reboot_notifier);
1410 EXPORT_SYMBOL(in_group_p);
1411 EXPORT_SYMBOL(in_egroup_p);