Skip to content

Commit 47978ac

Browse files
committed
Avoid using /tmp for qrexec return pipes
This avoids a privilege escalation from unprivileged users (not in the "qubes" group). Fixes: QubesOS/qubes-issues#9097
1 parent 48944be commit 47978ac

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/qubes-rpc-multiplexer

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/bin/sh -l
2+
# we don't use globbing, disable it
3+
set -f
24

3-
if [ -z "$QREXEC_SERVICE_PATH" ]; then
5+
if [ -z "${QREXEC_SERVICE_PATH+x}" ]; then
46
QREXEC_SERVICE_PATH=/usr/local/etc/qubes-rpc:/etc/qubes-rpc
57
fi
8+
tmpdir=${XDG_RUNTIME_DIR-/tmp}
69

710
# write stderr to both calling party and local log; be very careful about
811
# closing file descriptors here - if either stdout or stderr will not be closed
912
# when service process does the same - service call will hang (waiting for EOF
1013
# on stdout/stderr)
11-
stderr_pipe=/tmp/qrexec-rpc-stderr.$$
12-
mkfifo $stderr_pipe
14+
stderr_pipe=$tmpdir/qrexec-rpc-stderr.$$
15+
mkfifo -- "$stderr_pipe"
1316
# tee can't write to file descriptor, nor /proc/self/fd/2 (EXIO on open)
14-
return_stderr_pipe=/tmp/qrexec-rpc-stderr-return.$$
15-
mkfifo $return_stderr_pipe
16-
{ cat <$return_stderr_pipe >&2 2>/dev/null; rm -f $return_stderr_pipe; } </dev/null >/dev/null &
17-
{ tee $return_stderr_pipe <$stderr_pipe |\
18-
logger -t "$1-$2"; rm -f $stderr_pipe; } </dev/null >/dev/null 2>&1 &
19-
exec 2>$stderr_pipe
17+
return_stderr_pipe=$tmpdir/qrexec-rpc-stderr-return.$$
18+
mkfifo -- "$return_stderr_pipe"
19+
{ cat <"$return_stderr_pipe" >&2 2>/dev/null; rm -f -- "$return_stderr_pipe"; } </dev/null >/dev/null &
20+
{ tee -- "$return_stderr_pipe" <"$stderr_pipe" |
21+
logger -t "$1-$2"; rm -f -- "$stderr_pipe"; } </dev/null >/dev/null 2>&1 &
22+
exec 2>"$stderr_pipe"
2023

2124
if ! [ $# = 2 -o $# = 4 ] ; then
2225
echo "$0: bad argument count, usage: $0 SERVICE-NAME REMOTE-DOMAIN-NAME [REQUESTED_TARGET_TYPE REQUESTED_TARGET]" >&2

0 commit comments

Comments
 (0)