-
Notifications
You must be signed in to change notification settings - Fork 190
consomme: avoid injecting guest packets with a localhost source address #3407
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,11 +162,19 @@ impl UdpConnection { | |
| }, | ||
| ) { | ||
| Poll::Ready(Ok((n, src_addr))) => { | ||
| // Replace loopback source IPs with the gateway IP so | ||
| // the guest's reply routes back through the virtual | ||
| // adapter instead of its own loopback interface. | ||
| let (packet_len, checksum_state) = match (dst_addr, src_addr.ip()) { | ||
| (SocketAddr::V4(dst), IpAddr::V4(src_ip)) => { | ||
| let effective_src_ip: IpAddress = if src_ip.is_loopback() { | ||
| state.params.gateway_ip.into() | ||
| } else { | ||
| src_ip.into() | ||
| }; | ||
| let len = build_udp_packet( | ||
| &mut eth, | ||
| src_ip.into(), | ||
| effective_src_ip, | ||
|
Comment on lines
+165
to
+177
|
||
| (*dst.ip()).into(), | ||
| src_addr.port(), | ||
| dst.port(), | ||
|
|
@@ -177,9 +185,14 @@ impl UdpConnection { | |
| (len, ChecksumState::UDP4) | ||
| } | ||
| (SocketAddr::V6(dst), IpAddr::V6(src_ip)) => { | ||
| let effective_src_ip: IpAddress = if src_ip.is_loopback() { | ||
| state.params.gateway_link_local_ipv6.into() | ||
| } else { | ||
| src_ip.into() | ||
| }; | ||
| let len = build_udp_packet( | ||
| &mut eth, | ||
| src_ip.into(), | ||
| effective_src_ip, | ||
| (*dst.ip()).into(), | ||
| src_addr.port(), | ||
| dst.port(), | ||
|
|
@@ -254,11 +267,19 @@ impl UdpListener { | |
| .recv_from(&mut eth.payload_mut()[header_offset..]) | ||
| }) { | ||
| Poll::Ready(Ok((n, src_addr))) => { | ||
| // Replace loopback source IPs with the gateway IP so | ||
| // the guest's reply routes back through the virtual | ||
| // adapter instead of its own loopback interface. | ||
| let Some((packet_len, checksum_state)) = (match (guest_dst_ip, src_addr.ip()) { | ||
| (IpAddr::V4(dst_ip), IpAddr::V4(src_ip)) => { | ||
| let effective_src_ip: IpAddress = if src_ip.is_loopback() { | ||
| state.params.gateway_ip.into() | ||
| } else { | ||
| src_ip.into() | ||
| }; | ||
| let len = build_udp_packet( | ||
| &mut eth, | ||
| src_ip.into(), | ||
| effective_src_ip, | ||
| dst_ip.into(), | ||
| src_addr.port(), | ||
| self.guest_port, | ||
|
|
@@ -269,9 +290,14 @@ impl UdpListener { | |
| Some((len, ChecksumState::UDP4)) | ||
| } | ||
| (IpAddr::V6(dst_ip), IpAddr::V6(src_ip)) => { | ||
| let effective_src_ip: IpAddress = if src_ip.is_loopback() { | ||
| state.params.gateway_link_local_ipv6.into() | ||
| } else { | ||
| src_ip.into() | ||
| }; | ||
| let len = build_udp_packet( | ||
| &mut eth, | ||
| src_ip.into(), | ||
| effective_src_ip, | ||
| dst_ip.into(), | ||
| src_addr.port(), | ||
| self.guest_port, | ||
|
Comment on lines
270
to
303
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing a loopback source IP with
gateway_ipchanges the remote address the guest sees. For UDP, replies will typically be sent to the packet’s source IP; that means the guest will reply togateway_ip, andhandle_udp()will then send the response togateway_ip:<port>(no special-case remap exists beyond DHCP/DNS). This likely breaks bidirectional UDP flows involving host loopback senders. Consider adding a reverse mapping on egress (e.g., when dst isgateway_ip/gateway_link_local_ipv6and port matches a forwarded flow) or preserving the original loopback IP while fixing routing another way.