moby / moby/libnetwork

Wrong way to detect network namespace from prestart hook

Open
#1,718 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.2k
Forks
875
PR merge metrics
No merged PRs in 30d

Description

In case of prestart hook, the network is set relying on /proc/<PID>/ns/net to find the network namespace (https://github.com/docker/libnetwork/blob/master/sandbox_externalkey_unix.go#L54).
But in case the runtime process has switched to the expected network namespace while it has a thread ID different from the process ID, libnetwork will find a wrong/different network namespace.

In order to avoid such issues, it would be good modify https://github.com/docker/libnetwork/blob/master/sandbox_externalkey_unix.go, relying on /proc/<PID>/task/<TID>/ns/net instead.
This asks the question about how to retrieve this thread ID because right now the code relies on https://github.com/opencontainers/runc/blob/master/libcontainer/configs/config.go#L263 which relies on OCI runtime spec here: https://github.com/opencontainers/runtime-spec/blob/master/specs-go/state.go

But I doubt this specs.State structure to be adapted to the purpose of the hook. I mean, I don't think we want to add a new Tid string field to this structure. Instead, we should define HookState with the same fields than specs.State and add this new Tid field.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in sandbox_externalkey_unix.go and trace the prestart-hook network namespace lookup, then read the referenced runc config.go and OCI specs.State definitions. Determine how the hook can obtain a thread ID without changing specs.State, and verify that the lookup uses /proc//task//ns/net for the intended namespace.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux
Domain
networking, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.