eventpoll: Prevent hang in epoll_wait
PATCH 1/1 eventpoll: Prevent hang in epoll_wait
In commit 0a65bc27bd64 ("eventpoll: Set epoll timeout if it's in the future"), a bug was introduced causing the loop in ep_poll to hang under certain circumstances.
When the timeout is non-NULL and ep_schedule_timeout returns false, the flag timed_out was not set to true. This causes a hang.
Adjust the logic and set timed_out, if needed, fixing the original code.
--- fs/eventpoll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/eventpoll.c +3 -1
@@ -2111,7 +2111,9 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,write_unlock_irq (&ep->lock); -if (!eavail &&ep_schedule_timeout (to)) +if (!ep_schedule_timeout (to)) + timed_out =1 ; +else if (!eavail) timed_out = !schedule_hrtimeout_range (to, slack,HRTIMER_MODE_ABS );__set_current_state (TASK_RUNNING );
base-commit: f520bed25d17bb31c2d2d72b0a785b593a4e3179
Signature · 1 line
2.43.0
Quoted 9 lines · Joe Damato
In commit
0a65bc27bd64("eventpoll: Set epoll timeout if it's in the future"), a bug was introduced causing the loop inep_pollto hang under certain circumstances.When the timeout is non-NULL and
ep_schedule_timeoutreturns false, the flagtimed_outwas not set to true. This causes a hang.Adjust the logic and set
timed_out, if needed, fixing the original code.
Quoted 9 lines
Reported-by Christian Brauner <[email protected]>Closes https://lore.kernel.org/linux-fsdevel/20250426-haben-redeverbot-0b58878ac722@brauner/ open hereReported-by Mike Pagano <[email protected]>Reported-by Carlos Llamas <[email protected]>Fixes 0a65bc27bd64 ("eventpoll: Set epoll timeout if it's in the future")Tested-by Carlos Llamas <[email protected]>Signed-off-by Joe Damato <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 24 lines
--- fs/eventpoll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/eventpoll.c +3
-1@@ -2111,7 +2111,9 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,write_unlock_irq (&ep->lock); -if (!eavail &&ep_schedule_timeout (to)) +if (!ep_schedule_timeout (to)) + timed_out =1 ; +else if (!eavail) timed_out = !schedule_hrtimeout_range (to, slack,HRTIMER_MODE_ABS );__set_current_state (TASK_RUNNING );base-commit:
f520bed25d17bb31c2d2d72b0a785b593a4e3179Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Joe Damato
In commit
0a65bc27bd64("eventpoll: Set epoll timeout if it's in the future"), a bug was introduced causing the loop inep_pollto hang under certain circumstances.When the timeout is non-NULL and
ep_schedule_timeoutreturns false, the flagtimed_outwas not set to true. This causes a hang.Adjust the logic and set
timed_out, if needed, fixing the original code.
Hi Joe,
we have been working on the fix at the same time, this is my fix:
https://lore.kernel.org/linux-fsdevel/[email protected]/T/#u
I think mine is better because it checks "eavail" before setting "timed_out", preserving the old behavior (before commit 0a65bc27bd64). Your version may set "timed_out" and thus does an unnecessary list_empty() call in the following block. (And maybe it can reset "evail" to false?)
Max
Quoted 14 lines · Max Kellermann
Quoted 8 lines · Joe Damato
In commit
0a65bc27bd64("eventpoll: Set epoll timeout if it's in the future"), a bug was introduced causing the loop inep_pollto hang under certain circumstances.When the timeout is non-NULL and
ep_schedule_timeoutreturns false, the flagtimed_outwas not set to true. This causes a hang.Adjust the logic and set
timed_out, if needed, fixing the original code.Hi Joe,
we have been working on the fix at the same time, this is my fix:
Quoted 7 lines
https://lore.kernel.org/linux-fsdevel/[email protected]/T/#u
I think mine is better because it checks "eavail" before setting "
timed_out", preserving the old behavior (before commit0a65bc27bd64). Your version may set "timed_out" and thus does an unnecessarylist_empty()call in the following block. (And maybe it can reset "evail" to false?)
I think it's up to the maintainers to decide which patch is preferred; I don't really have a preference.