Skip to content
Closed
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
17 changes: 4 additions & 13 deletions src/runtime/forkipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1549,21 +1549,12 @@ int64_t sys_clone(hv_vcpu_t vcpu,
* process would die instead of the clone failing. Suppress it per-socket
* the way syscall/net.c does for guest sockets; the option rides on the
* file description, so the spawned child inherits it.
*
* Failing the clone beats continuing without it: proceeding would leave the
* host one dead child away from being killed by a signal it never handles,
* which is worse than the guest seeing a fork it can retry.
*/
int nosigpipe = 1;
if (setsockopt(sock_fds[0], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe)) < 0 ||
setsockopt(sock_fds[1], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe)) < 0) {
log_error("clone: SO_NOSIGPIPE failed: %s", strerror(errno));
close(sock_fds[0]);
close(sock_fds[1]);
return -LINUX_ENOMEM;
}
setsockopt(sock_fds[0], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe));
setsockopt(sock_fds[1], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe));
Comment on lines +1554 to +1557

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: If the parent endpoint's setsockopt fails, sys_clone continues with an unprotected ipc_sock; a child that exits during the handshake can then raise the host's default SIGPIPE and terminate elfuse instead of returning a clone error. Restore fail-closed handling for either option, or otherwise guarantee SIGPIPE suppression before sending.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/runtime/forkipc.c, line 1554:

<comment>If the parent endpoint's `setsockopt` fails, `sys_clone` continues with an unprotected `ipc_sock`; a child that exits during the handshake can then raise the host's default SIGPIPE and terminate elfuse instead of returning a clone error. Restore fail-closed handling for either option, or otherwise guarantee SIGPIPE suppression before sending.</comment>

<file context>
@@ -1549,21 +1549,12 @@ int64_t sys_clone(hv_vcpu_t vcpu,
-        close(sock_fds[1]);
-        return -LINUX_ENOMEM;
-    }
+    setsockopt(sock_fds[0], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
+               sizeof(nosigpipe));
+    setsockopt(sock_fds[1], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
</file context>
Suggested change
setsockopt(sock_fds[0], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe));
setsockopt(sock_fds[1], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe));
if (setsockopt(sock_fds[0], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe)) < 0 ||
setsockopt(sock_fds[1], SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe)) < 0) {
log_error("clone: SO_NOSIGPIPE failed: %s", strerror(errno));
close(sock_fds[0]);
close(sock_fds[1]);
return -LINUX_ENOMEM;
}

if (is_vfork && pipe(vfork_notify_fds) < 0) {
log_error("clone: vfork notify pipe failed: %s", strerror(errno));
close(sock_fds[0]);
Expand Down
Loading