Skip to content

Commit

Permalink
Avoid using /tmp for qrexec return pipes
Browse files Browse the repository at this point in the history
This avoids a privilege escalation from unprivileged users (not in the
"qubes" group).

Fixes: QubesOS/qubes-issues#9097
  • Loading branch information
DemiMarie committed Apr 9, 2024
1 parent 48944be commit 47978ac
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/qubes-rpc-multiplexer
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/bin/sh -l
# we don't use globbing, disable it
set -f

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

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

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

0 comments on commit 47978ac

Please sign in to comment.