Skip to content

Commit 27e2f98

Browse files
committed
qrexec: validate socket fd before use
Check return value of connect_unix_socket*() before use to avoid passing invalid file descriptors and triggering EBADF. Fixes QubesOS/qubes-issues#10792
1 parent 4c1c239 commit 27e2f98

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

daemon/qrexec-client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ int main(int argc, char **argv)
345345
wait_connection_end, use_uuid) ? 0 : 137;
346346
} else {
347347
s = connect_unix_socket(domname);
348+
if (s < 0) {
349+
goto cleanup;
350+
}
348351
if (!negotiate_connection_params(s,
349352
src_domain_id,
350353
just_exec ? MSG_JUST_EXEC : MSG_EXEC_CMDLINE,

daemon/qrexec-daemon-common.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,13 @@ bool qrexec_execute_vm(const char *target, bool autostart, int remote_domain_id,
206206
}
207207

208208
s = connect_unix_socket_by_id((unsigned)remote_domain_id);
209-
rc = send_service_connect(s, request_id, data_domain, data_port);
210-
close(s);
209+
if (s < 0) {
210+
rc = false;
211+
} else {
212+
rc = send_service_connect(s, request_id, data_domain, data_port);
213+
close(s);
214+
}
215+
211216
if (wait_connection_end) {
212217
/* wait for EOF */
213218
struct pollfd fds[1] = {

0 commit comments

Comments
 (0)