History

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")

Konstantin Khlebnikov committed 12 years ago

Commit ebe06181 parent 68986c91 file · +2 −2Browse files

Unified · Split

fs/eventpoll.c+2−2
@@ -910,7 +910,7 @@ static const struct file_operations eventpoll_fops = { · 909 unmodified lines
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 not916 * We don't want to get "file->f_lock" because it is not
@@ -926,7 +926,7 @@ void eventpoll_release_file(struct file *file) · 9 unmodified lines
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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t