Deep Review: 20261007-102123-pr-5581

Date2026-10-07 10:21
Repolima-vm/lima
Round2
Author@ranacseruet
PR#5581 — vz: add hostLoopback option to block guest access to host loopback
Branchfeat/host-loopback-opt-out
Commits46771eb0 vz: add hostLoopback option to block guest access to host loopback
Review SHA46771eb073d74fc53a5f7160aee6eb623c27c9bf
ReviewersClaude Opus 5.5 (effort: high), Codex GPT 6 Astra (effort: high), Gemini 3.1 Pro (effort: default), Gemini 3.5 Flash (effort: default)
VerdictMerge with fixes — every round-1 fix holds; two links that make the option work are still untested
Wall-clock time20 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

I1. No test covers the 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

S1. The proxy caveat names only 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."

S2. The vz 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")
S3. No test runs 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

Strengths


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:

MutationResult
vz drops the ! before limayaml.HostLoopbackEnabledTestGVisorNetstackOptsHostLoopback fails
vz user-v2 refusal deletedTestValidateRejectsHostLoopbackFalseWithUserV2 fails by panic
vz user-v2 refusal added to validateConfiggreen (S2)
qemu refusal added to validateConfigTestValidateRejectsHostLoopbackFalse fails
natTable called with falsegreen (I1)
krunkit refusal deletedgreen (I1)
setupEnv break deletedgreen (S3)
  1. Required: the natTable call site and the krunkit refusal (I1). A regression silently leaves host loopback reachable.
  2. Optional: vz Configure accepting hostLoopback: false with user-v2 (S2). The failure names the field.
  3. Optional: setupEnv with hostLoopback false (S3).
  4. Dropped: the frame probes as permanent tests. They depend on the host's routing table.

Documentation Assessment


Acknowledged Limitations


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.5Codex GPT 6 AstraGemini 3.1 ProGemini 3.5 Flash
Duration7m 19s7m 38s10m 29s8m 55s
Findings1I 2S1I 2S1I 1S1I 1S
Tool calls35 (Bash 31, Read 4)15 (shell 13, stdin 2)27 (runshellcommand 27)78 (runshellcommand 27, grepsearch 22, readfile 17)
Design observations4322
False positives0011
Unique insights4000
Files reviewed20202020
Coverage misses0100
Totals1I 2S1I 2S1I 1S1I 1S
Downgraded0000
Dropped1022

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

Repo context updates