Skip to content

Commit e5a5b0a

Browse files
committed
Add error messages to few more QREXEC_EXIT_PROBLEM cases
Tests detect that sometimes qrexec call fails with QREXEC_EXIT_PROBLEM, but no message about the actual cause. Review all instances of QREXEC_EXIT_PROBLEM and try to cover missing ones with an error message.
1 parent 55f1263 commit e5a5b0a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

agent/qrexec-agent.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,14 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
276276
case 0:
277277
/* child */
278278

279-
if (setgid (pw->pw_gid))
279+
if (setgid (pw->pw_gid)) {
280+
PERROR("setgid");
280281
_exit(QREXEC_EXIT_PROBLEM);
281-
if (setuid (pw->pw_uid))
282+
}
283+
if (setuid (pw->pw_uid)) {
284+
PERROR("setuid");
282285
_exit(QREXEC_EXIT_PROBLEM);
286+
}
283287
setsid();
284288
/* This is a copy but don't care to free as we exec later anyway. */
285289
env = pam_getenvlist (pamh);
@@ -296,6 +300,7 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
296300
}
297301
/* otherwise exec shell */
298302
execle(pw->pw_shell, arg0, "-c", cmd, (char*)NULL, env);
303+
LOGE(ERROR, "exec shell");
299304
_exit(QREXEC_EXIT_PROBLEM);
300305
default:
301306
/* parent */
@@ -322,6 +327,7 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
322327

323328
if (pam_end(pamh, retval) != PAM_SUCCESS) { /* close Linux-PAM */
324329
pamh = NULL;
330+
LOG(ERROR, "pam_end (retval %d)", retval);
325331
exit(QREXEC_EXIT_PROBLEM);
326332
}
327333
exit(status);

libqrexec/exec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ void exec_qubes_rpc2(const char *program, const char *cmd, char *const envp[],
161161
assert(iterator <= env_amount);
162162
buf[iterator] = NULL;
163163
execve(program, (char *const *)argv, buf);
164-
_exit(errno == ENOENT ? QREXEC_EXIT_SERVICE_NOT_FOUND : QREXEC_EXIT_PROBLEM);
164+
if (errno != ENOENT) {
165+
PERROR("execve");
166+
_exit(QREXEC_EXIT_PROBLEM);
167+
}
168+
_exit(QREXEC_EXIT_SERVICE_NOT_FOUND);
165169
}
166170

167171
// Generate a shell command and call it with the correct arguments.
@@ -208,6 +212,7 @@ void exec_qubes_rpc2(const char *program, const char *cmd, char *const envp[],
208212
argv[9] = NULL;
209213
execve("/bin/sh", (char *const *)argv, buf);
210214
/* /bin/sh should always exist */
215+
PERROR("execve /bin/sh");
211216
_exit(QREXEC_EXIT_PROBLEM);
212217
bad_asprintf:
213218
PERROR("asprintf");

0 commit comments

Comments
 (0)