diff options
| author | Steve French <sfrench@us.ibm.com> | 2006-01-12 17:47:08 -0500 |
|---|---|---|
| committer | Steve French <sfrench@us.ibm.com> | 2006-01-12 17:47:08 -0500 |
| commit | 94bc2be31a01a3055ec94176e595dfe208e92d3b (patch) | |
| tree | ebfbe81c6718a6390bfa1b99c6d228237d818576 /kernel/signal.c | |
| parent | c32a0b689cb9cc160cfcd19735bbf50bb70c6ef4 (diff) | |
| parent | 58cba4650a7a414eabd2b40cc9d8e45fcdf192d9 (diff) | |
Merge with /pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'kernel/signal.c')
| -rw-r--r-- | kernel/signal.c | 138 |
1 files changed, 118 insertions, 20 deletions
diff --git a/kernel/signal.c b/kernel/signal.c index d7611f189ef7..1da2e74beb97 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <linux/posix-timers.h> | 25 | #include <linux/posix-timers.h> |
| 26 | #include <linux/signal.h> | 26 | #include <linux/signal.h> |
| 27 | #include <linux/audit.h> | 27 | #include <linux/audit.h> |
| 28 | #include <linux/capability.h> | ||
| 28 | #include <asm/param.h> | 29 | #include <asm/param.h> |
| 29 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
| 30 | #include <asm/unistd.h> | 31 | #include <asm/unistd.h> |
| @@ -329,13 +330,20 @@ void __exit_sighand(struct task_struct *tsk) | |||
| 329 | /* Ok, we're done with the signal handlers */ | 330 | /* Ok, we're done with the signal handlers */ |
| 330 | tsk->sighand = NULL; | 331 | tsk->sighand = NULL; |
| 331 | if (atomic_dec_and_test(&sighand->count)) | 332 | if (atomic_dec_and_test(&sighand->count)) |
| 332 | kmem_cache_free(sighand_cachep, sighand); | 333 | sighand_free(sighand); |
| 333 | } | 334 | } |
| 334 | 335 | ||
| 335 | void exit_sighand(struct task_struct *tsk) | 336 | void exit_sighand(struct task_struct *tsk) |
| 336 | { | 337 | { |
| 337 | write_lock_irq(&tasklist_lock); | 338 | write_lock_irq(&tasklist_lock); |
| 338 | __exit_sighand(tsk); | 339 | rcu_read_lock(); |
| 340 | if (tsk->sighand != NULL) { | ||
| 341 | struct sighand_struct *sighand = rcu_dereference(tsk->sighand); | ||
| 342 | spin_lock(&sighand->siglock); | ||
| 343 | __exit_sighand(tsk); | ||
| 344 | spin_unlock(&sighand->siglock); | ||
| 345 | } | ||
| 346 | rcu_read_unlock(); | ||
| 339 | write_unlock_irq(&tasklist_lock); | 347 | write_unlock_irq(&tasklist_lock); |
| 340 | } | 348 | } |
| 341 | 349 | ||
| @@ -345,19 +353,20 @@ void exit_sighand(struct task_struct *tsk) | |||
| 345 | void __exit_signal(struct task_struct *tsk) | 353 | void __exit_signal(struct task_struct *tsk) |
| 346 | { | 354 | { |
| 347 | struct signal_struct * sig = tsk->signal; | 355 | struct signal_struct * sig = tsk->signal; |
| 348 | struct sighand_struct * sighand = tsk->sighand; | 356 | struct sighand_struct * sighand; |
| 349 | 357 | ||
| 350 | if (!sig) | 358 | if (!sig) |
| 351 | BUG(); | 359 | BUG(); |
| 352 | if (!atomic_read(&sig->count)) | 360 | if (!atomic_read(&sig->count)) |
| 353 | BUG(); | 361 | BUG(); |
| 362 | rcu_read_lock(); | ||
| 363 | sighand = rcu_dereference(tsk->sighand); | ||
| 354 | spin_lock(&sighand->siglock); | 364 | spin_lock(&sighand->siglock); |
| 355 | posix_cpu_timers_exit(tsk); | 365 | posix_cpu_timers_exit(tsk); |
| 356 | if (atomic_dec_and_test(&sig->count)) { | 366 | if (atomic_dec_and_test(&sig->count)) { |
| 357 | posix_cpu_timers_exit_group(tsk); | 367 | posix_cpu_timers_exit_group(tsk); |
| 358 | if (tsk == sig->curr_target) | ||
| 359 | sig->curr_target = next_thread(tsk); | ||
| 360 | tsk->signal = NULL; | 368 | tsk->signal = NULL; |
| 369 | __exit_sighand(tsk); | ||
| 361 | spin_unlock(&sighand->siglock); | 370 | spin_unlock(&sighand->siglock); |
| 362 | flush_sigqueue(&sig->shared_pending); | 371 | flush_sigqueue(&sig->shared_pending); |
| 363 | } else { | 372 | } else { |
| @@ -389,9 +398,11 @@ void __exit_signal(struct task_struct *tsk) | |||
| 389 | sig->nvcsw += tsk->nvcsw; | 398 | sig->nvcsw += tsk->nvcsw; |
| 390 | sig->nivcsw += tsk->nivcsw; | 399 | sig->nivcsw += tsk->nivcsw; |
| 391 | sig->sched_time += tsk->sched_time; | 400 | sig->sched_time += tsk->sched_time; |
| 401 | __exit_sighand(tsk); | ||
| 392 | spin_unlock(&sighand->siglock); | 402 | spin_unlock(&sighand->siglock); |
| 393 | sig = NULL; /* Marker for below. */ | 403 | sig = NULL; /* Marker for below. */ |
| 394 | } | 404 | } |
| 405 | rcu_read_unlock(); | ||
| 395 | clear_tsk_thread_flag(tsk,TIF_SIGPENDING); | 406 | clear_tsk_thread_flag(tsk,TIF_SIGPENDING); |
| 396 | flush_sigqueue(&tsk->pending); | 407 | flush_sigqueue(&tsk->pending); |
| 397 | if (sig) { | 408 | if (sig) { |
| @@ -613,6 +624,33 @@ void signal_wake_up(struct task_struct *t, int resume) | |||
| 613 | * Returns 1 if any signals were found. | 624 | * Returns 1 if any signals were found. |
| 614 | * | 625 | * |
| 615 | * All callers must be holding the siglock. | 626 | * All callers must be holding the siglock. |
| 627 | * | ||
| 628 | * This version takes a sigset mask and looks at all signals, | ||
| 629 | * not just those in the first mask word. | ||
| 630 | */ | ||
| 631 | static int rm_from_queue_full(sigset_t *mask, struct sigpending *s) | ||
| 632 | { | ||
| 633 | struct sigqueue *q, *n; | ||
| 634 | sigset_t m; | ||
| 635 | |||
| 636 | sigandsets(&m, mask, &s->signal); | ||
| 637 | if (sigisemptyset(&m)) | ||
| 638 | return 0; | ||
| 639 | |||
| 640 | signandsets(&s->signal, &s->signal, mask); | ||
| 641 | list_for_each_entry_safe(q, n, &s->list, list) { | ||
| 642 | if (sigismember(mask, q->info.si_signo)) { | ||
| 643 | list_del_init(&q->list); | ||
| 644 | __sigqueue_free(q); | ||
| 645 | } | ||
| 646 | } | ||
| 647 | return 1; | ||
| 648 | } | ||
| 649 | /* | ||
| 650 | * Remove signals in mask from the pending set and queue. | ||
| 651 | * Returns 1 if any signals were found. | ||
| 652 | * | ||
| 653 | * All callers must be holding the siglock. | ||
| 616 | */ | 654 | */ |
| 617 | static int rm_from_queue(unsigned long mask, struct sigpending *s) | 655 | static int rm_from_queue(unsigned long mask, struct sigpending *s) |
| 618 | { | 656 | { |
| @@ -1080,18 +1118,29 @@ void zap_other_threads(struct task_struct *p) | |||
| 1080 | } | 1118 | } |
| 1081 | 1119 | ||
| 1082 | /* | 1120 | /* |
| 1083 | * Must be called with the tasklist_lock held for reading! | 1121 | * Must be called under rcu_read_lock() or with tasklist_lock read-held. |
| 1084 | */ | 1122 | */ |
| 1085 | int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) | 1123 | int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
| 1086 | { | 1124 | { |
| 1087 | unsigned long flags; | 1125 | unsigned long flags; |
| 1126 | struct sighand_struct *sp; | ||
| 1088 | int ret; | 1127 | int ret; |
| 1089 | 1128 | ||
| 1129 | retry: | ||
| 1090 | ret = check_kill_permission(sig, info, p); | 1130 | ret = check_kill_permission(sig, info, p); |
| 1091 | if (!ret && sig && p->sighand) { | 1131 | if (!ret && sig && (sp = rcu_dereference(p->sighand))) { |
| 1092 | spin_lock_irqsave(&p->sighand->siglock, flags); | 1132 | spin_lock_irqsave(&sp->siglock, flags); |
| 1133 | if (p->sighand != sp) { | ||
| 1134 | spin_unlock_irqrestore(&sp->siglock, flags); | ||
| 1135 | goto retry; | ||
| 1136 | } | ||
| 1137 | if ((atomic_read(&sp->count) == 0) || | ||
| 1138 | (atomic_read(&p->usage) == 0)) { | ||
| 1139 | spin_unlock_irqrestore(&sp->siglock, flags); | ||
| 1140 | return -ESRCH; | ||
| 1141 | } | ||
| 1093 | ret = __group_send_sig_info(sig, info, p); | 1142 | ret = __group_send_sig_info(sig, info, p); |
| 1094 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 1143 | spin_unlock_irqrestore(&sp->siglock, flags); |
| 1095 | } | 1144 | } |
| 1096 | 1145 | ||
| 1097 | return ret; | 1146 | return ret; |
| @@ -1136,14 +1185,21 @@ int | |||
| 1136 | kill_proc_info(int sig, struct siginfo *info, pid_t pid) | 1185 | kill_proc_info(int sig, struct siginfo *info, pid_t pid) |
| 1137 | { | 1186 | { |
| 1138 | int error; | 1187 | int error; |
| 1188 | int acquired_tasklist_lock = 0; | ||
| 1139 | struct task_struct *p; | 1189 | struct task_struct *p; |
| 1140 | 1190 | ||
| 1141 | read_lock(&tasklist_lock); | 1191 | rcu_read_lock(); |
| 1192 | if (unlikely(sig_kernel_stop(sig) || sig == SIGCONT)) { | ||
| 1193 | read_lock(&tasklist_lock); | ||
| 1194 | acquired_tasklist_lock = 1; | ||
| 1195 | } | ||
| 1142 | p = find_task_by_pid(pid); | 1196 | p = find_task_by_pid(pid); |
| 1143 | error = -ESRCH; | 1197 | error = -ESRCH; |
| 1144 | if (p) | 1198 | if (p) |
| 1145 | error = group_send_sig_info(sig, info, p); | 1199 | error = group_send_sig_info(sig, info, p); |
| 1146 | read_unlock(&tasklist_lock); | 1200 | if (unlikely(acquired_tasklist_lock)) |
| 1201 | read_unlock(&tasklist_lock); | ||
| 1202 | rcu_read_unlock(); | ||
| 1147 | return error; | 1203 | return error; |
| 1148 | } | 1204 | } |
| 1149 | 1205 | ||
| @@ -1163,8 +1219,7 @@ int kill_proc_info_as_uid(int sig, struct siginfo *info, pid_t pid, | |||
| 1163 | ret = -ESRCH; | 1219 | ret = -ESRCH; |
| 1164 | goto out_unlock; | 1220 | goto out_unlock; |
| 1165 | } | 1221 | } |
| 1166 | if ((!info || ((unsigned long)info != 1 && | 1222 | if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) |
| 1167 | (unsigned long)info != 2 && SI_FROMUSER(info))) | ||
| 1168 | && (euid != p->suid) && (euid != p->uid) | 1223 | && (euid != p->suid) && (euid != p->uid) |
| 1169 | && (uid != p->suid) && (uid != p->uid)) { | 1224 | && (uid != p->suid) && (uid != p->uid)) { |
| 1170 | ret = -EPERM; | 1225 | ret = -EPERM; |
| @@ -1355,16 +1410,54 @@ send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p) | |||
| 1355 | { | 1410 | { |
| 1356 | unsigned long flags; | 1411 | unsigned long flags; |
| 1357 | int ret = 0; | 1412 | int ret = 0; |
| 1413 | struct sighand_struct *sh; | ||
| 1358 | 1414 | ||
| 1359 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); | 1415 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); |
| 1360 | read_lock(&tasklist_lock); | 1416 | |
| 1417 | /* | ||
| 1418 | * The rcu based delayed sighand destroy makes it possible to | ||
| 1419 | * run this without tasklist lock held. The task struct itself | ||
| 1420 | * cannot go away as create_timer did get_task_struct(). | ||
| 1421 | * | ||
| 1422 | * We return -1, when the task is marked exiting, so | ||
| 1423 | * posix_timer_event can redirect it to the group leader | ||
| 1424 | */ | ||
| 1425 | rcu_read_lock(); | ||
| 1361 | 1426 | ||
| 1362 | if (unlikely(p->flags & PF_EXITING)) { | 1427 | if (unlikely(p->flags & PF_EXITING)) { |
| 1363 | ret = -1; | 1428 | ret = -1; |
| 1364 | goto out_err; | 1429 | goto out_err; |
| 1365 | } | 1430 | } |
| 1366 | 1431 | ||
| 1367 | spin_lock_irqsave(&p->sighand->siglock, flags); | 1432 | retry: |
| 1433 | sh = rcu_dereference(p->sighand); | ||
| 1434 | |||
| 1435 | spin_lock_irqsave(&sh->siglock, flags); | ||
| 1436 | if (p->sighand != sh) { | ||
| 1437 | /* We raced with exec() in a multithreaded process... */ | ||
| 1438 | spin_unlock_irqrestore(&sh->siglock, flags); | ||
| 1439 | goto retry; | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | /* | ||
| 1443 | * We do the check here again to handle the following scenario: | ||
| 1444 | * | ||
| 1445 | * CPU 0 CPU 1 | ||
| 1446 | * send_sigqueue | ||
| 1447 | * check PF_EXITING | ||
| 1448 | * interrupt exit code running | ||
| 1449 | * __exit_signal | ||
| 1450 | * lock sighand->siglock | ||
| 1451 | * unlock sighand->siglock | ||
| 1452 | * lock sh->siglock | ||
| 1453 | * add(tsk->pending) flush_sigqueue(tsk->pending) | ||
| 1454 | * | ||
| 1455 | */ | ||
| 1456 | |||
| 1457 | if (unlikely(p->flags & PF_EXITING)) { | ||
| 1458 | ret = -1; | ||
| 1459 | goto out; | ||
| 1460 | } | ||
| 1368 | 1461 | ||
| 1369 | if (unlikely(!list_empty(&q->list))) { | 1462 | if (unlikely(!list_empty(&q->list))) { |
| 1370 | /* | 1463 | /* |
| @@ -1388,9 +1481,9 @@ send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p) | |||
| 1388 | signal_wake_up(p, sig == SIGKILL); | 1481 | signal_wake_up(p, sig == SIGKILL); |
| 1389 | 1482 | ||
| 1390 | out: | 1483 | out: |
| 1391 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 1484 | spin_unlock_irqrestore(&sh->siglock, flags); |
| 1392 | out_err: | 1485 | out_err: |
| 1393 | read_unlock(&tasklist_lock); | 1486 | rcu_read_unlock(); |
| 1394 | 1487 | ||
| 1395 | return ret; | 1488 | return ret; |
| 1396 | } | 1489 | } |
| @@ -1402,7 +1495,9 @@ send_group_sigqueue(int sig, struct sigqueue *q, struct task_struct *p) | |||
| 1402 | int ret = 0; | 1495 | int ret = 0; |
| 1403 | 1496 | ||
| 1404 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); | 1497 | BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); |
| 1498 | |||
| 1405 | read_lock(&tasklist_lock); | 1499 | read_lock(&tasklist_lock); |
| 1500 | /* Since it_lock is held, p->sighand cannot be NULL. */ | ||
| 1406 | spin_lock_irqsave(&p->sighand->siglock, flags); | 1501 | spin_lock_irqsave(&p->sighand->siglock, flags); |
| 1407 | handle_stop_signal(sig, p); | 1502 | handle_stop_signal(sig, p); |
| 1408 | 1503 | ||
| @@ -1436,7 +1531,7 @@ send_group_sigqueue(int sig, struct sigqueue *q, struct task_struct *p) | |||
| 1436 | out: | 1531 | out: |
| 1437 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | 1532 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
| 1438 | read_unlock(&tasklist_lock); | 1533 | read_unlock(&tasklist_lock); |
| 1439 | return(ret); | 1534 | return ret; |
| 1440 | } | 1535 | } |
| 1441 | 1536 | ||
| 1442 | /* | 1537 | /* |
| @@ -2338,6 +2433,7 @@ int | |||
| 2338 | do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact) | 2433 | do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact) |
| 2339 | { | 2434 | { |
| 2340 | struct k_sigaction *k; | 2435 | struct k_sigaction *k; |
| 2436 | sigset_t mask; | ||
| 2341 | 2437 | ||
| 2342 | if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig))) | 2438 | if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig))) |
| 2343 | return -EINVAL; | 2439 | return -EINVAL; |
| @@ -2385,9 +2481,11 @@ do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact) | |||
| 2385 | *k = *act; | 2481 | *k = *act; |
| 2386 | sigdelsetmask(&k->sa.sa_mask, | 2482 | sigdelsetmask(&k->sa.sa_mask, |
| 2387 | sigmask(SIGKILL) | sigmask(SIGSTOP)); | 2483 | sigmask(SIGKILL) | sigmask(SIGSTOP)); |
| 2388 | rm_from_queue(sigmask(sig), &t->signal->shared_pending); | 2484 | sigemptyset(&mask); |
| 2485 | sigaddset(&mask, sig); | ||
| 2486 | rm_from_queue_full(&mask, &t->signal->shared_pending); | ||
| 2389 | do { | 2487 | do { |
| 2390 | rm_from_queue(sigmask(sig), &t->pending); | 2488 | rm_from_queue_full(&mask, &t->pending); |
| 2391 | recalc_sigpending_tsk(t); | 2489 | recalc_sigpending_tsk(t); |
| 2392 | t = next_thread(t); | 2490 | t = next_thread(t); |
| 2393 | } while (t != current); | 2491 | } while (t != current); |
