summaryrefslogtreecommitdiffstats
path: root/fs/eventpoll.c
diff options
context:
space:
mode:
authorKonstantin Khlebnikov <koct9i@gmail.com>2014-06-16 22:58:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-16 23:21:59 -0400
commitebe06187bf2aec10d537ce4595e416035367d703 (patch)
treea428632381694d7de07944ea5398df4dfb20f0e1 /fs/eventpoll.c
parent68986c9f0f4552c34c248501eb0c690553866d6e (diff)
epoll: fix use-after-free in eventpoll_release_file
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 <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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r--fs/eventpoll.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index b73e0621ce9e..b10b48c2a7af 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -910,7 +910,7 @@ static const struct file_operations eventpoll_fops = {
910void eventpoll_release_file(struct file *file) 910void eventpoll_release_file(struct file *file)
911{ 911{
912 struct eventpoll *ep; 912 struct eventpoll *ep;
913 struct epitem *epi; 913 struct epitem *epi, *next;
914 914
915 /* 915 /*
916 * We don't want to get "file->f_lock" because it is not 916 * We don't want to get "file->f_lock" because it is not
@@ -926,7 +926,7 @@ void eventpoll_release_file(struct file *file)
926 * Besides, ep_remove() acquires the lock, so we can't hold it here. 926 * Besides, ep_remove() acquires the lock, so we can't hold it here.
927 */ 927 */
928 mutex_lock(&epmutex); 928 mutex_lock(&epmutex);
929 list_for_each_entry_rcu(epi, &file->f_ep_links, fllink) { 929 list_for_each_entry_safe(epi, next, &file->f_ep_links, fllink) {
930 ep = epi->ep; 930 ep = epi->ep;
931 mutex_lock_nested(&ep->mtx, 0); 931 mutex_lock_nested(&ep->mtx, 0);
932 ep_remove(ep, epi); 932 ep_remove(ep, epi);