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

Disabled unix sockets being wrongfully sent to the agent when socket isn't connected #2217

Merged
merged 2 commits into from
Feb 5, 2024
Merged
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
1 change: 1 addition & 0 deletions changelog.d/+unix-socket-falsely-sent.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disabled unix sockets being wrongfully sent to the agent when socket isn't connected
16 changes: 15 additions & 1 deletion mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
};

use errno::set_errno;
use libc::{c_int, c_void, hostent, sockaddr, socklen_t};
use libc::{c_int, c_void, hostent, sockaddr, socklen_t, AF_UNIX};
use mirrord_config::feature::network::incoming::IncomingMode;
use mirrord_intproxy_protocol::{
ConnMetadataRequest, ConnMetadataResponse, NetProtocol, OutgoingConnectRequest,
Expand Down Expand Up @@ -1135,6 +1135,13 @@ pub(super) fn send_to(
.remove(&sockfd)
.ok_or(Bypass::LocalFdNotFound(sockfd))?;

// we don't support unix sockets which don't use `connect`
if (destination.is_unix() || user_socket_info.domain == AF_UNIX)
&& !matches!(user_socket_info.state, SocketState::Connected(_))
{
return Detour::Bypass(Bypass::Domain(AF_UNIX));
}

// Currently this flow only handles DNS resolution.
// So here we have to check for 2 things:
//
Expand Down Expand Up @@ -1214,6 +1221,13 @@ pub(super) fn sendmsg(
.remove(&sockfd)
.ok_or(Bypass::LocalFdNotFound(sockfd))?;

// we don't support unix sockets which don't use `connect`
if (destination.is_unix() || user_socket_info.domain == AF_UNIX)
&& !matches!(user_socket_info.state, SocketState::Connected(_))
{
return Detour::Bypass(Bypass::Domain(AF_UNIX));
}

// Currently this flow only handles DNS resolution.
// So here we have to check for 2 things:
//
Expand Down
Loading