runtime sockets: close the local-user race window around control-plane creation

Previously the daemon socket, per-VM firecracker API socket, and vsock
socket were transiently world-exposed on hosts without XDG_RUNTIME_DIR:
the runtime directory landed in /tmp at 0755, Firecracker ran with
umask 000 (mode 0666 sockets), and only a follow-up chown/chmod in
EnsureSocketAccess tightened them. A local attacker could race into
bangerd.sock or the firecracker API socket during that window.

Three changes:

- internal/paths/paths.go: RuntimeDir is now created (and re-chmod'd if
  stale) at 0700 unconditionally. When XDG_RUNTIME_DIR is unset and we
  fall back to /tmp/banger-runtime-<uid>, Ensure() now verifies the
  parent dir is owned by the current uid and 0700 mode — refusing to
  place sockets inside a directory someone else created. Symlink swaps
  rejected via Lstat.

- internal/firecracker/client.go: launch firecracker with umask 077
  instead of umask 000 so the API socket is mode 0600 from birth. The
  chown in fcproc.EnsureSocketAccess still transfers ownership from
  root to the invoking user afterwards.

- internal/daemon/fcproc/fcproc.go: EnsureSocketDir now creates (and
  re-chmod's) the runtime socket directory at 0700.

Tests cover the tightening path — an existing 0755 RuntimeDir is
re-chmod'd on Ensure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-20 12:53:47 -03:00
parent 2b6437d1b4
commit b930c51990
No known key found for this signature in database
GPG key ID: 33112E6833C34679
5 changed files with 119 additions and 13 deletions

View file

@ -68,9 +68,15 @@ func (m *Manager) EnsureBridge(ctx context.Context) error {
return err
}
// EnsureSocketDir creates the runtime socket directory.
// EnsureSocketDir creates the runtime socket directory at 0700. This is
// the directory the daemon socket, per-VM firecracker API sockets, and
// vsock sockets all live inside, so it must be readable only by the
// invoking user.
func (m *Manager) EnsureSocketDir() error {
return os.MkdirAll(m.cfg.RuntimeDir, 0o755)
if err := os.MkdirAll(m.cfg.RuntimeDir, 0o700); err != nil {
return err
}
return os.Chmod(m.cfg.RuntimeDir, 0o700)
}
// CreateTap (re)creates a TAP owned by the current uid/gid, attaches it to