Moon MCHN: egress filter saturation
Moon MCHN v0.3.1 fixes a security bug where malicious code in one machine (VM) could block the network connections of the other machines on your computer (host). With some configurations, the same machine could also reach a server you put in deny.
v0.1.0 through v0.3.0 are affected. Upgrade with cargo install moonmchn-cli --locked and then restart the daemon to run the new code.
NOTE: mchn daemon stop --force stops every machine too, and a stopped machine loses its disk.
How Moon MCHN Checks a Name
Every connection a guestg in a machine (VM) opens goes through a gateway on the host. Before the gateway dials the destination, it asks the Moon MCHN daemon to allow or deny it. The daemon decides with the machine’s allow and deny lists in ~/.config/moonmchn/config.toml. These lists hold IP addresses and hostnames.
But there is a catch: the gateway sees a connection as an IP address and a port. The only name in it is the one the guest writes in its TLS hello, the SNI (Server Name Indication). So when the lists hold hostnames, the daemon needs a DNS lookup on the host to match that name to the IP address.
Let’s say allow lists example.com. A guest normally resolves example.com and dials the address it gets back. But nothing ties the name to the address. The guest can dial any IP and still write example.com in its TLS hello.
Here’s the trick with curl:
curl -k --resolve example.com:443:203.0.113.7 https://example.com
--resolve makes curl dial 203.0.113.7, an untrusted server, instead of an address of example.com. The TLS hello still says example.com. The untrusted server can’t show a valid certificate for that name, so -k tells curl to skip the check. If the daemon trusted the name, allow would admit the connection, and the gateway would dial the untrusted server.
To catch that lie, the daemon looks the claimed name up with the host’s DNS resolver. It trusts the name only when it resolves to the dialed address. A lookup can take up to 5 seconds, and at most 32 run at once, to protect the host from being flooded with these requests. All machines share these 32 slots.
The Saturation Bug
The daemon looked up the name of every TLS connection before any other check. But the guest picks the name, so it also picks how long the lookup takes. A name whose DNS servers never answer keeps a slot (among the 32 max) busy for the full 5 seconds.
Code in one machine, such as a rogue agent or a malicious package, could keep every slot busy. Let’s say a guest opens 32 connections, each claiming such a name. All 32 slots stay busy for 5 seconds. To hold them, the guest needs only 32 new connections every 5 seconds: about 6 a second.
Meanwhile, no other machine can get a lookup. Let’s say another machine allows api.github.com only by name. The daemon can’t check the name, so it drops it and denies the connection, even if in this case it is legit:
egress: api.github.com was not looked up: too many lookups running
egress: denied my-machine to 192.0.2.1:443: no list allows it
Before the fix, denies were slow too. Some addresses are always denied and they should not require a DNS lookup: the host itself, link-local addresses, and every IP in your deny list.
Still, the Moon MCHN daemon waited for it before it turned the connection away. So the guest decided how long those connections stayed pending at the gateway.
The Escape Bug
The lookup also opened a hole in deny: a guest could reach a site you denied. Here’s how, with any server that hosts more than one domain, like a CDN (Content Delivery Network).
A CDN runs many servers, each with its own IP address. Often, any of them can serve any site on the CDN: it reads the name in the TLS hello to pick the site. But a DNS lookup for a site returns only a few of those addresses.
Let’s say your allow list has the IP address of one of these servers. Your deny list has evil.example, another site on the same CDN.
A guest dials an allowed IP and claims evil.example in its TLS hello. The daemon looks up evil.example on the host. The lookup returns one of the other addresses of the CDN, not the dialed IP.
Before the fix, the daemon checked a name against deny only after the lookup confirmed it. This name fails the lookup, so the daemon throws it away. It never compares evil.example with your deny list.
With no name left, the daemon judges the connection by its IP alone. The IP is in allow, so the guest reaches evil.example.
Checking the Destination First
The daemon now gives most verdicts without a lookup, in this order:
- The destination. A connection to the host, to the guest’s own link, to a link-local address or to an IP in
denyis denied right away. - The name against
deny. A claimed name that matches a hostname indenyis denied right away, wherever the name resolves. - The name against
allow. If the connection gets the same verdict with or without the name, the daemon gives it right away. It looks the name up only when the name alone would allow the connection.
With the default lists, the daemon never looks a name up. A machine with these lists can no longer keep the slots busy. Connections that an IP in allow admits don’t wait for a lookup either.
The second check, closes the hole in deny. I decided to trust the claimed name for deny, without a lookup, because the daemon can already take a decision upon a name the user decided to block. Now, in case the guest claims evil.example over a CDN, the daemon denies the connection right away, whatever IP it dials.
Since no lookup checks a denied name, a deny line can show a name that doesn’t resolve to the address next to it:
egress: denied my-machine to https://evil.example (192.0.2.1:443): listed in deny
What’s Left
A lookup still runs when only the name can allow the connection. With hostnames in allow, a guest can make the daemon look up only the names your list matches. With a bare * and a hostname in deny, any name can allow the connection. In that case, a malicious guest can still keep the 32 slots busy. The spec lists it in its known limitations.
Zero Trust
Moon MCHN treats every action from within a machine as if it came from malicious code. That includes the name in a TLS hello.
The cap of 32 lookups protected the host, but one guest could spend all of it, and the other machines paid the price.
Now the daemon checks the IP address first, because that’s where the connection really goes. When a machine claims something, the host must check it only if the DNS lookup answer can change the verdict, and a false claim must hurt only that machine.
If you find any security problem, please report it privately, as SECURITY.md explains.