-
Notifications
You must be signed in to change notification settings - Fork 192
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 1 commit
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.
There are existing TCP listener forwarding tests, but none appear to assert the new loopback-to-gateway source-IP rewrite. Consider updating
test_tcp_bind_port_forward(or adding a dedicated test) to parse the forwarded SYN and confirm its source IP is the gateway when the host connector is loopback.