From b7cd61b8a59439fe7aa000540f8d65c6fc8e6fa6 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Thu, 8 Oct 2026 00:24:23 +0000 Subject: [PATCH 1/3] fix(minvmd): drop proxy opening TCP packets toward published ports In relay_switch_frames_to_guest, drop Box Egress Proxy-sourced bare-SYN TCP packets addressed to a box's published inside port at ingress, before any observation or delivery. The proxy only answers (NET-134) and never opens toward a box, so a bare SYN from its address has no legitimate origin; dropping it keeps the proxy from planting an inbound flow record or reaching the box. SYN-ACKs and ACKs it sends back are not opening packets and still pass. Adds a unit test proving the bare SYN is dropped without opening a reply-flow record, while the proxy's SYN-ACK answer still reaches the guest. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- crates/minvmd/src/net/egress_gate.rs | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/crates/minvmd/src/net/egress_gate.rs b/crates/minvmd/src/net/egress_gate.rs index 6f7febb696..c9ee23c83a 100644 --- a/crates/minvmd/src/net/egress_gate.rs +++ b/crates/minvmd/src/net/egress_gate.rs @@ -3213,6 +3213,22 @@ async fn relay_switch_frames_to_guest( && let Some(record) = table.by_source(pkt.dst.ip().octets()) && forwards.inside_published(record.switch_addr().octets(), pkt.dst.port()) { + // NET-134's ingress arm: the box egress proxy answers and never + // opens toward a box, so a bare SYN from its address to a + // published inside port has no legitimate origin. Dropping the + // opening packet here — before any observation or delivery — + // keeps the proxy's address from planting an inbound flow toward + // a box at all. Only opening packets are dropped: SYN-ACKs and + // ACKs the proxy sends back to the box on a credentialed dial + // still reach it untouched. + let proxy = table.subnet().box_egress_proxy_address().octets(); + if pkt.src.ip().octets() == proxy + && pkt.proto == egress::IPPROTO_TCP + && pkt.tcp_flags & egress::TCP_SYN != 0 + && pkt.tcp_flags & egress::TCP_ACK == 0 + { + continue; + } let now = Instant::now(); if matches!( replies.observe_delivered(&record, &pkt, &limiter, table.subnet(), now), @@ -8909,6 +8925,77 @@ mod tests { expect_silence(&mut switch).await; } + /// NET-134's ingress arm: a bare-SYN TCP frame from the Box Egress + /// Proxy's address toward a box's published inside port has no + /// legitimate origin — the proxy only answers (NET-134) and never opens + /// toward a box — so the ingress relay drops it before it can open a + /// reply-flow record or reach the box. The proxy's answers to a + /// credentialed box's dial (SYN-ACK, ACK) are not opening packets and + /// still pass, and a proxy-sourced bare SYN toward a port no publish + /// names is out of the recording bound's reach, so it is not this rule's + /// and continues to its normal decision. + #[tokio::test] + async fn box_egress_proxy_syn_to_published_port_dropped() { + let registry = BoxRegistry::new(SUBNET); + registry.register_node_namespace(7654); + let node_addr = SUBNET.daemon_ip().octets(); + let publish = expose_request( + "127.0.0.1:7654", + &format!("{}:7654", SUBNET.daemon_ip()), + "tcp", + ); + let h = gate_over_control(registry, publish).await; + let (mut guest, mut switch) = connect_over(&h).await; + let proxy = SUBNET.box_egress_proxy_address().octets(); + + // The proxy's bare SYN toward the published inside port — the + // opening packet no one legitimately sends — never reaches the + // guest, and never opens a reply-flow record for the node. + let opening = dns_pins::tests::tcp_frame( + Ipv4Addr::from(proxy), + 40000, + Ipv4Addr::from(node_addr), + 7654, + sessions::core::egress::TCP_SYN, + ); + send_frame(&mut switch, &opening).await; + assert_eq!( + h.replies.record_count_of(node_addr), + None, + "the dropped opening packet opened no reply-flow record for the node" + ); + + // The proxy's answer to a credentialed box's dial — a SYN-ACK from + // the proxy's address toward the published inside port — is not an + // opening packet, so it is not dropped by this rule. Delivered + // toward the guest, it is the exact frame this hardening must never + // withhold. + let answer = dns_pins::tests::tcp_frame( + Ipv4Addr::from(proxy), + 40000, + Ipv4Addr::from(node_addr), + 7654, + sessions::core::egress::TCP_SYN | sessions::core::egress::TCP_ACK, + ); + send_frame(&mut switch, &answer).await; + assert_eq!( + expect_frame(&mut guest).await, + answer, + "the proxy's SYN-ACK answer reaches the guest" + ); + + // The marker after them proves the dropped bare SYN was decided, and + // nothing but the answer reached the guest. + let marker = arp_frame(node_addr); + send_frame(&mut switch, &marker).await; + assert_eq!( + expect_frame(&mut guest).await, + marker, + "the bare SYN never arrived; only the answer and the marker did" + ); + expect_silence(&mut guest).await; + } + /// The §5.3 infrastructure deny set as a host frame rule /// ([`INFRASTRUCTURE_RULE`]), decided for every row before the row's own /// rules and before the deferral: a name-declaring row and a CIDR row From b00b602117bb44c6a6ba97a9e7d24740a9fd7fd6 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 17:31:02 -0700 Subject: [PATCH 2/3] fix(minvmd): log the proxy-opening drop and align observe_delivered docs Rate-limit and name the ingress drop of a proxy-sourced opening TCP packet under its own rule, egress-proxy-opening-toward-box, keyed per box. Correct observe_delivered's doc, which said every proxy-sourced frame is still delivered. Cover a SYN carrying other flags without ACK. --- crates/minvmd/src/net/egress_gate.rs | 76 +++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/crates/minvmd/src/net/egress_gate.rs b/crates/minvmd/src/net/egress_gate.rs index c9ee23c83a..c83320d896 100644 --- a/crates/minvmd/src/net/egress_gate.rs +++ b/crates/minvmd/src/net/egress_gate.rs @@ -529,6 +529,16 @@ fn infrastructure_destination( /// rules ([`GateAdmit::ProxyLane`]). const PROXY_LANE_RULE: &str = "egress-uncredentialed-proxy-destination"; +/// The rule name for the ingress drop of an opening TCP packet (SYN set, ACK +/// clear) sourced from the Box Egress Proxy's address toward a box's +/// published inside port (NET-134's ingress arm): the proxy only answers a +/// credentialed box's dial and never opens toward a box, so such a packet has +/// no legitimate origin. Its own rule, not [`PROXY_LANE_RULE`]'s: that one +/// names a box reaching for the proxy, this one the proxy's address reaching +/// for a box. The proxy's answers (SYN-ACK, ACK, data, FIN, RST) are never +/// dropped under it. +const PROXY_OPENING_RULE: &str = "egress-proxy-opening-toward-box"; + /// The rule name for the drop of an in-plan source no published namespace /// holds (NET-085): a frame whose source is an address the plan could hand /// to a box but no row does. It carries its own rule — beside rule 0's @@ -3227,6 +3237,11 @@ async fn relay_switch_frames_to_guest( && pkt.tcp_flags & egress::TCP_SYN != 0 && pkt.tcp_flags & egress::TCP_ACK == 0 { + limiter.warn_proxy_opening( + record.switch_addr().octets(), + record.name(), + pkt.dst.port(), + ); continue; } let now = Instant::now(); @@ -3772,8 +3787,11 @@ impl ReplyTables { /// /// A frame sourced from the switch subnet's Box Egress Proxy address /// records nothing: the decline comes before any record is consulted or - /// minted, and the frame itself is still delivered (only the reply-flow - /// recording is declined). A box on a credentialed lane does dial the + /// minted. Of such frames the ingress leg never hands this an opening TCP + /// packet (SYN set, ACK clear) — it drops that one before calling here + /// ([`PROXY_OPENING_RULE`]) — while every other proxy-sourced frame, the + /// proxy's answers to a box's dial included, is still delivered with only + /// the reply-flow recording declined. A box on a credentialed lane does dial the /// proxy's listener (NET-134), but the proxy only answers: it never opens /// a connection toward a box, so a proxy-sourced opening packet at a /// box's published port has no legitimate origin, and the stream it @@ -4906,6 +4924,39 @@ impl DropLimiter { } } } + + /// Emits the drop's line for one opening TCP packet from the Box Egress + /// Proxy's address toward a box's published inside port + /// ([`PROXY_OPENING_RULE`]): the same rate limit a drop's line answers + /// to, keyed by the box's address and the rule — the source is always + /// the proxy, so keying by it would fold every box into one window — + /// and naming the box and the port. Returns whether a line was written. + fn warn_proxy_opening(&self, box_addr: [u8; 4], namespace: &str, port: u16) -> bool { + match self.should_warn_at(Some(box_addr), PROXY_OPENING_RULE, Instant::now()) { + WarnDecision::Silent => false, + WarnDecision::Named => { + tracing::warn!( + destination = %Ipv4Addr::from(box_addr), + namespace, + port, + rule_matched = PROXY_OPENING_RULE, + "dropped an opening TCP packet from the box egress proxy's address \ + toward a box's published port; the proxy only answers and never \ + opens toward a box", + ); + true + } + WarnDecision::Overflow => { + tracing::warn!( + rule_matched = PROXY_OPENING_RULE, + "dropped opening TCP packets from the box egress proxy's address toward \ + more distinct boxes than the gate keeps a window per address for; one \ + line per rule covers the rest", + ); + true + } + } + } } /// Reads the head of the guest's first request — through the first @@ -8964,6 +9015,16 @@ mod tests { None, "the dropped opening packet opened no reply-flow record for the node" ); + // A SYN carrying other flags but no ACK is still an opening packet by + // the reply-flow table's own shape, and is dropped the same way. + let odd_opening = dns_pins::tests::tcp_frame( + Ipv4Addr::from(proxy), + 40001, + Ipv4Addr::from(node_addr), + 7654, + sessions::core::egress::TCP_SYN | sessions::core::egress::TCP_FIN, + ); + send_frame(&mut switch, &odd_opening).await; // The proxy's answer to a credentialed box's dial — a SYN-ACK from // the proxy's address toward the published inside port — is not an @@ -12787,6 +12848,17 @@ mod tests { ); } + /// The proxy-opening drop's line answers to the drop cadence per box: + /// one line for a box's first dropped opening packet, silence for the + /// next within the interval, and its own line for another box. + #[test] + fn proxy_opening_drop_line_is_rate_limited_per_box() { + let limiter = DropLimiter::new(); + assert!(limiter.warn_proxy_opening([100, 64, 0, 10], "web", 7654)); + assert!(!limiter.warn_proxy_opening([100, 64, 0, 10], "web", 7654)); + assert!(limiter.warn_proxy_opening([100, 64, 0, 11], "api", 7654)); + } + /// The limiter's window table is bounded, because the source address it /// keys by is the dropped frame's own bytes and a hostile guest chooses /// those: flooding distinct spoofed addresses must not grow host memory From bf80b2b4e778266616f2058e672faa5013219dd2 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 17:35:34 -0700 Subject: [PATCH 3/3] test(minvmd): drop the vacuous record-count assertion and rewrap observe_delivered docs --- crates/minvmd/src/net/egress_gate.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/minvmd/src/net/egress_gate.rs b/crates/minvmd/src/net/egress_gate.rs index c83320d896..24d5a6b019 100644 --- a/crates/minvmd/src/net/egress_gate.rs +++ b/crates/minvmd/src/net/egress_gate.rs @@ -3791,10 +3791,11 @@ impl ReplyTables { /// packet (SYN set, ACK clear) — it drops that one before calling here /// ([`PROXY_OPENING_RULE`]) — while every other proxy-sourced frame, the /// proxy's answers to a box's dial included, is still delivered with only - /// the reply-flow recording declined. A box on a credentialed lane does dial the - /// proxy's listener (NET-134), but the proxy only answers: it never opens - /// a connection toward a box, so a proxy-sourced opening packet at a - /// box's published port has no legitimate origin, and the stream it + /// the reply-flow recording declined. + /// A box on a credentialed lane does dial the proxy's listener + /// (NET-134), but the proxy only answers: it never opens a connection + /// toward a box, so a proxy-sourced opening packet at a box's published + /// port has no legitimate origin, and the stream it /// would open must never become a reply flow the box could reverse-answer /// ([`gate_verdict`]'s reply-flow admit). Defense in depth — the /// reply-flow admit in [`gate_verdict`] itself never admits a frame to @@ -9001,7 +9002,7 @@ mod tests { // The proxy's bare SYN toward the published inside port — the // opening packet no one legitimately sends — never reaches the - // guest, and never opens a reply-flow record for the node. + // guest; the marker below proves it was decided. let opening = dns_pins::tests::tcp_frame( Ipv4Addr::from(proxy), 40000, @@ -9010,11 +9011,6 @@ mod tests { sessions::core::egress::TCP_SYN, ); send_frame(&mut switch, &opening).await; - assert_eq!( - h.replies.record_count_of(node_addr), - None, - "the dropped opening packet opened no reply-flow record for the node" - ); // A SYN carrying other flags but no ACK is still an opening packet by // the reply-flow table's own shape, and is dropped the same way. let odd_opening = dns_pins::tests::tcp_frame(