* [patch][bugfix] epoll cross-thread deletion fix ...
@ 2003-03-26 20:20 Davide Libenzi
2003-03-27 17:19 ` Marc-Christian Petersen
0 siblings, 1 reply; 3+ messages in thread
From: Davide Libenzi @ 2003-03-26 20:20 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Linus Torvalds
This fixes a bug that might happen having a thread doing epoll_wait() with
another thread doing epoll_ctl(EPOLL_CTL_DEL) and close(). The fast check
inside eventpoll_release() is good to not effect performace of code not
using epoll, but it requires get_file() to be called ( that can be avoided
by dropping the fast check ). I opted to keep the fast check and to have
epoll to call get_file() before the event send loop. I tested it on UP and
2SMP with a bug-exploiting program provided by @pivia.com ( thx to them )
and it looks fine. I also update the 2.4.20 epoll patch with this fix :
http://www.xmailserver.org/linux-patches/epoll-lt-2.4.20-0.5.diff
- Davide
eventpoll.c | 26 +++++++++++++++++++++++++-
1 files changed, 25 insertions, 1 deletion
diff -Nru linux-2.5.66.vanilla/fs/eventpoll.c linux-2.5.66.epoll/fs/eventpoll.c
--- linux-2.5.66.vanilla/fs/eventpoll.c Mon Mar 24 14:00:19 2003
+++ linux-2.5.66.epoll/fs/eventpoll.c Tue Mar 25 19:00:50 2003
@@ -1342,6 +1342,13 @@
ep_use_epitem(epi);
/*
+ * We need to increase the usage count of the "struct file" because
+ * another thread might call close() on this target and make the file
+ * to vanish before we will be able to call f_op->poll().
+ */
+ get_file(epi->file);
+
+ /*
* This is initialized in this way so that the default
* behaviour of the reinjecting code will be to push back
* the item inside the ready list.
@@ -1386,6 +1393,14 @@
revents = epi->file->f_op->poll(epi->file, NULL);
/*
+ * Release the file usage before checking the event mask.
+ * In case this call will lead to the file removal, its
+ * ->event.events member has been already set to zero and
+ * this will make the event to be dropped.
+ */
+ fput(epi->file);
+
+ /*
* Set the return event set for the current file descriptor.
* Note that only the task task was successfully able to link
* the item to its "txlist" will write this field.
@@ -1398,8 +1413,17 @@
eventbuf++;
if (eventbuf == EP_MAX_BUF_EVENTS) {
if (__copy_to_user(&events[eventcnt], event,
- eventbuf * sizeof(struct epoll_event)))
+ eventbuf * sizeof(struct epoll_event))) {
+ /*
+ * We need to complete the loop to decrement the file
+ * usage before returning from this function.
+ */
+ for (lnk = lnk->next; lnk != txlist; lnk = lnk->next) {
+ epi = list_entry(lnk, struct epitem, txlink);
+ fput(epi->file);
+ }
return -EFAULT;
+ }
eventcnt += eventbuf;
eventbuf = 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch][bugfix] epoll cross-thread deletion fix ...
2003-03-26 20:20 [patch][bugfix] epoll cross-thread deletion fix Davide Libenzi
@ 2003-03-27 17:19 ` Marc-Christian Petersen
2003-03-27 18:03 ` Davide Libenzi
0 siblings, 1 reply; 3+ messages in thread
From: Marc-Christian Petersen @ 2003-03-27 17:19 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Davide Libenzi
On Wednesday 26 March 2003 21:20, Davide Libenzi wrote:
Hi Davide,
> This fixes a bug that might happen having a thread doing epoll_wait() with
> another thread doing epoll_ctl(EPOLL_CTL_DEL) and close(). The fast check
> inside eventpoll_release() is good to not effect performace of code not
> using epoll, but it requires get_file() to be called ( that can be avoided
> by dropping the fast check ). I opted to keep the fast check and to have
> epoll to call get_file() before the event send loop. I tested it on UP and
> 2SMP with a bug-exploiting program provided by @pivia.com ( thx to them )
> and it looks fine. I also update the 2.4.20 epoll patch with this fix :
>
> http://www.xmailserver.org/linux-patches/epoll-lt-2.4.20-0.5.diff
so this is v0.63?
ciao, Marc
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch][bugfix] epoll cross-thread deletion fix ...
2003-03-27 17:19 ` Marc-Christian Petersen
@ 2003-03-27 18:03 ` Davide Libenzi
0 siblings, 0 replies; 3+ messages in thread
From: Davide Libenzi @ 2003-03-27 18:03 UTC (permalink / raw)
To: Marc-Christian Petersen; +Cc: Linux Kernel Mailing List
On Thu, 27 Mar 2003, Marc-Christian Petersen wrote:
> On Wednesday 26 March 2003 21:20, Davide Libenzi wrote:
>
> Hi Davide,
>
> > This fixes a bug that might happen having a thread doing epoll_wait() with
> > another thread doing epoll_ctl(EPOLL_CTL_DEL) and close(). The fast check
> > inside eventpoll_release() is good to not effect performace of code not
> > using epoll, but it requires get_file() to be called ( that can be avoided
> > by dropping the fast check ). I opted to keep the fast check and to have
> > epoll to call get_file() before the event send loop. I tested it on UP and
> > 2SMP with a bug-exploiting program provided by @pivia.com ( thx to them )
> > and it looks fine. I also update the 2.4.20 epoll patch with this fix :
> >
> > http://www.xmailserver.org/linux-patches/epoll-lt-2.4.20-0.5.diff
> so this is v0.63?
Ok, I messed up with namings :) Yes, it'll be 0.63 ...
- Davide
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-03-27 17:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-26 20:20 [patch][bugfix] epoll cross-thread deletion fix Davide Libenzi
2003-03-27 17:19 ` Marc-Christian Petersen
2003-03-27 18:03 ` Davide Libenzi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®