From 798d239c15c2b00859c4762671539de5845aee2f Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 27 Aug 2012 00:20:25 +0200 Subject: [PATCH] vm/qrexec: fix race between child cleanup and select call reap_children() can close FD, which was already added to FD_SET for select. This can lead to EBADF and agent termination. --- qrexec/qrexec_agent.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qrexec/qrexec_agent.c b/qrexec/qrexec_agent.c index f5e80256..eda5199e 100644 --- a/qrexec/qrexec_agent.c +++ b/qrexec/qrexec_agent.c @@ -554,14 +554,14 @@ int main() for (;;) { + sigprocmask(SIG_BLOCK, &chld_set, NULL); + if (child_exited) + reap_children(); max = fill_fds_for_select(&rdset, &wrset); if (buffer_space_vchan_ext() <= sizeof(struct server_header)) FD_ZERO(&rdset); - sigprocmask(SIG_BLOCK, &chld_set, NULL); - if (child_exited) - reap_children(); wait_for_vchan_or_argfd(max, &rdset, &wrset); sigprocmask(SIG_UNBLOCK, &chld_set, NULL);