]> Git Repo - linux.git/commitdiff
epoll: fix use-after-free in eventpoll_release_file
authorKonstantin Khlebnikov <[email protected]>
Tue, 17 Jun 2014 02:58:05 +0000 (06:58 +0400)
committerLinus Torvalds <[email protected]>
Tue, 17 Jun 2014 03:21:59 +0000 (17:21 -1000)
This fixes use-after-free of epi->fllink.next inside list loop macro.
This loop actually releases elements in the body.  The list is
rcu-protected but here we cannot hold rcu_read_lock because we need to
lock mutex inside.

The 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.

The bug was introduced by ae10b2b4eb01 ("epoll: optimize EPOLL_CTL_DEL
using rcu")

Signed-off-by: Konstantin Khlebnikov <[email protected]>
Reported-by: Cyrill Gorcunov <[email protected]>
Cc: Stable <[email protected]> # 3.13+
Cc: Sasha Levin <[email protected]>
Cc: Jason Baron <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/eventpoll.c

index b73e0621ce9e79eaf3a5d67cbb28c0fbeb9a99f3..b10b48c2a7afaf859f2b508d5bca784abfe870ac 100644 (file)
@@ -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);
This page took 0.067838 seconds and 4 git commands to generate.