Commit f9ee228bdc82cff8ea1ec00fd952890e00679dd8
Committed by
Linus Torvalds
1 parent
834d216e1f
Exists in
master
and in
4 other branches
signalfd: make it group-wide, fix posix-timers scheduling
With this patch any thread can dequeue its own private signals via signalfd, even if it was created by another sub-thread. To do so, we pass "current" to dequeue_signal() if the caller is from the same thread group. This also fixes the scheduling of posix timers broken by the previous patch. If the caller doesn't belong to this thread group, we can't handle __SI_TIMER case properly anyway. Perhaps we should forbid the cross-process signalfd usage and convert ctx->tsk to ctx->sighand. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Davide Libenzi <davidel@xmailserver.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: Michael Kerrisk <mtk-manpages@gmx.net> Cc: Roland McGrath <roland@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 12 additions and 11 deletions Side-by-side Diff
fs/exec.c
... | ... | @@ -780,18 +780,12 @@ |
780 | 780 | int count; |
781 | 781 | |
782 | 782 | /* |
783 | - * Tell all the sighand listeners that this sighand has | |
784 | - * been detached. The signalfd_detach() function grabs the | |
785 | - * sighand lock, if signal listeners are present on the sighand. | |
786 | - */ | |
787 | - signalfd_detach(tsk); | |
788 | - | |
789 | - /* | |
790 | 783 | * If we don't share sighandlers, then we aren't sharing anything |
791 | 784 | * and we can just re-use it all. |
792 | 785 | */ |
793 | 786 | if (atomic_read(&oldsighand->count) <= 1) { |
794 | 787 | BUG_ON(atomic_read(&sig->count) != 1); |
788 | + signalfd_detach(tsk); | |
795 | 789 | exit_itimers(sig); |
796 | 790 | return 0; |
797 | 791 | } |
... | ... | @@ -930,6 +924,7 @@ |
930 | 924 | sig->flags = 0; |
931 | 925 | |
932 | 926 | no_thread_group: |
927 | + signalfd_detach(tsk); | |
933 | 928 | exit_itimers(sig); |
934 | 929 | if (leader) |
935 | 930 | release_task(leader); |
fs/signalfd.c
... | ... | @@ -56,12 +56,18 @@ |
56 | 56 | sighand = lock_task_sighand(lk->tsk, &lk->flags); |
57 | 57 | rcu_read_unlock(); |
58 | 58 | |
59 | - if (sighand && !ctx->tsk) { | |
59 | + if (!sighand) | |
60 | + return 0; | |
61 | + | |
62 | + if (!ctx->tsk) { | |
60 | 63 | unlock_task_sighand(lk->tsk, &lk->flags); |
61 | - sighand = NULL; | |
64 | + return 0; | |
62 | 65 | } |
63 | 66 | |
64 | - return sighand != NULL; | |
67 | + if (lk->tsk->tgid == current->tgid) | |
68 | + lk->tsk = current; | |
69 | + | |
70 | + return 1; | |
65 | 71 | } |
66 | 72 | |
67 | 73 | static void signalfd_unlock(struct signalfd_lockctx *lk) |
... | ... | @@ -331,7 +337,7 @@ |
331 | 337 | |
332 | 338 | init_waitqueue_head(&ctx->wqh); |
333 | 339 | ctx->sigmask = sigmask; |
334 | - ctx->tsk = current; | |
340 | + ctx->tsk = current->group_leader; | |
335 | 341 | |
336 | 342 | sighand = current->sighand; |
337 | 343 | /* |