-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly setuid/setgid after entering userns #606
Conversation
strace details on the "0555" perms:
The stat, mount, fchmodat relate to the code highlighted: https://github.com/opencontainers/runc/blob/master/libcontainer/rootfs_linux.go#L146-L160 |
Also, for further detail, this is
|
Interesting. I wonder if it is related to the umask which is somehow different now.. (just a theory). |
@mrunalp: @crosbymichael thought something similar (and so did I initially) but I can't find anything different about umask before/after this commit. What does seem different in a full strace comparison is the way Go process startup used to handle setuid/setgid after setting up the mappings. In fact, in testing after a local vendoring-in to Docker, I now have to explicitly set up the user string to " UPDATE: However.. as a counterpoint, sprinking |
@estesp Are you sure the mode is the root cause here? Isn't 0555 actually valid?
However, I did notice that prior to the recent changes, setuid(0) was called before setting up rootfs, and this is no longer the case. As a quick hack, moving setgid/setuid before setupRootfs() seems to fix the issue. |
@codido you are correct that Where did you put the setuid/setgid to resolve the issue? I tried several things yesterday without any luck. |
@estesp added that just before calling setupRootfs(). It's not a valid patch, just a hack to verify that this is indeed the culprit. |
@codido understand, but was curious because I tried the same but have no change in behavior. Just tried again to confirm--still no change. :( |
@estesp Here's the hack I used to test this:
Before applying it, and using a more or less default spec with userns, I got this:
With this hack applied the container started successfully. |
Ok, that is quite interesting that using Golang UPDATE: Lesson learned on not checking errors even with a quick hack; from pkg/syscall/syscall_linux.go:
|
I guess in the end, root cause is this fact:
We are not root in the user-namespaced process by the time we are running the |
@estesp Previously the setuid/setgid was done after mappings were written in go standard library. We could make the calls in the C code after setsid in nsexec.c |
@estesp Also, they are safe to make as we always require a mapping for 0. |
@mrunalp I think I'm only slightly losing my mind :)
I have no idea why. |
@estesp I noticed that as well but haven't root caused it :) |
@codido Even if we move setuid/setgid to beginning to Init (before the oomscoreadj) we see the same issue. What is a bit puzzling here is that previously also we were root at this point of time in the code. |
@codido Also, the new proc mount and pivot root only happen in setupRootfs so that shouldn't be an issue as it was the same earlier, too. |
I tried moving setOomScoreAdj after setupRootfs, but still see the same error. |
@mrunalp Right. It appears that a process that calls setuid() cannot access it's own oom_score_adj until it calls re-executes. Not sure if that's intended though:
|
Hmm, we could try adjusting it from the parent on procReady. Sent from my iPhone
|
f36b31b
to
ce5be72
Compare
ce5be72
to
820abf1
Compare
@mrunalp this has been reworked after your idea about setting @crosbymichael hopefully this is the more appropriate fix so that I can vendor libcontainer into Docker and get shared namespaces. |
@estesp Nice! I will test it out once before acking. |
In that case it may work by moving setting the oom score in |
Yes another option is to do it in C code but will have to pass additional config that we can avoid by setting it from parent. Sent from my iPhone
|
820abf1
to
50a4667
Compare
@mrunalp @mlaventure fixed properly now. PTAL. I even tested :) |
@estesp Thanks! LGTM. |
nice, looks good! |
The re-work of namespace entering lost the setuid/setgid that was part of the Go-routine based process exec in the prior code. A side issue was found with setting oom_score_adj before execve() in a userns that is also solved here. Docker-DCO-1.1-Signed-off-by: Phil Estes <[email protected]> (github: estesp)
50a4667
to
178bad5
Compare
rebased. @crosbymichael: I'd like to vendor this into Docker as well as another commit from earlier soon; PTAL when you have a chance |
btw according to http://www.openwall.com/lists/kernel-hardening/2016/01/20/14 you need to set uid and gid BEFORE you're joining namespace :) |
Properly setuid/setgid after entering userns
@LK4D4 it's on my todo list :) |
Yeah we could do that now we are not bound to the go standard library :) Sent from my iPhone
|
Also if we make runc truly unprivileged for userns then we don't need to even that. I have a branch with a poc. Sent from my iPhone
|
The re-work of namespace entering lost the setuid/setgid that was part
of the Go-routine based process exec in the prior code. A side issue was
found with setting oom_score_adj before execve() in a userns that is
also solved here.
Docker-DCO-1.1-Signed-off-by: Phil Estes [email protected] (github: estesp)