aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/signal.c
diff options
context:
space:
mode:
authorJulien Tinnes <jln@google.com>2011-03-18 18:05:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-21 17:23:43 -0400
commitda48524eb20662618854bb3df2db01fc65f3070c (patch)
tree0e9a9aa0c091e96f110a6ef121f0b31f99491325 /kernel/signal.c
parentb52307ca144881bf9ef1c2610b3f1911472eb467 (diff)
Prevent rt_sigqueueinfo and rt_tgsigqueueinfo from spoofing the signal code
Userland should be able to trust the pid and uid of the sender of a signal if the si_code is SI_TKILL. Unfortunately, the kernel has historically allowed sigqueueinfo() to send any si_code at all (as long as it was negative - to distinguish it from kernel-generated signals like SIGILL etc), so it could spoof a SI_TKILL with incorrect siginfo values. Happily, it looks like glibc has always set si_code to the appropriate SI_QUEUE, so there are probably no actual user code that ever uses anything but the appropriate SI_QUEUE flag. So just tighten the check for si_code (we used to allow any negative value), and add a (one-time) warning in case there are binaries out there that might depend on using other si_code values. Signed-off-by: Julien Tinnes <jln@google.com> Acked-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/signal.c')
-rw-r--r--kernel/signal.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/kernel/signal.c b/kernel/signal.c
index 4e3cff10fdce..31751868de88 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2421,9 +2421,13 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
2421 return -EFAULT; 2421 return -EFAULT;
2422 2422
2423 /* Not even root can pretend to send signals from the kernel. 2423 /* Not even root can pretend to send signals from the kernel.
2424 Nor can they impersonate a kill(), which adds source info. */ 2424 * Nor can they impersonate a kill()/tgkill(), which adds source info.
2425 if (info.si_code >= 0) 2425 */
2426 if (info.si_code != SI_QUEUE) {
2427 /* We used to allow any < 0 si_code */
2428 WARN_ON_ONCE(info.si_code < 0);
2426 return -EPERM; 2429 return -EPERM;
2430 }
2427 info.si_signo = sig; 2431 info.si_signo = sig;
2428 2432
2429 /* POSIX.1b doesn't mention process groups. */ 2433 /* POSIX.1b doesn't mention process groups. */
@@ -2437,9 +2441,13 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info)
2437 return -EINVAL; 2441 return -EINVAL;
2438 2442
2439 /* Not even root can pretend to send signals from the kernel. 2443 /* Not even root can pretend to send signals from the kernel.
2440 Nor can they impersonate a kill(), which adds source info. */ 2444 * Nor can they impersonate a kill()/tgkill(), which adds source info.
2441 if (info->si_code >= 0) 2445 */
2446 if (info->si_code != SI_QUEUE) {
2447 /* We used to allow any < 0 si_code */
2448 WARN_ON_ONCE(info->si_code < 0);
2442 return -EPERM; 2449 return -EPERM;
2450 }
2443 info->si_signo = sig; 2451 info->si_signo = sig;
2444 2452
2445 return do_send_specific(tgid, pid, sig, info); 2453 return do_send_specific(tgid, pid, sig, info);