Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rip out qubes-rpc-multiplexer #141

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions agent/qrexec-agent-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,52 @@

static int handle_just_exec(struct qrexec_parsed_command *cmd)
{
int fdn, pid;
int fdn, pid, log_fd;

if (cmd == NULL)
return QREXEC_EXIT_PROBLEM;

char file_path[QUBES_SOCKADDR_UN_MAX_PATH_LEN];
struct buffer buf = { .data = file_path, .buflen = (int)sizeof(file_path) };
struct buffer stdin_buffer;
buffer_init(&stdin_buffer);
if (cmd->service_descriptor) {
int socket_fd;
struct buffer stdin_buffer;
buffer_init(&stdin_buffer);
int status = find_qrexec_service(cmd, &socket_fd, &stdin_buffer);
int status = find_qrexec_service(cmd, &socket_fd, &stdin_buffer, &buf);
if (status == -1)
return QREXEC_EXIT_SERVICE_NOT_FOUND;
if (status != 0)
return QREXEC_EXIT_PROBLEM;
if (socket_fd != -1)
return write_all(socket_fd, stdin_buffer.data, stdin_buffer.buflen) ? 0 : QREXEC_EXIT_PROBLEM;
return write_all(socket_fd, stdin_buffer.data, stdin_buffer.buflen) ?
0 : QREXEC_EXIT_PROBLEM;
} else {
buf.data = NULL;
}
switch (pid = fork()) {
case -1:
PERROR("fork");
return QREXEC_EXIT_PROBLEM;
case 0:
fdn = open("/dev/null", O_RDWR);
fix_fds(fdn, fdn, fdn);
do_exec(cmd->command, cmd->username);
if (fdn < 0) {
LOG(ERROR, "open /dev/null failed");
_exit(QREXEC_EXIT_PROBLEM);

Check warning on line 173 in agent/qrexec-agent-data.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent-data.c#L172-L173

Added lines #L172 - L173 were not covered by tests
}
int other_pid;
log_fd = cmd->service_descriptor ? open_logger(cmd, &other_pid) : fdn;
if (log_fd < 0)
_exit(QREXEC_EXIT_PROBLEM);

Check warning on line 178 in agent/qrexec-agent-data.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent-data.c#L178

Added line #L178 was not covered by tests
fix_fds(fdn, fdn, log_fd);
do_exec(buf.data, cmd->command, cmd->username);
default:;
}
LOG(INFO, "executed (nowait): %s (pid %d)", cmd->command, pid);
if (buf.data)
LOG(INFO, "executed (nowait): %s %s (pid %d)", buf.data, cmd->command, pid);
else
LOG(INFO, "executed (nowait): %s (pid %d)", cmd->command, pid);
return 0;
}

Expand Down Expand Up @@ -261,6 +279,7 @@
return 0;
}

int logger_pid = 0;
req.vchan = data_vchan;
req.stdin_buf = &stdin_buf;

Expand All @@ -280,6 +299,8 @@

req.prefix_data.data = NULL;
req.prefix_data.len = 0;
if (cmd->service_descriptor != NULL)
req.logger_fd = open_logger(cmd, &logger_pid);

exit_code = qrexec_process_io(&req, cmd);

Expand Down
11 changes: 7 additions & 4 deletions agent/qrexec-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
* If dom0 sends overly long cmd, it will probably crash qrexec-agent (unless
* process can allocate up to 4GB on both stack and heap), sorry.
*/
_Noreturn void do_exec(const char *cmd, const char *user)
_Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
{
#ifdef HAVE_PAM
int retval, status;
Expand Down Expand Up @@ -172,7 +172,8 @@
exit(1);
}
/* call QUBESRPC if requested */
exec_qubes_rpc_if_requested(cmd, environ);
if (prog)
exec_qubes_rpc(prog, cmd, environ);

/* otherwise exec shell */
execl("/bin/sh", "sh", "-c", cmd, NULL);
Expand Down Expand Up @@ -279,7 +280,8 @@
warn("chdir(%s)", pw->pw_dir);

/* call QUBESRPC if requested */
exec_qubes_rpc_if_requested(cmd, env);
if (prog)
exec_qubes_rpc(prog, cmd, env);

Check warning on line 284 in agent/qrexec-agent.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent.c#L283-L284

Added lines #L283 - L284 were not covered by tests

/* otherwise exec shell */
execle(pw->pw_shell, arg0, "-c", cmd, (char*)NULL, env);
Expand Down Expand Up @@ -317,7 +319,8 @@
exit(1);
#else
/* call QUBESRPC if requested */
exec_qubes_rpc_if_requested(cmd, environ);
if (prog)
exec_qubes_rpc(prog, cmd, environ);

/* otherwise exec shell */
execl("/bin/su", "su", "-", user, "-c", cmd, NULL);
Expand Down
2 changes: 1 addition & 1 deletion agent/qrexec-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

int handle_handshake(libvchan_t *ctrl);
void handle_vchan_error(const char *op);
_Noreturn void do_exec(const char *cmd, const char *user);
_Noreturn void do_exec(const char *prog, const char *cmd, const char *user);
/* call before fork() for service handling process (either end) */
void prepare_child_env(void);

Expand Down
2 changes: 1 addition & 1 deletion agent/qrexec-client-vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
exit(1);
}

_Noreturn void do_exec(const char *cmd __attribute__((unused)), char const* user __attribute__((__unused__))) {
_Noreturn void do_exec(const char *prog __attribute__((unused)), const char *cmd __attribute__((unused)), char const* user __attribute__((__unused__))) {

Check warning on line 46 in agent/qrexec-client-vm.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-client-vm.c#L46

Added line #L46 was not covered by tests
LOG(ERROR, "BUG: do_exec function shouldn't be called!");
abort();
}
Expand Down
5 changes: 3 additions & 2 deletions agent/qrexec-fork-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@
extern char **environ;
const bool qrexec_is_fork_server = true;

void do_exec(const char *cmd, const char *user __attribute__((unused)))
void do_exec(const char *prog, const char *cmd, const char *user __attribute__((unused)))

Check warning on line 40 in agent/qrexec-fork-server.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-fork-server.c#L40

Added line #L40 was not covered by tests
{
char *shell;

signal(SIGCHLD, SIG_DFL);
signal(SIGPIPE, SIG_DFL);

/* call QUBESRPC if requested */
exec_qubes_rpc_if_requested(cmd, environ);
if (prog != NULL)
exec_qubes_rpc(prog, cmd, environ);

Check warning on line 49 in agent/qrexec-fork-server.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-fork-server.c#L48-L49

Added lines #L48 - L49 were not covered by tests

/* otherwise, pass it to shell */
shell = getenv("SHELL");
Expand Down
13 changes: 8 additions & 5 deletions daemon/qrexec-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ static void set_remote_domain(const char *src_domain_name) {
}

/* called from do_fork_exec */
static _Noreturn void do_exec(const char *prog, const char *username __attribute__((unused)))
static _Noreturn void do_exec(const char *prog,
const char *cmdline,
const char *username __attribute__((unused)))
{
/* avoid calling qubes-rpc-multiplexer through shell */
exec_qubes_rpc_if_requested(prog, environ);
/* avoid calling RPC service through shell */
if (prog)
exec_qubes_rpc(prog, cmdline, environ);

/* if above haven't executed qubes-rpc-multiplexer, pass it to shell */
execl("/bin/bash", "bash", "-c", prog, NULL);
/* if above haven't executed RPC service, pass it to shell */
execl("/bin/bash", "bash", "-c", cmdline, NULL);
PERROR("exec bash");
exit(1);
}
Expand Down
12 changes: 7 additions & 5 deletions daemon/qrexec-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,14 +1131,16 @@
}

/* called from do_fork_exec */
static _Noreturn void do_exec(const char *prog, const char *username __attribute__((unused)))
static _Noreturn void do_exec(const char *prog, const char *cmd, const char *username __attribute__((unused)))
{
/* avoid calling qubes-rpc-multiplexer through shell */
exec_qubes_rpc_if_requested(prog, environ);
/* avoid calling RPC command through shell */
if (prog)
exec_qubes_rpc(prog, cmd, environ);

Check warning on line 1138 in daemon/qrexec-daemon.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-daemon.c#L1137-L1138

Added lines #L1137 - L1138 were not covered by tests

/* if above haven't executed qubes-rpc-multiplexer, pass it to shell */
execl("/bin/bash", "bash", "-c", prog, NULL);
/* if above haven't executed RPC command, pass it to shell */
execl("/bin/bash", "bash", "-c", cmd, NULL);

Check warning on line 1141 in daemon/qrexec-daemon.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-daemon.c#L1141

Added line #L1141 was not covered by tests
PERROR("exec bash");
/* treat ENOENT as "problem" because bash should always exist */
_exit(QREXEC_EXIT_PROBLEM);
}

Expand Down
6 changes: 3 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Homepage: https://www.qubes-os.org
Package: qubes-core-qrexec
Architecture: any
Depends:
libqrexec-utils2 (= ${binary:Version}),
libqrexec-utils4 (= ${binary:Version}),
python3-qrexec,
${shlibs:Depends},
${misc:Depends}
Expand All @@ -36,7 +36,7 @@ Description: Qubes qrexec agent
Agent part of Qubes RPC system. A daemon responsible for starting processes as
requested by dom0 or other VMs, according to dom0-enforced policy.

Package: libqrexec-utils2
Package: libqrexec-utils4
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Breaks: qubes-utils (<< 3.1.4)
Expand All @@ -47,7 +47,7 @@ Description: Library of common functions of qrexec agent and daemon
Package: libqrexec-utils-dev
Architecture: any
Section: libdevel
Depends: libqrexec-utils2 (= ${binary:Version}), ${misc:Depends}
Depends: libqrexec-utils4 (= ${binary:Version}), ${misc:Depends}
Breaks: qubes-utils (<< 3.1.4)
Replaces: qubes-utils (<< 3.1.4)
Description: Development headers for libqrexec-utils
Expand Down
1 change: 0 additions & 1 deletion debian/libqrexec-utils2.install

This file was deleted.

1 change: 0 additions & 1 deletion debian/libqrexec-utils2.shlibs

This file was deleted.

1 change: 1 addition & 0 deletions debian/libqrexec-utils4.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/libqrexec-utils.so.4*
1 change: 1 addition & 0 deletions debian/libqrexec-utils4.shlibs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libqrexec-utils 4 libqrexec-utils4 (>=4.2.18)
4 changes: 2 additions & 2 deletions libqrexec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CFLAGS += -I. -I../libqrexec -g -O2 -Wall -Wextra -Werror \

LDFLAGS += -pie -Wl,-z,relro,-z,now -shared

SO_VER=3
SO_VER=4
VCHANLIBS := $(shell pkg-config --libs vchan)
LIBDIR ?= /usr/lib
INCLUDEDIR ?= /usr/include
Expand All @@ -22,7 +22,7 @@ endif


all: libqrexec-utils.so
libqrexec-utils.so.$(SO_VER): unix-server.o ioall.o buffer.o exec.o txrx-vchan.o write-stdin.o replace.o remote.o process_io.o log.o toml.o vchan_timeout.o
libqrexec-utils.so.$(SO_VER): unix-server.o ioall.o buffer.o exec.o txrx-vchan.o write-stdin.o replace.o remote.o process_io.o log.o toml.o open_logger.o vchan_timeout.o
$(CC) $(LDFLAGS) -Wl,-soname,$@ -o $@ $^ $(VCHANLIBS)

libqrexec-utils.so: libqrexec-utils.so.$(SO_VER)
Expand Down
10 changes: 5 additions & 5 deletions libqrexec/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
(total_mem > BUFFER_LIMIT) || (len <= 0))
{
LOG(ERROR, "attempt to allocate >BUFFER_LIMIT");
exit(1);
abort();

Check warning on line 38 in libqrexec/buffer.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/buffer.c#L38

Added line #L38 was not covered by tests
}
ret = malloc((size_t)len);
if (!ret) {
PERROR("malloc");
exit(1);
abort();

Check warning on line 43 in libqrexec/buffer.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/buffer.c#L43

Added line #L43 was not covered by tests
}
return ret;
}
Expand Down Expand Up @@ -83,11 +83,11 @@
assert(data != NULL && "NULL data");
if (b->buflen < 0 || b->buflen > BUFFER_LIMIT) {
LOG(ERROR, "buffer_append buflen %d", len);
exit(1);
abort();

Check warning on line 86 in libqrexec/buffer.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/buffer.c#L86

Added line #L86 was not covered by tests
}
if (len < 0 || len > BUFFER_LIMIT) {
LOG(ERROR, "buffer_append %d", len);
exit(1);
abort();

Check warning on line 90 in libqrexec/buffer.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/buffer.c#L90

Added line #L90 was not covered by tests
}
if (len == 0)
return;
Expand All @@ -108,7 +108,7 @@
char *qdata = NULL;
if (len < 0 || len > b->buflen) {
LOG(ERROR, "buffer_remove %d/%d", len, b->buflen);
exit(1);
abort();

Check warning on line 111 in libqrexec/buffer.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/buffer.c#L111

Added line #L111 was not covered by tests
}
newsize = b->buflen - len;
if (newsize > 0) {
Expand Down
Loading