aboutsummaryrefslogtreecommitdiffstats
path: root/fs/signalfd.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2012-02-24 20:07:29 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-29 16:34:35 -0800
commitd10e3b2952f0df0f23896e32ed54a5a6c916058e (patch)
tree8856b6b0cd68cfd6cdfb3f1f165af3f9efc44512 /fs/signalfd.c
parent391d7bfe9ce7a08a700f1ff3dc950a347b23e3cb (diff)
downloadkernel_samsung_smdk4412-d10e3b2952f0df0f23896e32ed54a5a6c916058e.zip
kernel_samsung_smdk4412-d10e3b2952f0df0f23896e32ed54a5a6c916058e.tar.gz
kernel_samsung_smdk4412-d10e3b2952f0df0f23896e32ed54a5a6c916058e.tar.bz2
epoll: ep_unregister_pollwait() can use the freed pwq->whead
commit 971316f0503a5c50633d07b83b6db2f15a3a5b00 upstream. signalfd_cleanup() ensures that ->signalfd_wqh is not used, but this is not enough. eppoll_entry->whead still points to the memory we are going to free, ep_unregister_pollwait()->remove_wait_queue() is obviously unsafe. Change ep_poll_callback(POLLFREE) to set eppoll_entry->whead = NULL, change ep_unregister_pollwait() to check pwq->whead != NULL under rcu_read_lock() before remove_wait_queue(). We add the new helper, ep_remove_wait_queue(), for this. This works because sighand_cachep is SLAB_DESTROY_BY_RCU and because ->signalfd_wqh is initialized in sighand_ctor(), not in copy_sighand. ep_unregister_pollwait()->remove_wait_queue() can play with already freed and potentially reused ->sighand, but this is fine. This memory must have the valid ->signalfd_wqh until rcu_read_unlock(). Reported-by: Maxime Bizon <mbizon@freebox.fr> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/signalfd.c')
-rw-r--r--fs/signalfd.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 79c1eea..7ae2a57 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -33,7 +33,11 @@
void signalfd_cleanup(struct sighand_struct *sighand)
{
wait_queue_head_t *wqh = &sighand->signalfd_wqh;
-
+ /*
+ * The lockless check can race with remove_wait_queue() in progress,
+ * but in this case its caller should run under rcu_read_lock() and
+ * sighand_cachep is SLAB_DESTROY_BY_RCU, we can safely return.
+ */
if (likely(!waitqueue_active(wqh)))
return;