Skip to content

cmd/tailcat: fix genkey --embed-derp-map panic without a fixed region - #91

Merged
bradfitz merged 1 commit into
tailscale:mainfrom
gmkbenjamin:fix-embed-derp-map-panic
Sep 4, 2026
Merged

cmd/tailcat: fix genkey --embed-derp-map panic without a fixed region#91
bradfitz merged 1 commit into
tailscale:mainfrom
gmkbenjamin:fix-embed-derp-map-panic

Conversation

@gmkbenjamin

Copy link
Copy Markdown
Contributor

genkey --embed-derp-map looked up dm.Regions[ci.RegionID] and used the
result without checking it. With --region left at its "auto" default,
ci.RegionID is -1, meaning "probe for the nearest region at each server
startup", so the lookup missed and the nil *tailcfg.DERPRegion crashed
on the next line.

Nothing can be embedded in that case: embedding bakes one region's
nodes into the address, which is the opposite of choosing the region
later. Reject an explicit --region=auto as contradictory, and treat the
"auto" default as a request to pick the nearest region now, exactly as
--fixed-region does, since --embed-derp-map already implies a fixed
region.

Two adjacent forms reached the same nil lookup. A --region naming DERP
hostnames leaves RegionID 0 while already embedding those nodes, so it
is now a usage error; a numeric region absent from the DERP map now
names the missing region instead of panicking.

Thanks to Ray Chan for the report!

Fixes #90

genkey --embed-derp-map looked up dm.Regions[ci.RegionID] and used the
result without checking it. With --region left at its "auto" default,
ci.RegionID is -1, meaning "probe for the nearest region at each server
startup", so the lookup missed and the nil *tailcfg.DERPRegion crashed
on the next line.

Nothing can be embedded in that case: embedding bakes one region's
nodes into the address, which is the opposite of choosing the region
later. Reject an explicit --region=auto as contradictory, and treat the
"auto" default as a request to pick the nearest region now, exactly as
--fixed-region does, since --embed-derp-map already implies a fixed
region.

Two adjacent forms reached the same nil lookup. A --region naming DERP
hostnames leaves RegionID 0 while already embedding those nodes, so it
is now a usage error; a numeric region absent from the DERP map now
names the missing region instead of panicking.

Thanks to Ray Chan for the report!

Fixes tailscale#90

Reported-by: Ray Chan (https://github.com/chanchiwai-ray)

Signed-off-by: Ben B <gmkbenjamin@hotmail.com>
@bradfitz

bradfitz commented Sep 4, 2026

Copy link
Copy Markdown
Member

Thanks. The tests are pretty heavy, but I can lighten those up later if they start to annoy me :)

@bradfitz
bradfitz merged commit 9148b22 into tailscale:main Sep 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] tailcat genkey --embed-derp-map cause panic

2 participants