aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/signal.c')
-rw-r--r--kernel/signal.c124
1 files changed, 67 insertions, 57 deletions
diff --git a/kernel/signal.c b/kernel/signal.c
index 4530fc654455..e73759783dc8 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -41,6 +41,8 @@
41 41
42static struct kmem_cache *sigqueue_cachep; 42static struct kmem_cache *sigqueue_cachep;
43 43
44DEFINE_TRACE(sched_signal_send);
45
44static void __user *sig_handler(struct task_struct *t, int sig) 46static void __user *sig_handler(struct task_struct *t, int sig)
45{ 47{
46 return t->sighand->action[sig - 1].sa.sa_handler; 48 return t->sighand->action[sig - 1].sa.sa_handler;
@@ -177,6 +179,11 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
177 return sig; 179 return sig;
178} 180}
179 181
182/*
183 * allocate a new signal queue record
184 * - this may be called without locks if and only if t == current, otherwise an
185 * appopriate lock must be held to stop the target task from exiting
186 */
180static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags, 187static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
181 int override_rlimit) 188 int override_rlimit)
182{ 189{
@@ -184,11 +191,12 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
184 struct user_struct *user; 191 struct user_struct *user;
185 192
186 /* 193 /*
187 * In order to avoid problems with "switch_user()", we want to make 194 * We won't get problems with the target's UID changing under us
188 * sure that the compiler doesn't re-load "t->user" 195 * because changing it requires RCU be used, and if t != current, the
196 * caller must be holding the RCU readlock (by way of a spinlock) and
197 * we use RCU protection here
189 */ 198 */
190 user = t->user; 199 user = get_uid(__task_cred(t)->user);
191 barrier();
192 atomic_inc(&user->sigpending); 200 atomic_inc(&user->sigpending);
193 if (override_rlimit || 201 if (override_rlimit ||
194 atomic_read(&user->sigpending) <= 202 atomic_read(&user->sigpending) <=
@@ -196,12 +204,14 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
196 q = kmem_cache_alloc(sigqueue_cachep, flags); 204 q = kmem_cache_alloc(sigqueue_cachep, flags);
197 if (unlikely(q == NULL)) { 205 if (unlikely(q == NULL)) {
198 atomic_dec(&user->sigpending); 206 atomic_dec(&user->sigpending);
207 free_uid(user);
199 } else { 208 } else {
200 INIT_LIST_HEAD(&q->list); 209 INIT_LIST_HEAD(&q->list);
201 q->flags = 0; 210 q->flags = 0;
202 q->user = get_uid(user); 211 q->user = user;
203 } 212 }
204 return(q); 213
214 return q;
205} 215}
206 216
207static void __sigqueue_free(struct sigqueue *q) 217static void __sigqueue_free(struct sigqueue *q)
@@ -562,10 +572,12 @@ static int rm_from_queue(unsigned long mask, struct sigpending *s)
562 572
563/* 573/*
564 * Bad permissions for sending the signal 574 * Bad permissions for sending the signal
575 * - the caller must hold at least the RCU read lock
565 */ 576 */
566static int check_kill_permission(int sig, struct siginfo *info, 577static int check_kill_permission(int sig, struct siginfo *info,
567 struct task_struct *t) 578 struct task_struct *t)
568{ 579{
580 const struct cred *cred = current_cred(), *tcred;
569 struct pid *sid; 581 struct pid *sid;
570 int error; 582 int error;
571 583
@@ -579,8 +591,11 @@ static int check_kill_permission(int sig, struct siginfo *info,
579 if (error) 591 if (error)
580 return error; 592 return error;
581 593
582 if ((current->euid ^ t->suid) && (current->euid ^ t->uid) && 594 tcred = __task_cred(t);
583 (current->uid ^ t->suid) && (current->uid ^ t->uid) && 595 if ((cred->euid ^ tcred->suid) &&
596 (cred->euid ^ tcred->uid) &&
597 (cred->uid ^ tcred->suid) &&
598 (cred->uid ^ tcred->uid) &&
584 !capable(CAP_KILL)) { 599 !capable(CAP_KILL)) {
585 switch (sig) { 600 switch (sig) {
586 case SIGCONT: 601 case SIGCONT:
@@ -843,8 +858,9 @@ static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
843 q->info.si_signo = sig; 858 q->info.si_signo = sig;
844 q->info.si_errno = 0; 859 q->info.si_errno = 0;
845 q->info.si_code = SI_USER; 860 q->info.si_code = SI_USER;
846 q->info.si_pid = task_pid_vnr(current); 861 q->info.si_pid = task_tgid_nr_ns(current,
847 q->info.si_uid = current->uid; 862 task_active_pid_ns(t));
863 q->info.si_uid = current_uid();
848 break; 864 break;
849 case (unsigned long) SEND_SIG_PRIV: 865 case (unsigned long) SEND_SIG_PRIV:
850 q->info.si_signo = sig; 866 q->info.si_signo = sig;
@@ -1008,6 +1024,10 @@ struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long
1008 return sighand; 1024 return sighand;
1009} 1025}
1010 1026
1027/*
1028 * send signal info to all the members of a group
1029 * - the caller must hold the RCU read lock at least
1030 */
1011int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) 1031int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
1012{ 1032{
1013 unsigned long flags; 1033 unsigned long flags;
@@ -1029,8 +1049,8 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
1029/* 1049/*
1030 * __kill_pgrp_info() sends a signal to a process group: this is what the tty 1050 * __kill_pgrp_info() sends a signal to a process group: this is what the tty
1031 * control characters do (^C, ^Z etc) 1051 * control characters do (^C, ^Z etc)
1052 * - the caller must hold at least a readlock on tasklist_lock
1032 */ 1053 */
1033
1034int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp) 1054int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp)
1035{ 1055{
1036 struct task_struct *p = NULL; 1056 struct task_struct *p = NULL;
@@ -1086,6 +1106,7 @@ int kill_pid_info_as_uid(int sig, struct siginfo *info, struct pid *pid,
1086{ 1106{
1087 int ret = -EINVAL; 1107 int ret = -EINVAL;
1088 struct task_struct *p; 1108 struct task_struct *p;
1109 const struct cred *pcred;
1089 1110
1090 if (!valid_signal(sig)) 1111 if (!valid_signal(sig))
1091 return ret; 1112 return ret;
@@ -1096,9 +1117,11 @@ int kill_pid_info_as_uid(int sig, struct siginfo *info, struct pid *pid,
1096 ret = -ESRCH; 1117 ret = -ESRCH;
1097 goto out_unlock; 1118 goto out_unlock;
1098 } 1119 }
1099 if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) 1120 pcred = __task_cred(p);
1100 && (euid != p->suid) && (euid != p->uid) 1121 if ((info == SEND_SIG_NOINFO ||
1101 && (uid != p->suid) && (uid != p->uid)) { 1122 (!is_si_special(info) && SI_FROMUSER(info))) &&
1123 euid != pcred->suid && euid != pcred->uid &&
1124 uid != pcred->suid && uid != pcred->uid) {
1102 ret = -EPERM; 1125 ret = -EPERM;
1103 goto out_unlock; 1126 goto out_unlock;
1104 } 1127 }
@@ -1369,10 +1392,9 @@ int do_notify_parent(struct task_struct *tsk, int sig)
1369 */ 1392 */
1370 rcu_read_lock(); 1393 rcu_read_lock();
1371 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns); 1394 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
1395 info.si_uid = __task_cred(tsk)->uid;
1372 rcu_read_unlock(); 1396 rcu_read_unlock();
1373 1397
1374 info.si_uid = tsk->uid;
1375
1376 thread_group_cputime(tsk, &cputime); 1398 thread_group_cputime(tsk, &cputime);
1377 info.si_utime = cputime_to_jiffies(cputime.utime); 1399 info.si_utime = cputime_to_jiffies(cputime.utime);
1378 info.si_stime = cputime_to_jiffies(cputime.stime); 1400 info.si_stime = cputime_to_jiffies(cputime.stime);
@@ -1440,10 +1462,9 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
1440 */ 1462 */
1441 rcu_read_lock(); 1463 rcu_read_lock();
1442 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns); 1464 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
1465 info.si_uid = __task_cred(tsk)->uid;
1443 rcu_read_unlock(); 1466 rcu_read_unlock();
1444 1467
1445 info.si_uid = tsk->uid;
1446
1447 info.si_utime = cputime_to_clock_t(tsk->utime); 1468 info.si_utime = cputime_to_clock_t(tsk->utime);
1448 info.si_stime = cputime_to_clock_t(tsk->stime); 1469 info.si_stime = cputime_to_clock_t(tsk->stime);
1449 1470
@@ -1598,7 +1619,7 @@ void ptrace_notify(int exit_code)
1598 info.si_signo = SIGTRAP; 1619 info.si_signo = SIGTRAP;
1599 info.si_code = exit_code; 1620 info.si_code = exit_code;
1600 info.si_pid = task_pid_vnr(current); 1621 info.si_pid = task_pid_vnr(current);
1601 info.si_uid = current->uid; 1622 info.si_uid = current_uid();
1602 1623
1603 /* Let the debugger run. */ 1624 /* Let the debugger run. */
1604 spin_lock_irq(&current->sighand->siglock); 1625 spin_lock_irq(&current->sighand->siglock);
@@ -1710,7 +1731,7 @@ static int ptrace_signal(int signr, siginfo_t *info,
1710 info->si_errno = 0; 1731 info->si_errno = 0;
1711 info->si_code = SI_USER; 1732 info->si_code = SI_USER;
1712 info->si_pid = task_pid_vnr(current->parent); 1733 info->si_pid = task_pid_vnr(current->parent);
1713 info->si_uid = current->parent->uid; 1734 info->si_uid = task_uid(current->parent);
1714 } 1735 }
1715 1736
1716 /* If the (new) signal is now blocked, requeue it. */ 1737 /* If the (new) signal is now blocked, requeue it. */
@@ -1940,7 +1961,7 @@ EXPORT_SYMBOL(unblock_all_signals);
1940 * System call entry points. 1961 * System call entry points.
1941 */ 1962 */
1942 1963
1943asmlinkage long sys_restart_syscall(void) 1964SYSCALL_DEFINE0(restart_syscall)
1944{ 1965{
1945 struct restart_block *restart = &current_thread_info()->restart_block; 1966 struct restart_block *restart = &current_thread_info()->restart_block;
1946 return restart->fn(restart); 1967 return restart->fn(restart);
@@ -1993,8 +2014,8 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
1993 return error; 2014 return error;
1994} 2015}
1995 2016
1996asmlinkage long 2017SYSCALL_DEFINE4(rt_sigprocmask, int, how, sigset_t __user *, set,
1997sys_rt_sigprocmask(int how, sigset_t __user *set, sigset_t __user *oset, size_t sigsetsize) 2018 sigset_t __user *, oset, size_t, sigsetsize)
1998{ 2019{
1999 int error = -EINVAL; 2020 int error = -EINVAL;
2000 sigset_t old_set, new_set; 2021 sigset_t old_set, new_set;
@@ -2053,8 +2074,7 @@ out:
2053 return error; 2074 return error;
2054} 2075}
2055 2076
2056asmlinkage long 2077SYSCALL_DEFINE2(rt_sigpending, sigset_t __user *, set, size_t, sigsetsize)
2057sys_rt_sigpending(sigset_t __user *set, size_t sigsetsize)
2058{ 2078{
2059 return do_sigpending(set, sigsetsize); 2079 return do_sigpending(set, sigsetsize);
2060} 2080}
@@ -2125,11 +2145,9 @@ int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from)
2125 2145
2126#endif 2146#endif
2127 2147
2128asmlinkage long 2148SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
2129sys_rt_sigtimedwait(const sigset_t __user *uthese, 2149 siginfo_t __user *, uinfo, const struct timespec __user *, uts,
2130 siginfo_t __user *uinfo, 2150 size_t, sigsetsize)
2131 const struct timespec __user *uts,
2132 size_t sigsetsize)
2133{ 2151{
2134 int ret, sig; 2152 int ret, sig;
2135 sigset_t these; 2153 sigset_t these;
@@ -2202,8 +2220,7 @@ sys_rt_sigtimedwait(const sigset_t __user *uthese,
2202 return ret; 2220 return ret;
2203} 2221}
2204 2222
2205asmlinkage long 2223SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
2206sys_kill(pid_t pid, int sig)
2207{ 2224{
2208 struct siginfo info; 2225 struct siginfo info;
2209 2226
@@ -2211,7 +2228,7 @@ sys_kill(pid_t pid, int sig)
2211 info.si_errno = 0; 2228 info.si_errno = 0;
2212 info.si_code = SI_USER; 2229 info.si_code = SI_USER;
2213 info.si_pid = task_tgid_vnr(current); 2230 info.si_pid = task_tgid_vnr(current);
2214 info.si_uid = current->uid; 2231 info.si_uid = current_uid();
2215 2232
2216 return kill_something_info(sig, &info, pid); 2233 return kill_something_info(sig, &info, pid);
2217} 2234}
@@ -2228,7 +2245,7 @@ static int do_tkill(pid_t tgid, pid_t pid, int sig)
2228 info.si_errno = 0; 2245 info.si_errno = 0;
2229 info.si_code = SI_TKILL; 2246 info.si_code = SI_TKILL;
2230 info.si_pid = task_tgid_vnr(current); 2247 info.si_pid = task_tgid_vnr(current);
2231 info.si_uid = current->uid; 2248 info.si_uid = current_uid();
2232 2249
2233 rcu_read_lock(); 2250 rcu_read_lock();
2234 p = find_task_by_vpid(pid); 2251 p = find_task_by_vpid(pid);
@@ -2262,7 +2279,7 @@ static int do_tkill(pid_t tgid, pid_t pid, int sig)
2262 * exists but it's not belonging to the target process anymore. This 2279 * exists but it's not belonging to the target process anymore. This
2263 * method solves the problem of threads exiting and PIDs getting reused. 2280 * method solves the problem of threads exiting and PIDs getting reused.
2264 */ 2281 */
2265asmlinkage long sys_tgkill(pid_t tgid, pid_t pid, int sig) 2282SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig)
2266{ 2283{
2267 /* This is only valid for single tasks */ 2284 /* This is only valid for single tasks */
2268 if (pid <= 0 || tgid <= 0) 2285 if (pid <= 0 || tgid <= 0)
@@ -2274,8 +2291,7 @@ asmlinkage long sys_tgkill(pid_t tgid, pid_t pid, int sig)
2274/* 2291/*
2275 * Send a signal to only one task, even if it's a CLONE_THREAD task. 2292 * Send a signal to only one task, even if it's a CLONE_THREAD task.
2276 */ 2293 */
2277asmlinkage long 2294SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig)
2278sys_tkill(pid_t pid, int sig)
2279{ 2295{
2280 /* This is only valid for single tasks */ 2296 /* This is only valid for single tasks */
2281 if (pid <= 0) 2297 if (pid <= 0)
@@ -2284,8 +2300,8 @@ sys_tkill(pid_t pid, int sig)
2284 return do_tkill(0, pid, sig); 2300 return do_tkill(0, pid, sig);
2285} 2301}
2286 2302
2287asmlinkage long 2303SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
2288sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo) 2304 siginfo_t __user *, uinfo)
2289{ 2305{
2290 siginfo_t info; 2306 siginfo_t info;
2291 2307
@@ -2413,8 +2429,7 @@ out:
2413 2429
2414#ifdef __ARCH_WANT_SYS_SIGPENDING 2430#ifdef __ARCH_WANT_SYS_SIGPENDING
2415 2431
2416asmlinkage long 2432SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set)
2417sys_sigpending(old_sigset_t __user *set)
2418{ 2433{
2419 return do_sigpending(set, sizeof(*set)); 2434 return do_sigpending(set, sizeof(*set));
2420} 2435}
@@ -2425,8 +2440,8 @@ sys_sigpending(old_sigset_t __user *set)
2425/* Some platforms have their own version with special arguments others 2440/* Some platforms have their own version with special arguments others
2426 support only sys_rt_sigprocmask. */ 2441 support only sys_rt_sigprocmask. */
2427 2442
2428asmlinkage long 2443SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set,
2429sys_sigprocmask(int how, old_sigset_t __user *set, old_sigset_t __user *oset) 2444 old_sigset_t __user *, oset)
2430{ 2445{
2431 int error; 2446 int error;
2432 old_sigset_t old_set, new_set; 2447 old_sigset_t old_set, new_set;
@@ -2476,11 +2491,10 @@ out:
2476#endif /* __ARCH_WANT_SYS_SIGPROCMASK */ 2491#endif /* __ARCH_WANT_SYS_SIGPROCMASK */
2477 2492
2478#ifdef __ARCH_WANT_SYS_RT_SIGACTION 2493#ifdef __ARCH_WANT_SYS_RT_SIGACTION
2479asmlinkage long 2494SYSCALL_DEFINE4(rt_sigaction, int, sig,
2480sys_rt_sigaction(int sig, 2495 const struct sigaction __user *, act,
2481 const struct sigaction __user *act, 2496 struct sigaction __user *, oact,
2482 struct sigaction __user *oact, 2497 size_t, sigsetsize)
2483 size_t sigsetsize)
2484{ 2498{
2485 struct k_sigaction new_sa, old_sa; 2499 struct k_sigaction new_sa, old_sa;
2486 int ret = -EINVAL; 2500 int ret = -EINVAL;
@@ -2510,15 +2524,13 @@ out:
2510/* 2524/*
2511 * For backwards compatibility. Functionality superseded by sigprocmask. 2525 * For backwards compatibility. Functionality superseded by sigprocmask.
2512 */ 2526 */
2513asmlinkage long 2527SYSCALL_DEFINE0(sgetmask)
2514sys_sgetmask(void)
2515{ 2528{
2516 /* SMP safe */ 2529 /* SMP safe */
2517 return current->blocked.sig[0]; 2530 return current->blocked.sig[0];
2518} 2531}
2519 2532
2520asmlinkage long 2533SYSCALL_DEFINE1(ssetmask, int, newmask)
2521sys_ssetmask(int newmask)
2522{ 2534{
2523 int old; 2535 int old;
2524 2536
@@ -2538,8 +2550,7 @@ sys_ssetmask(int newmask)
2538/* 2550/*
2539 * For backwards compatibility. Functionality superseded by sigaction. 2551 * For backwards compatibility. Functionality superseded by sigaction.
2540 */ 2552 */
2541asmlinkage unsigned long 2553SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler)
2542sys_signal(int sig, __sighandler_t handler)
2543{ 2554{
2544 struct k_sigaction new_sa, old_sa; 2555 struct k_sigaction new_sa, old_sa;
2545 int ret; 2556 int ret;
@@ -2556,8 +2567,7 @@ sys_signal(int sig, __sighandler_t handler)
2556 2567
2557#ifdef __ARCH_WANT_SYS_PAUSE 2568#ifdef __ARCH_WANT_SYS_PAUSE
2558 2569
2559asmlinkage long 2570SYSCALL_DEFINE0(pause)
2560sys_pause(void)
2561{ 2571{
2562 current->state = TASK_INTERRUPTIBLE; 2572 current->state = TASK_INTERRUPTIBLE;
2563 schedule(); 2573 schedule();
@@ -2567,7 +2577,7 @@ sys_pause(void)
2567#endif 2577#endif
2568 2578
2569#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND 2579#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
2570asmlinkage long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize) 2580SYSCALL_DEFINE2(rt_sigsuspend, sigset_t __user *, unewset, size_t, sigsetsize)
2571{ 2581{
2572 sigset_t newset; 2582 sigset_t newset;
2573 2583