From f86bec735b012116971bc5e9c2e47e7fd8245471 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 4 Jul 2023 17:06:11 +0200 Subject: [PATCH] poll: Drop all events except POLLOUT when called recursively The FD locking was modified in 30b5a2e33bf260062dd31c9c0e98cf9982b08961 but it caused some weird issues on s390x in Debian tests, which were getting POLLHUP, causing infinite recursion while the callback tried to close socket. Previously, the lock blocked only the POLLIN events as we believed these were the only events we could get recursively that could cause issues. But it looks like more sane behavior will be blocking everything but POLLOUT to allow the buffers to be flushed. Fixes #202 Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/poll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/poll.c b/src/poll.c index 828f5e0a..b5d0a662 100644 --- a/src/poll.c +++ b/src/poll.c @@ -698,13 +698,13 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) return SSH_ERROR; } - /* Ignore any pollin events on locked sockets as that means we are called + /* Allow only POLLOUT events on locked sockets as that means we are called * recursively and we only want process the POLLOUT events here to flush * output buffer */ for (i = 0; i < ctx->polls_used; i++) { - /* The lock prevents invoking POLLIN events: drop them now */ + /* The lock allows only POLLOUT events: drop the rest */ if (ctx->pollptrs[i]->lock_cnt > 0) { - ctx->pollfds[i].events &= ~POLLIN; + ctx->pollfds[i].events &= POLLOUT; } } ssh_timestamp_init(&ts);