* [PATCH] epoll_wait: fix EINTR leak
@ 2013-06-24 15:31 Denys Vlasenko
2013-06-24 17:08 ` Oleg Nesterov
0 siblings, 1 reply; 3+ messages in thread
From: Denys Vlasenko @ 2013-06-24 15:31 UTC (permalink / raw)
To: linux-kernel; +Cc: Denys Vlasenko, Oleg Nesterov
Usage of EINTR is wrong. For one, it causes epoll_wait
to spuriously return with EINTR on ptrace attach.
One of ERESTARTfoo's should be used.
By analogy with poll syscall family, epoll_wait should be interrupted
by signals regardless of SA_RESTART, thus ERESTARTNOHAND is used,
not ERESTARTSYS.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Oleg Nesterov <oleg@redhat.com>
---
fs/eventpoll.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 0cff4434..08f8076 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1598,7 +1598,7 @@ fetch_events:
if (ep_events_available(ep) || timed_out)
break;
if (signal_pending(current)) {
- res = -EINTR;
+ res = -ERESTARTNOHAND;
break;
}
@@ -1990,7 +1990,7 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
* the way back to userspace, before the signal mask is restored.
*/
if (sigmask) {
- if (error == -EINTR) {
+ if (error == -ERESTARTNOHAND) {
memcpy(¤t->saved_sigmask, &sigsaved,
sizeof(sigsaved));
set_restore_sigmask();
@@ -2035,7 +2035,7 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
* the way back to userspace, before the signal mask is restored.
*/
if (sigmask) {
- if (err == -EINTR) {
+ if (err == -ERESTARTNOHAND) {
memcpy(¤t->saved_sigmask, &sigsaved,
sizeof(sigsaved));
set_restore_sigmask();
--
1.8.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] epoll_wait: fix EINTR leak
2013-06-24 15:31 [PATCH] epoll_wait: fix EINTR leak Denys Vlasenko
@ 2013-06-24 17:08 ` Oleg Nesterov
2013-06-24 18:39 ` Oleg Nesterov
0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2013-06-24 17:08 UTC (permalink / raw)
To: Denys Vlasenko; +Cc: linux-kernel
On 06/24, Denys Vlasenko wrote:
>
> Usage of EINTR is wrong.
I agree, this is not nice. However "fix EINTR leak" doesn't look
accurate, -EINTR is fine as an error code. Just the syscall should
restart if possible.
> --- a/fs/eventpoll.c
> +++ b/fs/eventpoll.c
> @@ -1598,7 +1598,7 @@ fetch_events:
> if (ep_events_available(ep) || timed_out)
> break;
> if (signal_pending(current)) {
> - res = -EINTR;
> + res = -ERESTARTNOHAND;
This and other similar changes do look right.
Say, sys_epoll_wait(). With this patch it can sleep, then return
ERESTARTNOHAND.
And we restart it with the same timeout again. If you want to
make it restartable, you need ERESTART_RESTARTBLOCK and
do_restart_epoll_wait() which we do not have.
See for example sys_poll() which implements this logic.
Oleg.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] epoll_wait: fix EINTR leak
2013-06-24 17:08 ` Oleg Nesterov
@ 2013-06-24 18:39 ` Oleg Nesterov
0 siblings, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2013-06-24 18:39 UTC (permalink / raw)
To: Denys Vlasenko; +Cc: linux-kernel
On 06/24, Oleg Nesterov wrote:
>
> On 06/24, Denys Vlasenko wrote:
> >
> > Usage of EINTR is wrong.
>
> I agree, this is not nice. However "fix EINTR leak" doesn't look
> accurate, -EINTR is fine as an error code. Just the syscall should
> restart if possible.
>
> > --- a/fs/eventpoll.c
> > +++ b/fs/eventpoll.c
> > @@ -1598,7 +1598,7 @@ fetch_events:
> > if (ep_events_available(ep) || timed_out)
> > break;
> > if (signal_pending(current)) {
> > - res = -EINTR;
> > + res = -ERESTARTNOHAND;
>
> This and other similar changes do look right.
>
> Say, sys_epoll_wait(). With this patch it can sleep, then return
> ERESTARTNOHAND.
>
> And we restart it with the same timeout again. If you want to
> make it restartable, you need ERESTART_RESTARTBLOCK and
> do_restart_epoll_wait() which we do not have.
>
> See for example sys_poll() which implements this logic.
But, to avoid the confusion, please note that this change won't
make it restartable wrt SA_RESTART. But it will help PTRACE_ATTACH
or PTRACE_INTERRUPT or other "spurious" signal.
We simply can't do this because there is no way to update
"timeout" later if the task actually returns to user-mode.
Oleg.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-24 18:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-24 15:31 [PATCH] epoll_wait: fix EINTR leak Denys Vlasenko
2013-06-24 17:08 ` Oleg Nesterov
2013-06-24 18:39 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).