Skip to content

Do not create or delete a TAP whose short name another guest shares - #615

Draft
yummybomb wants to merge 1 commit into
hypeship/fork-pending-recoveryfrom
hypeship/tap-short-name-guards
Draft

yummybomb wants to merge 1 commit into
hypeship/fork-pending-recoveryfrom
hypeship/tap-short-name-guards

Conversation

@yummybomb

Copy link
Copy Markdown
Contributor

Summary

An allocation is refused, and a release leaves the TAP alone, when another guest directory maps to the same short TAP name.

Split out of #555. Stacked on the fork recovery PR.

Why

A TAP is named after the first eight characters of its instance ID. Two guests whose IDs share that prefix share a name: creating an allocation replaces the link, and releasing one deletes it, whichever guest it belongs to.

What changes

  • reserveAllocationIdentityLocked and RecreateAllocation fail if another guest directory has the same TAP name.
  • A release with an ambiguous name leaves a live TAP in place. ReleaseByInstanceID uses the same check.
  • ReleaseAllocation returns an error for a TAP it could not delete. Callers that tear a guest down log it and continue.
  • deleteTAPDevice returns netlink errors other than "not found".

Testing

  • Unit tests for the refused reservation and the release with a missing shared TAP.
  • TestRecoveryReleasesOnlyUnambiguousKernelTAP creates real TAPs. Its four cases passed as root in a private network namespace on a staging host: an unambiguous TAP is deleted with its fork, a shared name is left in place.
  • Smoke on the same host: fork to Running, delete, and the kill-and-restart runs behave as on the fork recovery branch, with no TAP left.

Not reproduced

The collision itself. IDs are generated, so two guests sharing an eight-character prefix could not be made through the API. With about 2e12 possible prefixes, 1,000 guests on a host collide with a probability of about 2.5e-7.

The TAP leak that was reproduced (a fork killed before its allocation is saved) is fixed in the fork recovery PR, not here.

Review notes

  • Every create, restore and release now reads the guests directory.

A TAP is named after the first eight characters of its instance ID, so
two guests whose IDs share that prefix share a TAP name. Creating an
allocation replaced whatever link had the name, and releasing one
deleted it, whichever guest it belonged to.

Reserving or recreating an allocation now fails if another guest
directory maps to the same TAP name, and a release leaves a live TAP
alone when the name is ambiguous. Both release paths use the same
check, and a release reports a TAP it could not delete instead of only
logging it; callers that tear a guest down still continue, leaving the
TAP to the TAP reconciler.

This branch has not been deployed

No deployments
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.

1 participant