Commit Graph

12 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
97a3793345
qrexec: implement buffered write to a child stdin
Implement one of TODOs left in the code. Without this buffering, it may
happen that qrexec-agent will hang waiting on write(2) to the child
process, while that child will do the same (try to write something to
the qrexec-agent), without reading its stdin. This would end up in a
deadlock.

Fixes QubesOS/qubes-issues#1347
2015-10-24 20:35:36 +02:00
Marek Marczykowski-Górecki
51e2d6d356
qrexec: make sure that all the pipes/sockets are closed on cleanup
This will ensure that the child process will receive info that the
connection is closed. Otherwise it could hang on write() or in some
cases read() - on its stdin/stdout.

Thanks @adrelanos for help with debugging.
2015-08-08 01:52:59 +02:00
Marek Marczykowski-Górecki
cc83b8d344
qrexec: fix exit code from qrexec-client-vm
It should be remote process exit code, not the local one.
Also do not 'return' from the middle of the look, just use 'break' to
execute common cleanup code (which will be introduced in next commit).
2015-08-07 21:36:49 +02:00
Marek Marczykowski-Górecki
8f00bdb4a6 qrexec: process vchan data queue (esp MSG_EXIT_CODE) before sending anything
In case of remote process exit even when some messages are still
waiting, vchan connection can be already closed. If we try to send some
data in this case (for example stdout of local process), there will be
an error, which will terminate qrexec-client-vm/qrexec-agent child. So
first check vchan data (where could be MSG_EXIT_CODE queued) , then
local process.

There is still some race condition in this code - remote process could
exit just after we check vchan, but before we send some data. But this
is much less probable and in the worst case we only loose remote process
exit code.
2015-03-17 12:39:30 +01:00
Marek Marczykowski-Górecki
55e040cbef qrexec: do not break connection on duplicated SIGUSR1
Child process can request to use single socket for both stdin and
stdout by sending SIGUSR1 signal. If it does so twice or more, previous
code broke the connection by closing the socket.
2015-03-16 21:39:34 +01:00
Marek Marczykowski-Górecki
23fc3599e8 qrexec: better handle remote process termination
If remote end terminates without proper protocol finish
(MSG_DATA_EXIT_CODE), terminate also local part instead of waiting
indefinitely.
2015-03-16 21:37:59 +01:00
Marek Marczykowski-Górecki
4eb1d72aee qrexec: return remote process status as qrexec-client-vm exit code
This doesn't cover all the cases, because local process could want to
receive that value (currently it cant), but I can't think of any simple,
*compatible* way to pass it there.
2015-03-16 21:32:34 +01:00
Marek Marczykowski-Górecki
1aa05ebc36 qrexec: handle data vchan directly from qrexec-client-vm
This way qrexec-client-vm will have much more information, at least:
 - will know whether the service call was accepted or refused
 - potentially will know remote process exit code
This commit implements the first point - the local process will not be
started if service call was refused.
2015-03-16 21:10:25 +01:00
Marek Marczykowski-Górecki
e43c43f7b5 qrexec: fix compile warning 2015-02-17 14:09:36 +01:00
Marek Marczykowski-Górecki
4b5960daa3 qrexec: reorganise code for upcoming change
Move (qrexec-agent version of) do_exec to qrexec-agent.c, move
handle_handshake to qrexec-agent-data.c (common to all agent binaries).
Fix indentation (tabs -> spaces).
2015-02-17 04:06:19 +01:00
Marek Marczykowski-Górecki
c1cb78e0e8 qrexec: use sockets instead of pipes to communicate with child process
The main advantage is possible use of single socket for both stdin and
stdout. This is strictly required for using USBIP over qrexec.

For compatibility qrexec still creates three socket pairs (instead of
pipes) for stdin/out/err respectively. When qrexec-agent receives
SIGUSR1, it will close stdout socket and use stdin socket for both
directions.

Some additional work is needed here to actually allow child process to
send that signal - qrexec is running as root, but child as "user" in
most cases.
2015-02-17 01:36:09 +01:00
Marek Marczykowski-Górecki
b13844afe1 qrexec: new protocol - direct data vchan connections 2014-11-19 15:34:34 +01:00