diff options
Diffstat (limited to 'kernel/sys.c')
-rw-r--r-- | kernel/sys.c | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index bce933ebb2..d09cac23fd 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/kexec.h> | 20 | #include <linux/kexec.h> |
21 | #include <linux/workqueue.h> | 21 | #include <linux/workqueue.h> |
22 | #include <linux/capability.h> | ||
22 | #include <linux/device.h> | 23 | #include <linux/device.h> |
23 | #include <linux/key.h> | 24 | #include <linux/key.h> |
24 | #include <linux/times.h> | 25 | #include <linux/times.h> |
@@ -32,6 +33,7 @@ | |||
32 | 33 | ||
33 | #include <linux/compat.h> | 34 | #include <linux/compat.h> |
34 | #include <linux/syscalls.h> | 35 | #include <linux/syscalls.h> |
36 | #include <linux/kprobes.h> | ||
35 | 37 | ||
36 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
37 | #include <asm/io.h> | 39 | #include <asm/io.h> |
@@ -168,7 +170,7 @@ EXPORT_SYMBOL(notifier_chain_unregister); | |||
168 | * of the last notifier function called. | 170 | * of the last notifier function called. |
169 | */ | 171 | */ |
170 | 172 | ||
171 | int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v) | 173 | int __kprobes notifier_call_chain(struct notifier_block **n, unsigned long val, void *v) |
172 | { | 174 | { |
173 | int ret=NOTIFY_DONE; | 175 | int ret=NOTIFY_DONE; |
174 | struct notifier_block *nb = *n; | 176 | struct notifier_block *nb = *n; |
@@ -222,6 +224,18 @@ int unregister_reboot_notifier(struct notifier_block * nb) | |||
222 | 224 | ||
223 | EXPORT_SYMBOL(unregister_reboot_notifier); | 225 | EXPORT_SYMBOL(unregister_reboot_notifier); |
224 | 226 | ||
227 | #ifndef CONFIG_SECURITY | ||
228 | int capable(int cap) | ||
229 | { | ||
230 | if (cap_raised(current->cap_effective, cap)) { | ||
231 | current->flags |= PF_SUPERPRIV; | ||
232 | return 1; | ||
233 | } | ||
234 | return 0; | ||
235 | } | ||
236 | EXPORT_SYMBOL(capable); | ||
237 | #endif | ||
238 | |||
225 | static int set_one_prio(struct task_struct *p, int niceval, int error) | 239 | static int set_one_prio(struct task_struct *p, int niceval, int error) |
226 | { | 240 | { |
227 | int no_nice; | 241 | int no_nice; |
@@ -488,6 +502,12 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user | |||
488 | magic2 != LINUX_REBOOT_MAGIC2C)) | 502 | magic2 != LINUX_REBOOT_MAGIC2C)) |
489 | return -EINVAL; | 503 | return -EINVAL; |
490 | 504 | ||
505 | /* Instead of trying to make the power_off code look like | ||
506 | * halt when pm_power_off is not set do it the easy way. | ||
507 | */ | ||
508 | if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) | ||
509 | cmd = LINUX_REBOOT_CMD_HALT; | ||
510 | |||
491 | lock_kernel(); | 511 | lock_kernel(); |
492 | switch (cmd) { | 512 | switch (cmd) { |
493 | case LINUX_REBOOT_CMD_RESTART: | 513 | case LINUX_REBOOT_CMD_RESTART: |
@@ -1083,10 +1103,11 @@ asmlinkage long sys_times(struct tms __user * tbuf) | |||
1083 | asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | 1103 | asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) |
1084 | { | 1104 | { |
1085 | struct task_struct *p; | 1105 | struct task_struct *p; |
1106 | struct task_struct *group_leader = current->group_leader; | ||
1086 | int err = -EINVAL; | 1107 | int err = -EINVAL; |
1087 | 1108 | ||
1088 | if (!pid) | 1109 | if (!pid) |
1089 | pid = current->pid; | 1110 | pid = group_leader->pid; |
1090 | if (!pgid) | 1111 | if (!pgid) |
1091 | pgid = pid; | 1112 | pgid = pid; |
1092 | if (pgid < 0) | 1113 | if (pgid < 0) |
@@ -1106,16 +1127,16 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1106 | if (!thread_group_leader(p)) | 1127 | if (!thread_group_leader(p)) |
1107 | goto out; | 1128 | goto out; |
1108 | 1129 | ||
1109 | if (p->parent == current || p->real_parent == current) { | 1130 | if (p->real_parent == group_leader) { |
1110 | err = -EPERM; | 1131 | err = -EPERM; |
1111 | if (p->signal->session != current->signal->session) | 1132 | if (p->signal->session != group_leader->signal->session) |
1112 | goto out; | 1133 | goto out; |
1113 | err = -EACCES; | 1134 | err = -EACCES; |
1114 | if (p->did_exec) | 1135 | if (p->did_exec) |
1115 | goto out; | 1136 | goto out; |
1116 | } else { | 1137 | } else { |
1117 | err = -ESRCH; | 1138 | err = -ESRCH; |
1118 | if (p != current) | 1139 | if (p != group_leader) |
1119 | goto out; | 1140 | goto out; |
1120 | } | 1141 | } |
1121 | 1142 | ||
@@ -1127,7 +1148,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) | |||
1127 | struct task_struct *p; | 1148 | struct task_struct *p; |
1128 | 1149 | ||
1129 | do_each_task_pid(pgid, PIDTYPE_PGID, p) { | 1150 | do_each_task_pid(pgid, PIDTYPE_PGID, p) { |
1130 | if (p->signal->session == current->signal->session) | 1151 | if (p->signal->session == group_leader->signal->session) |
1131 | goto ok_pgid; | 1152 | goto ok_pgid; |
1132 | } while_each_task_pid(pgid, PIDTYPE_PGID, p); | 1153 | } while_each_task_pid(pgid, PIDTYPE_PGID, p); |
1133 | goto out; | 1154 | goto out; |
@@ -1207,24 +1228,22 @@ asmlinkage long sys_getsid(pid_t pid) | |||
1207 | 1228 | ||
1208 | asmlinkage long sys_setsid(void) | 1229 | asmlinkage long sys_setsid(void) |
1209 | { | 1230 | { |
1231 | struct task_struct *group_leader = current->group_leader; | ||
1210 | struct pid *pid; | 1232 | struct pid *pid; |
1211 | int err = -EPERM; | 1233 | int err = -EPERM; |
1212 | 1234 | ||
1213 | if (!thread_group_leader(current)) | ||
1214 | return -EINVAL; | ||
1215 | |||
1216 | down(&tty_sem); | 1235 | down(&tty_sem); |
1217 | write_lock_irq(&tasklist_lock); | 1236 | write_lock_irq(&tasklist_lock); |
1218 | 1237 | ||
1219 | pid = find_pid(PIDTYPE_PGID, current->pid); | 1238 | pid = find_pid(PIDTYPE_PGID, group_leader->pid); |
1220 | if (pid) | 1239 | if (pid) |
1221 | goto out; | 1240 | goto out; |
1222 | 1241 | ||
1223 | current->signal->leader = 1; | 1242 | group_leader->signal->leader = 1; |
1224 | __set_special_pids(current->pid, current->pid); | 1243 | __set_special_pids(group_leader->pid, group_leader->pid); |
1225 | current->signal->tty = NULL; | 1244 | group_leader->signal->tty = NULL; |
1226 | current->signal->tty_old_pgrp = 0; | 1245 | group_leader->signal->tty_old_pgrp = 0; |
1227 | err = process_group(current); | 1246 | err = process_group(group_leader); |
1228 | out: | 1247 | out: |
1229 | write_unlock_irq(&tasklist_lock); | 1248 | write_unlock_irq(&tasklist_lock); |
1230 | up(&tty_sem); | 1249 | up(&tty_sem); |
@@ -1686,7 +1705,10 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1686 | if (unlikely(!p->signal)) | 1705 | if (unlikely(!p->signal)) |
1687 | return; | 1706 | return; |
1688 | 1707 | ||
1708 | utime = stime = cputime_zero; | ||
1709 | |||
1689 | switch (who) { | 1710 | switch (who) { |
1711 | case RUSAGE_BOTH: | ||
1690 | case RUSAGE_CHILDREN: | 1712 | case RUSAGE_CHILDREN: |
1691 | spin_lock_irqsave(&p->sighand->siglock, flags); | 1713 | spin_lock_irqsave(&p->sighand->siglock, flags); |
1692 | utime = p->signal->cutime; | 1714 | utime = p->signal->cutime; |
@@ -1696,22 +1718,11 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1696 | r->ru_minflt = p->signal->cmin_flt; | 1718 | r->ru_minflt = p->signal->cmin_flt; |
1697 | r->ru_majflt = p->signal->cmaj_flt; | 1719 | r->ru_majflt = p->signal->cmaj_flt; |
1698 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 1720 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
1699 | cputime_to_timeval(utime, &r->ru_utime); | 1721 | |
1700 | cputime_to_timeval(stime, &r->ru_stime); | 1722 | if (who == RUSAGE_CHILDREN) |
1701 | break; | 1723 | break; |
1724 | |||
1702 | case RUSAGE_SELF: | 1725 | case RUSAGE_SELF: |
1703 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
1704 | utime = stime = cputime_zero; | ||
1705 | goto sum_group; | ||
1706 | case RUSAGE_BOTH: | ||
1707 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
1708 | utime = p->signal->cutime; | ||
1709 | stime = p->signal->cstime; | ||
1710 | r->ru_nvcsw = p->signal->cnvcsw; | ||
1711 | r->ru_nivcsw = p->signal->cnivcsw; | ||
1712 | r->ru_minflt = p->signal->cmin_flt; | ||
1713 | r->ru_majflt = p->signal->cmaj_flt; | ||
1714 | sum_group: | ||
1715 | utime = cputime_add(utime, p->signal->utime); | 1726 | utime = cputime_add(utime, p->signal->utime); |
1716 | stime = cputime_add(stime, p->signal->stime); | 1727 | stime = cputime_add(stime, p->signal->stime); |
1717 | r->ru_nvcsw += p->signal->nvcsw; | 1728 | r->ru_nvcsw += p->signal->nvcsw; |
@@ -1728,13 +1739,14 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1728 | r->ru_majflt += t->maj_flt; | 1739 | r->ru_majflt += t->maj_flt; |
1729 | t = next_thread(t); | 1740 | t = next_thread(t); |
1730 | } while (t != p); | 1741 | } while (t != p); |
1731 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
1732 | cputime_to_timeval(utime, &r->ru_utime); | ||
1733 | cputime_to_timeval(stime, &r->ru_stime); | ||
1734 | break; | 1742 | break; |
1743 | |||
1735 | default: | 1744 | default: |
1736 | BUG(); | 1745 | BUG(); |
1737 | } | 1746 | } |
1747 | |||
1748 | cputime_to_timeval(utime, &r->ru_utime); | ||
1749 | cputime_to_timeval(stime, &r->ru_stime); | ||
1738 | } | 1750 | } |
1739 | 1751 | ||
1740 | int getrusage(struct task_struct *p, int who, struct rusage __user *ru) | 1752 | int getrusage(struct task_struct *p, int who, struct rusage __user *ru) |