Deep Review: 20261007-102123-pr-5581
| Date | 2026-10-07 10:21 |
| Repo | lima-vm/lima |
| Round | 2 |
| Author | @ranacseruet |
| PR | #5581 — vz: add hostLoopback option to block guest access to host loopback |
| Branch | feat/host-loopback-opt-out |
| Commits | 46771eb0 vz: add hostLoopback option to block guest access to host loopback |
| Review SHA | 46771eb073d74fc53a5f7160aee6eb623c27c9bf |
| Reviewers | Claude Opus 5.5 (effort: high), Codex GPT 6 Astra (effort: high), Gemini 3.1 Pro (effort: default), Gemini 3.5 Flash (effort: default) |
| Verdict | Merge with fixes — every round-1 fix holds; two links that make the option work are still untested |
| Wall-clock time | 20 min 42 s |
Executive Summary ¶
The PR adds hostLoopback: false for vz, which maps host.lima.internal and 0.0.0.0 to the unroutable 0.0.0.1; every other driver refuses the setting in Validate. All five round-1 findings are fixed, and probes confirm that blocked connections now fail at once and limactl delete works again. One gap remains. No test covers the natTable call site or the krunkit refusal, and removing either silently turns the isolation off.
Critical Issues ¶
None.
Important Issues ¶
natTable call site or the krunkit refusal, so removing either silently turns hostLoopback: false off Claude Opus 5.5 Codex GPT 6 Astra Gemini 3.1 Pro Gemini 3.5 Flash¶
GatewayMacAddress: gatewayMacAddr,
DHCPStaticLeases: leases,
Forwards: map[string]string{},
DNS: []types.Zone{},
DNSSearchDomains: searchDomains(),
NAT: natTable(gatewayIP, opts.DisableHostLoopback),
GatewayVirtualIPs: []string{gatewayIP},
}
groupErrs, ctx := errgroup.WithContext(ctx)
err = run(ctx, groupErrs, &config)
TestGVisorNetstackOptsHostLoopback tests what vz passes in, and TestNATTable tests what natTable returns, but no test checks that StartGVisorNetstack hands the option over. Passing false here keeps the 127.0.0.1 mapping, and the suite stays green.
Nothing tests the krunkit refusal at pkg/driver/krunkit/krunkit_driver_darwin_arm64.go:190-192 either.
}
}
func (l *LimaKrunkitDriver) Validate(_ context.Context) error {
// Configure, which deletion also uses, runs validateConfig, so this start-time check is here.
if cfg := l.Instance.Config; cfg != nil && cfg.HostLoopback != nil && !*cfg.HostLoopback {
return errors.New("`hostLoopback: false` is not supported in krunkit driver")
}
return validateConfig(l.Instance.Config)
}
func checkKrunkitVersion() error {
cmd := exec.CommandContext(context.Background(), vmType, "--version")
krunkit starts its own netstack without the option (pkg/driver/krunkit/krunkit_darwin_arm64.go:195), so without the refusal a krunkit guest keeps host loopback while the user believes it is blocked. Round 1 dropped this test because validateConfig looks up the krunkit binary first, but the refusal now returns before that lookup. CI only type-checks _darwin_arm64_test.go files, so the krunkit test runs only on Apple silicon developer machines.
return nil, nil, err
}
os.RemoveAll(endpointSock)
os.RemoveAll(krunkitSock)
ctx, cancel := context.WithCancel(ctx)
err = usernet.StartGVisorNetstack(ctx, &usernet.GVisorNetstackOpts{
MTU: 1500,
Endpoint: endpointSock,
FdSocket: krunkitSock,
Async: true,
DefaultLeases: map[string]string{
Reproducer
# Save as mutate-links.sh; run on an Apple silicon Mac from the repo root: bash mutate-links.sh
set -u
f1=pkg/networks/usernet/gvproxy.go
f2=pkg/driver/krunkit/krunkit_driver_darwin_arm64.go
cp "$f1" "$f1.orig"
cp "$f2" "$f2.orig"
# 1: pass false at the call site, so hostLoopback: false keeps the 127.0.0.1 mapping
perl -pi -e 's/natTable\(gatewayIP, opts\.DisableHostLoopback\)/natTable(gatewayIP, false)/' "$f1"
# 2: delete the krunkit refusal
perl -0pi -e 's/\t\/\/ Configure, which deletion also uses.*?\n\tif cfg := .*?\n.*?\n\t\}\n//s' "$f2"
git diff --stat -- "$f1" "$f2"
go test -count=1 ./pkg/networks/usernet/ ./pkg/driver/vz/ ./pkg/driver/krunkit/ 2>&1 | grep -E '^(ok|FAIL|--- FAIL)'
mv "$f1.orig" "$f1"
mv "$f2.orig" "$f2"
$ bash mutate-links.sh
pkg/driver/krunkit/krunkit_driver_darwin_arm64.go | 4 ----
pkg/networks/usernet/gvproxy.go | 2 +-
2 files changed, 1 insertion(+), 5 deletions(-)
ok github.com/lima-vm/lima/v2/pkg/networks/usernet 0.535s
ok github.com/lima-vm/lima/v2/pkg/driver/vz 2.651s
ok github.com/lima-vm/lima/v2/pkg/driver/krunkit 0.821s
$ git apply i1.patch && bash mutate-links.sh
pkg/driver/krunkit/krunkit_driver_darwin_arm64.go | 4 ---
pkg/networks/usernet/gvproxy.go | 36 ++++++++++++++---------
2 files changed, 22 insertions(+), 18 deletions(-)
--- FAIL: TestNetstackConfigurationNAT (0.00s)
FAIL
FAIL github.com/lima-vm/lima/v2/pkg/networks/usernet 0.483s
ok github.com/lima-vm/lima/v2/pkg/driver/vz 2.843s
--- FAIL: TestValidateRejectsHostLoopbackFalse (0.01s)
FAIL
FAIL github.com/lima-vm/lima/v2/pkg/driver/krunkit 0.566s
FAIL
Fix: build the gvisor configuration in a helper and test its NAT table for both values of the option, and test the krunkit refusal through Validate.
Patch
diff --git a/pkg/driver/krunkit/krunkit_driver_darwin_arm64_test.go b/pkg/driver/krunkit/krunkit_driver_darwin_arm64_test.go
index bd1ce966..6635adce 100644
--- a/pkg/driver/krunkit/krunkit_driver_darwin_arm64_test.go
+++ b/pkg/driver/krunkit/krunkit_driver_darwin_arm64_test.go
@@ -17,6 +17,11 @@ func TestValidateConfigRejectsBlockDevices(t *testing.T) {
assert.ErrorContains(t, err, "field `blockDevices` is not supported for vmType: krunkit")
}
+func TestValidateRejectsHostLoopbackFalse(t *testing.T) {
+ l := &LimaKrunkitDriver{Instance: &limatype.Instance{Config: &limatype.LimaYAML{HostLoopback: new(false)}}}
+ assert.ErrorContains(t, l.Validate(t.Context()), "`hostLoopback: false` is not supported in krunkit driver")
+}
+
func TestValidateSnapshotTag(t *testing.T) {
tests := []struct {
tag string
diff --git a/pkg/networks/usernet/gvproxy.go b/pkg/networks/usernet/gvproxy.go
index 5f03b188..27849ba4 100644
--- a/pkg/networks/usernet/gvproxy.go
+++ b/pkg/networks/usernet/gvproxy.go
@@ -48,9 +48,27 @@ const gatewayMacAddr = "5a:94:ef:e4:0c:dd"
func StartGVisorNetstack(ctx context.Context, gVisorOpts *GVisorNetstackOpts) error {
opts = gVisorOpts
+ config, err := netstackConfiguration(opts)
+ if err != nil {
+ return err
+ }
+
+ groupErrs, ctx := errgroup.WithContext(ctx)
+ err = run(ctx, groupErrs, config)
+ if err != nil {
+ return err
+ }
+ if opts.Async {
+ return err
+ }
+ return groupErrs.Wait()
+}
+
+// netstackConfiguration returns the gvisor-tap-vsock configuration for opts.
+func netstackConfiguration(opts *GVisorNetstackOpts) (*types.Configuration, error) {
ip, ipNet, err := net.ParseCIDR(opts.Subnet)
if err != nil {
- return err
+ return nil, err
}
gatewayIP := GatewayIP(ip)
@@ -70,7 +88,7 @@ func StartGVisorNetstack(ctx context.Context, gVisorOpts *GVisorNetstackOpts) er
// Comparing this with QEMU SLIRP,
// - DNS is equivalent to GatewayIP
// - GatewayIP is equivalent to NAT configuration
- config := types.Configuration{
+ return &types.Configuration{
Debug: false,
MTU: opts.MTU,
Subnet: opts.Subnet,
@@ -82,17 +100,7 @@ func StartGVisorNetstack(ctx context.Context, gVisorOpts *GVisorNetstackOpts) er
DNSSearchDomains: searchDomains(),
NAT: natTable(gatewayIP, opts.DisableHostLoopback),
GatewayVirtualIPs: []string{gatewayIP},
- }
-
- groupErrs, ctx := errgroup.WithContext(ctx)
- err = run(ctx, groupErrs, &config)
- if err != nil {
- return err
- }
- if opts.Async {
- return err
- }
- return groupErrs.Wait()
+ }, nil
}
// natTable returns the gateway's NAT table. By default the gateway IP maps to the host's loopback,
diff --git a/pkg/networks/usernet/gvproxy_test.go b/pkg/networks/usernet/gvproxy_test.go
index 53c0a823..fc041a31 100644
--- a/pkg/networks/usernet/gvproxy_test.go
+++ b/pkg/networks/usernet/gvproxy_test.go
@@ -46,6 +46,14 @@ func TestNATTable(t *testing.T) {
})
}
+func TestNetstackConfigurationNAT(t *testing.T) {
+ for _, disable := range []bool{false, true} {
+ config, err := netstackConfiguration(&GVisorNetstackOpts{Subnet: "192.168.5.0/24", DisableHostLoopback: disable})
+ assert.NilError(t, err)
+ assert.DeepEqual(t, config.NAT, natTable("192.168.5.2", disable))
+ }
+}
+
func createResolveFile(t *testing.T, file, content string) {
f, err := os.Create(file)
assert.NilError(t, err)
Suggestions ¶
propagateProxyEnv, but the rewrite also takes proxies from the host's network settings and env Claude Opus 5.5¶
# DNS, outbound access to other hosts and `limactl shell` keep working.
# Set this to false for a guest that runs untrusted code, such as a CI runner.
# - Only supported with `vmType: vz`. Not supported with a `user-v2` network, which is shared by instances.
# - Does not restrict the host's other addresses: a host service bound to all interfaces is still
# reachable through the host's LAN IP.
# - A proxy on the host's loopback (e.g. `http_proxy=http://127.0.0.1:3128`, propagated by
# `propagateProxyEnv`) becomes unreachable from the guest.
# 🟢 Builtin default: true
hostLoopback: null
# EXPERIMENTAL
# When enabled, an emulated TPM 2.0 device is provided to the guest via swtpm.
setupEnv starts from osutil.ProxySettings(), which reads the macOS network proxy settings. It then adds env from lima.yaml, adds the limactl process environment only when propagateProxyEnv is true, and rewrites a loopback proxy from any of the three to the gateway. So a user who turns propagateProxyEnv off to avoid the unreachable proxy still gets a proxy the guest cannot reach. The warning does fire in that case.
website/content/en/docs/config/network/user.md:32 and the commit body say the same.
hostLoopback: false
```
DNS, outbound connections to other hosts and `limactl shell` keep working. Connections to `host.lima.internal` are refused instead.
A host service that listens on all interfaces is still reachable through the host's LAN address.
A proxy on the host's loopback (for example `http_proxy=http://127.0.0.1:3128`, propagated by `propagateProxyEnv`) becomes unreachable from the guest.
`hostLoopback: false` is only supported with `vmType: vz`, and not with a [`user-v2`]({{< ref "/docs/config/network/user-v2" >}}) network.
## DNS (192.168.5.3)
Fix: name all three sources, for example "A proxy on the host's loopback, whether from the host's network settings, env, or propagateProxyEnv, becomes unreachable from the guest."
user-v2 test fails by panic, and it still passes when the refusal moves back into validateConfig Claude Opus 5.5 Codex GPT 6 Astra¶
Firmware: limatype.Firmware{LegacyBIOS: new(false)},
HostLoopback: new(false),
Networks: []limatype.Network{{Lima: "user-v2"}},
}
l := &LimaVzDriver{Instance: &limatype.Instance{Config: cfg}}
assert.ErrorContains(t, l.Validate(t.Context()), "not supported with a `user-v2` network")
}
Deleting the refusal at pkg/driver/vz/vz_driver_darwin.go:262 fails this test only through a nil-pointer panic in validateConfig, which dereferences fields the fixture leaves unset.
return scripts, nil
}
func (l *LimaVzDriver) Validate(_ context.Context) error {
// Configure, which deletion also uses, runs validateConfig, so this start-time check is here.
if cfg := l.Instance.Config; cfg != nil && !limayaml.HostLoopbackEnabled(cfg) && limayaml.FirstUsernetIndex(cfg) != -1 {
return errors.New("`hostLoopback: false` is not supported with a `user-v2` network, which is shared by instances")
}
if err := validateConfig(l.Instance.Config); err != nil {
return err
}
Moving the refusal back into validateConfig, which limactl delete runs, leaves the test green. The qemu, WSL2 and HCS tests catch that by asserting that validateConfig accepts the config. The test is optional, because a misplaced refusal makes limactl delete fail with an error that names the field.
Fix: fill the config with FillDefault and run Configure, the path deletion uses, before Validate. This version passes, and fails once the refusal moves into validateConfig.
t.Setenv("LIMA_HOME", t.TempDir())
y := limatype.LimaYAML{VMType: new(limatype.VZ), HostLoopback: new(false), Networks: []limatype.Network{{Lima: "user-v2"}}}
limayaml.FillDefault(t.Context(), &y, &limatype.LimaYAML{}, &limatype.LimaYAML{}, "test.yaml", false)
l := &LimaVzDriver{}
_, err := l.Configure(t.Context(), &limatype.Instance{Dir: t.TempDir(), Config: &y})
assert.NilError(t, err)
assert.ErrorContains(t, l.Validate(t.Context()), "not supported with a `user-v2` network")
setupEnv with hostLoopback false Codex GPT 6 Astra Gemini 3.1 Pro Gemini 3.5 Flash¶
for _, httpProxy := range httpProxyCases {
t.Run(httpProxy.Host, func(t *testing.T) {
envKey := "http_proxy"
envValue := httpProxy.String()
envs, err := setupEnv(map[string]string{envKey: envValue}, false, true, networks.SlirpGateway)
assert.NilError(t, err)
assert.Equal(t, envs[envKey], strings.ReplaceAll(envValue, httpProxy.Hostname(), networks.SlirpGateway))
})
}
}
Every caller passes true, so neither the warning nor the round-1 break has a test; deleting the break leaves go test ./pkg/cidata/ green. Round 1 rated this test optional, and it still is. A regression costs a missing or duplicated warning, and the guest's refused proxy connection still points at the cause.
Fix: stub netLookupIP to return 127.0.0.1 and ::1, pass false, capture the logrus output, and assert one warning that quotes the original URL.
Design Observations ¶
Concerns ¶
- (future) An older
limactlreadshostLoopback: falseas an unknown field, logs "Non-strict YAML detected" (pkg/limayaml/marshal.go:81), and starts the guest with host loopback reachable. For an option meant for untrusted guests, the docs could suggest settingminimumLimaVersionto the first release that has the field, so an olderlimactlrefuses the template. Claude Opus 5.5
Strengths ¶
- Mapping to
0.0.0.1fails at once on macOS. On this Mac a TCP dial gets "no route to host" in under a millisecond and a UDP write fails the same way. Claude Opus 5.5 Gemini 3.1 Pro Gemini 3.5 Flash - No other address reaches host loopback. gvisor drops packets from the guest addressed to
127/8, the stack does not register IPv6, and macOS has no route to the other0.0.0.xaddresses. No TCP or UDP frame to127.0.0.1,0.0.0.0or0.0.0.2reached a listener bound to127.0.0.1. Claude Opus 5.5 Codex GPT 6 Astra - The refusals in
Validatekeeplimactl deleteworking. Round 1's delete probe now removes a qemu instance withhostLoopback: falsein_config/default.yaml. Codex GPT 6 Astra Gemini 3.1 Pro Gemini 3.5 Flash
Testing Assessment ¶
I ran go test ./... in the lead worktree at the review SHA: exit 0, 49 packages ok, none failed. GOOS=windows go vet is clean for pkg/driver/hcs and pkg/driver/wsl2, and both test binaries compile for Windows. On 46771eb0, 35 CI checks pass and the three Netlify rule checks are skipped.
Each round-1 fix holds under its round-1 probe, re-run on this SHA. A closed port answers with an RST after 0.00 s, ten pending dials no longer block a new connection, UDP to 0.0.0.0 no longer arrives, and instance.Delete removes the instance.
I applied each mutation alone and ran the package's tests:
| Mutation | Result |
|---|---|
vz drops the ! before limayaml.HostLoopbackEnabled | TestGVisorNetstackOptsHostLoopback fails |
vz user-v2 refusal deleted | TestValidateRejectsHostLoopbackFalseWithUserV2 fails by panic |
vz user-v2 refusal added to validateConfig | green (S2) |
qemu refusal added to validateConfig | TestValidateRejectsHostLoopbackFalse fails |
natTable called with false | green (I1) |
| krunkit refusal deleted | green (I1) |
setupEnv break deleted | green (S3) |
- Required: the
natTablecall site and the krunkit refusal (I1). A regression silently leaves host loopback reachable. - Optional: vz
ConfigureacceptinghostLoopback: falsewithuser-v2(S2). The failure names the field. - Optional:
setupEnvwithhostLoopbackfalse (S3). - Dropped: the frame probes as permanent tests. They depend on the host's routing table.
Documentation Assessment ¶
- The proxy caveat leaves out the host's network settings and
envintemplates/default.yaml:702-703,website/content/en/docs/config/network/user.md:32and the commit body (S1). - "Connections to
host.lima.internalare refused" now holds, as measured above, and so do the vz-only,user-v2and LAN-reachability statements.
Acknowledged Limitations ¶
- External drivers from the registry still ignore
hostLoopback: false. The author agreed and deferred a driver feature flag to a follow-up. - krunkit,
user-v2and QEMU'sdisable_host_loopbackare deferred, and each rejectsfalse. - A host service bound to all interfaces stays reachable through the host's LAN IP (
templates/default.yaml:700-701). The change does not make that worse. - With the refusals in
Validate,limactl createon an unsupported driver writes the instance, andlimactl startthen refuses it;limactl editcan clear the setting. Round 1 accepted this as the cost of a deletable instance. - Do not re-suggest moving the refusals into
limayaml.Validate. It runs on every load (pkg/store/store.go:127), so the instance would become unlistable and undeletable. - Do not re-suggest remapping the gateway to
127.0.0.2or240.0.0.1. On macOS both time out instead of failing at once (round 1 measured 75 s and over 5 s). - Do not re-suggest mapping
127.0.0.1innatTable, or documenting aroute_localnetbypass. gvisor drops packets from the guest addressed to127/8unlessAllowExternalLoopbackTrafficis set (gvisorpkg/tcpip/network/ipv4/ipv4.go:840-849), gvisor-tap-vsock v0.8.9 never sets it, and a frame probe to127.0.0.1reached nothing. - Do not re-raise the qemu
Validatepanic on a nil config.CreateConfiguredDriverdereferencesinst.Config(pkg/driverutil/instance.go:22) before any driver method runs, and on macOS the merge-base panics on a nil config too, invalidateArch.
Agent Performance Retro ¶
Claude Opus 5.5 ¶
Claude was the only agent to rate the krunkit gap Important. It asked what a deleted refusal does, not where the refusal is. It alone found the untested natTable call site, and both mutation probes held up when rerun. It alone found S1, by reading where setupEnv gets its proxies, and the downgrade concern, and it found both halves of S2. Its suggestion to spell the five refusals one way was dropped as style, since three of those files would need a new import for no change in behavior. The orchestrator did not arm Claude's liveness monitor; the agent finished without needing it.
Codex GPT 6 Astra ¶
Codex re-verified every round-1 item in a table that names the test pinning each fix. It also found the placement half of S2, with a probe that called Configure before Validate. It rated the krunkit test optional because "a reverted refusal would fail deterministically with an error naming the setting". That holds for a misplaced refusal but not a deleted one, since krunkit's netstack ignores the option. It marked gvproxy.go reviewed with no issues, and it recorded its revert outcomes as reasoned, not run. The first launch failed with "Selected model is at capacity", and the one retry succeeded.
Gemini 3.1 Pro ¶
Gemini Pro's I1, a guest root routing 127.0.0.1 to the gateway, is a false positive. gvisor drops those packets, as Claude and Codex both cited from source, and the frame probe confirms it. Its I2, a qemu Validate panic on a nil config, was dropped because no caller can pass one. It added a nil-config test to qemu_test.go in its own worktree; its other file verdicts stand against a clean checkout. It raised the krunkit and setupEnv test gaps, both as Suggestions.
Gemini 3.5 Flash ¶
Flash raised the same nil-config panic with a regression label that holds only off macOS; on macOS the merge-base also panics, in validateArch. Its S3 repeats the 127.0.0.1 claim as defense in depth. Its proposed krunkit test asserts that validateConfig succeeds, which fails on any machine without the krunkit binary. The two Gemini models agree on the nil-config panic and the 127.0.0.1 path, which counts as one opinion, not two.
Summary ¶
| Claude Opus 5.5 | Codex GPT 6 Astra | Gemini 3.1 Pro | Gemini 3.5 Flash | |
|---|---|---|---|---|
| Duration | 7m 19s | 7m 38s | 10m 29s | 8m 55s |
| Findings | 1I 2S | 1I 2S | 1I 1S | 1I 1S |
| Tool calls | 35 (Bash 31, Read 4) | 15 (shell 13, stdin 2) | 27 (runshellcommand 27) | 78 (runshellcommand 27, grepsearch 22, readfile 17) |
| Design observations | 4 | 3 | 2 | 2 |
| False positives | 0 | 0 | 1 | 1 |
| Unique insights | 4 | 0 | 0 | 0 |
| Files reviewed | 20 | 20 | 20 | 20 |
| Coverage misses | 0 | 1 | 0 | 0 |
| Totals | 1I 2S | 1I 2S | 1I 1S | 1I 1S |
| Downgraded | 0 | 0 | 0 | 0 |
| Dropped | 1 | 0 | 2 | 2 |
Claude supplied the most value. It alone saw the natTable half of I1, rated I1 Important, and found S1. Codex supplied the most careful accounting of the round-1 fixes. Both Gemini models found the krunkit gap but filed false or unreachable findings as Important.
Reconciliation. Codex GPT 6 Astra P1 S1 (krunkit half): suggestion → important I1; its vz half became S2. Gemini 3.1 Pro P1 S1: suggestion → important I1. Gemini 3.5 Flash P1 S1: suggestion → important I1. Gemini 3.1 Pro P1 I1 and Gemini 3.5 Flash P1 S3 (127.0.0.1 path): dropped as false positives. Gemini 3.1 Pro P1 I2 and Gemini 3.5 Flash P1 I1 (qemu nil config): dropped as unreachable. Claude Opus 5.5 P1 S2 (one spelling of the refusals): dropped as style.
Review Process Notes ¶
Skill improvements ¶
- When rating a missing test for a guard, rate the guard's deletion as well as its relocation. A refusal whose deletion leaves an option silently ignored needs a test, even when moving it to the wrong place would fail loudly with an error naming the cause.
Repo context updates ¶
- [repo] ADD: vz and krunkit each start their own in-process gvisor-tap-vsock netstack, each from its own
startUsernetwith its ownGVisorNetstackOptsliteral. An option wired into one does not reach the other, so a driver that refuses a vz-only network option depends on that refusal alone. Check both call sites when a change touchesGVisorNetstackOpts. - [repo] ADD: gvisor, as gvisor-tap-vsock v0.8.9 configures it, drops packets from the guest with a
127/8source or destination (AllowExternalLoopbackTrafficis unset) and does not register an IPv6 protocol. A guest cannot reach host loopback by addressing127.0.0.1directly, whatever routes it adds; the paths to host loopback are the NAT table's entries and UDP to0.0.0.0, which macOS treats as a dial to its own loopback. - [repo] ADD:
driverutil.CreateConfiguredDriverdereferencesinst.Configbefore any driver method runs, so a driver'sConfigureandValidatealways see a non-nil config in production. Rate a nil-config crash inside a driver method as latent, not as a regression.