From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Roland McGrath <roland@hack.frob.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] exec: make de_thread() killable
Date: Mon, 8 Oct 2012 19:08:44 +0200 [thread overview]
Message-ID: <20121008170844.GB3259@redhat.com> (raw)
In-Reply-To: <20121008170812.GA3259@redhat.com>
Change de_thread() to use KILLABLE rather than UNINTERRUPTIBLE
while waiting for other threads. The only complication is that
we should clear ->group_exit_task and ->notify_count before we
return, and we should do this under tasklist_lock. -EAGAIN is
used to match the initial signal_group_exit() check/return, it
doesn't really matter.
This fixes the (unlikely) race with coredump. de_thread() checks
signal_group_exit() before it starts to kill the subthreads, but
this can't help if another CLONE_VM (but non CLONE_THREAD) task
starts the coredumping after de_thread() unlocks ->siglock. In
this case the killed sub-thread can block in exit_mm() waiting
for coredump_finish(), execing thread waits for that sub-thead,
and execing thread waits for execing thread. Deadlock.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
fs/exec.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -878,9 +878,11 @@ static int de_thread(struct task_struct
sig->notify_count--;
while (sig->notify_count) {
- __set_current_state(TASK_UNINTERRUPTIBLE);
+ __set_current_state(TASK_KILLABLE);
spin_unlock_irq(lock);
schedule();
+ if (unlikely(__fatal_signal_pending(tsk)))
+ goto killed;
spin_lock_irq(lock);
}
spin_unlock_irq(lock);
@@ -898,9 +900,11 @@ static int de_thread(struct task_struct
write_lock_irq(&tasklist_lock);
if (likely(leader->exit_state))
break;
- __set_current_state(TASK_UNINTERRUPTIBLE);
+ __set_current_state(TASK_KILLABLE);
write_unlock_irq(&tasklist_lock);
schedule();
+ if (unlikely(__fatal_signal_pending(tsk)))
+ goto killed;
}
/*
@@ -994,6 +998,14 @@ no_thread_group:
BUG_ON(!thread_group_leader(tsk));
return 0;
+
+killed:
+ /* protects against exit_notify() and __exit_signal() */
+ read_lock(&tasklist_lock);
+ sig->group_exit_task = NULL;
+ sig->notify_count = 0;
+ read_unlock(&tasklist_lock);
+ return -EAGAIN;
}
char *get_task_comm(char *buf, struct task_struct *tsk)
next parent reply other threads:[~2012-10-08 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CA+OH3v09PR9d=qKL4DNUYu_HYFY1CJxcB6DSUXoNp8BhB7k1-w@mail.gmail.com>
[not found] ` <CA+55aFzczRxYCXPsNs9u9G=Ch770+f2f--Dyw47m5a8BRoz9TA@mail.gmail.com>
[not found] ` <CA+OH3v1JKugp0PVOsHYrZ9wGS3oCDBMthMUeSgA6MPx_VDExQw@mail.gmail.com>
[not found] ` <CA+55aFy2t=pk07WO0ob3tUUYq_X_FhpPdNHZwQR6ZthA=8K5fA@mail.gmail.com>
[not found] ` <CA+OH3v3trHzrRdMFvccDx244jpWOxSRrv+kSCoMh=7ir-cqKCw@mail.gmail.com>
[not found] ` <CA+55aFwbKMs6DFV9ZvuSLCKx+TESMfR8raDAYU0=b8uuyZRWuQ@mail.gmail.com>
[not found] ` <CA+55aFxfJpSQ5VSx3L_xeHfTb1jqte9xAKLsj10J+pW-YS+SSw@mail.gmail.com>
[not found] ` <20120920153522.GA15426@redhat.com>
[not found] ` <20121008170812.GA3259@redhat.com>
2012-10-08 17:08 ` Oleg Nesterov [this message]
2012-10-08 17:13 ` [PATCH 1/1] exec: make de_thread() killable Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121008170844.GB3259@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@hack.frob.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.