public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] epoll: fix use-after-free in eventpoll_release_file
@ 2014-06-17  2:58 Konstantin Khlebnikov
  2014-06-17  3:02 ` Konstantin Khlebnikov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2014-06-17  2:58 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel
  Cc: Cyrill Gorcunov, Sasha Levin, Jason Baron, Linus Torvalds, Stable

This fixes use-after-free of epi->fllink.next inside list loop macro.
This loop actually releases elements in the body. List is rcu-protected
but here we cannot hold rcu_read_lock because we need to lock mutex inside.

Obvious solution is to use list_for_each_entry_safe(). RCU-ness isn't essential
because nobody can change this list under us, it's final fput for this file.

Bug is here since ae10b2b4eb01bedc91d29d5c5bb9e416fd806c40
("epoll: optimize EPOLL_CTL_DEL using rcu")

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Stable <stable@vger.kernel.org> # 3.13+
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Jason Baron <jbaron@akamai.com>
---
 fs/eventpoll.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index b73e062..b10b48c 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -910,7 +910,7 @@ static const struct file_operations eventpoll_fops = {
 void eventpoll_release_file(struct file *file)
 {
 	struct eventpoll *ep;
-	struct epitem *epi;
+	struct epitem *epi, *next;
 
 	/*
 	 * We don't want to get "file->f_lock" because it is not
@@ -926,7 +926,7 @@ void eventpoll_release_file(struct file *file)
 	 * Besides, ep_remove() acquires the lock, so we can't hold it here.
 	 */
 	mutex_lock(&epmutex);
-	list_for_each_entry_rcu(epi, &file->f_ep_links, fllink) {
+	list_for_each_entry_safe(epi, next, &file->f_ep_links, fllink) {
 		ep = epi->ep;
 		mutex_lock_nested(&ep->mtx, 0);
 		ep_remove(ep, epi);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-17 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17  2:58 [PATCH] epoll: fix use-after-free in eventpoll_release_file Konstantin Khlebnikov
2014-06-17  3:02 ` Konstantin Khlebnikov
2014-06-17  5:50 ` Cyrill Gorcunov
2014-06-17 16:40 ` Jason Baron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox