Skip to content

use /proc/thread-self for mounting network namespace#45682

Closed
spikecurtis wants to merge 1 commit intomoby:masterfrom
spikecurtis:45681-thread-mount-namespace
Closed

use /proc/thread-self for mounting network namespace#45682
spikecurtis wants to merge 1 commit intomoby:masterfrom
spikecurtis:45681-thread-mount-namespace

Conversation

@spikecurtis
Copy link
Copy Markdown

@spikecurtis spikecurtis commented Jun 2, 2023

- What I did

Fixes an issue where --net=host runs would fail if Docker is run within a sysbox container.

- How I did it

--net=host mounts the network namespace without using unshare, but the code uses a call to unix.Gettid() for the thread ID, builds the /proc path from it, then issues the syscall. Without unshare code on the same goroutine can be run on different OS threads, and it appears the syscall is run on a different thread and fails.

We can simplify and fix the logic by using /proc/thread-self instead of querying for the threadID.

- How to verify it

c.f. repro steps in #45681

- Description for the changelog

fixed an issue where --net=host would fail in restricted environments, for example sysbox

- A picture of a cute animal (not mandatory but encouraged)

IMG_1673

@thaJeztah
Copy link
Copy Markdown
Member

@corhere PTAL

/cc @ctalledo

Copy link
Copy Markdown
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/proc/thread-self does not exist on the oldest kernels we support so cannot be used

@corhere
Copy link
Copy Markdown
Contributor

corhere commented Jun 2, 2023

If mounting one thread's netns from another thread is the problem, use runtime.LockOSThread() to guarantee that the goroutine is running on the same thread for both the gettid and the mount call.

@spikecurtis
Copy link
Copy Markdown
Author

Tried with runtime.LockOSThread() and this unfortunately doesn't resolve the issue with sysbox. It's a mystery to my why /proc/thread-self works, but not /proc/self/task/<tid> with the correct thread ID.

I think that means my theory for what's wrong is false, so closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--net=host fails for Docker-in-Docker with sysbox

3 participants