Skip to content
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

Fix error from runc run on noexec fs #3522

Merged
merged 1 commit into from
Aug 2, 2022

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jun 30, 2022

When starting a new container, and the very last step of executing of a
user process fails (last lines of (*linuxStandardInit).Init), it is too
late to print a proper error since both the log pipe and the init pipe
are closed.

This is partially mitigated by using exec.LookPath() which is supposed
to say whether we will be able to execute or not. Alas, it fails to do
so when the binary to be executed resides on a filesystem mounted with
noexec flag.

A workaround is to use access(2) with X_OK flag. Alas, it is not
working when runc itself is a setuid (or setgid) binary. In this case,
faccessat2(2) with AT_EACCESS can be used, but it is only available
since Linux v5.8.

So, use faccessat2(2) with AT_EACCESS if available. If not, fall back to
access(2) for non-setuid runc, and do nothing for setuid runc (as there
is nothing we can do). Note that this check if in addition to whatever
exec.LookPath does.

The proper fix is something like https://go-review.googlesource.com/c/go/+/414824 but it won't be available for a while.

Fixes #3520

@kolyshkin kolyshkin added kind/bug backport/1.1-todo A PR in main branch which needs to be backported to release-1.1 labels Jun 30, 2022
@kolyshkin kolyshkin added this to the 1.2.0 milestone Jun 30, 2022
@kolyshkin
Copy link
Contributor Author

kolyshkin commented Jun 30, 2022

@opencontainers/runc-maintainers do we ever use runc as a setuid or setgid binary? If yes, this commit will break it, since access(2) checks the real, not effective, uid/gid, and we need faccessat2 with AT_EACCESS (which is actually only supported since Linux v5.8, but x/sys/unix workarounds it so we can use unix.Faccessat).

kolyshkin added a commit to kolyshkin/podman that referenced this pull request Jun 30, 2022
A newer runc (v1.1.x) changed the error message again, so simplify the
check to look for a common denominator of all these errors.

Note that due to an entirely different issue [1] the test still fails when
using runc, but this is being fixed elsewhere ([2], [3]). This will
presumably be fixed in runc 1.1.4 and runc 1.2.0.

[1] opencontainers/runc#3520
[2] opencontainers/runc#3522
[3] https://go-review.googlesource.com/c/go/+/414824

Signed-off-by: Kir Kolyshkin <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Sorry NOTLGTM, as potentially somebody might be using runc with setuid bit

(I know colima and Rancher Desktop launch nerdctl with setuid bit. AFAICS they do not launch runc with setuid bit, but I assume there are some similar projects and some of them may launch runc with setuid bit)

@kolyshkin
Copy link
Contributor Author

(I know colima and Rancher Desktop launch nerdctl with setuid bit. AFAICS they do not launch runc with setuid bit, but I assume there are some similar projects and some of them may launch runc with setuid bit)

Thanks! I explained above this is not a problem -- we just need a more complex check for this case.

Working on it.

@kolyshkin kolyshkin marked this pull request as draft July 1, 2022 16:42
@kolyshkin kolyshkin marked this pull request as draft July 1, 2022 16:42
When starting a new container, and the very last step of executing of a
user process fails (last lines of (*linuxStandardInit).Init), it is too
late to print a proper error since both the log pipe and the init pipe
are closed.

This is partially mitigated by using exec.LookPath() which is supposed
to say whether we will be able to execute or not. Alas, it fails to do
so when the binary to be executed resides on a filesystem mounted with
noexec flag.

A workaround would be to use access(2) with X_OK flag. Alas, it is not
working when runc itself is a setuid (or setgid) binary. In this case,
faccessat2(2) with AT_EACCESS can be used, but it is only available
since Linux v5.8.

So, use faccessat2(2) with AT_EACCESS if available. If not, fall back to
access(2) for non-setuid runc, and do nothing for setuid runc (as there
is nothing we can do). Note that this check if in addition to whatever
exec.LookPath does.

Fixes opencontainers#3520

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin kolyshkin marked this pull request as ready for review July 1, 2022 17:06
@kolyshkin
Copy link
Contributor Author

@AkihiroSuda added suid runc support; PTAL

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

SGTM

do we need more eyes on this?

@AkihiroSuda AkihiroSuda requested a review from cyphar July 5, 2022 07:12
@AkihiroSuda
Copy link
Member

@cyphar LGTY?

Copy link
Member

@cyphar cyphar left a comment

Choose a reason for hiding this comment

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

LGTM.

@cyphar cyphar merged commit bd69483 into opencontainers:main Aug 2, 2022
@kolyshkin kolyshkin added backport/1.1-done A PR in main branch which has been backported to release-1.1 and removed backport/1.1-todo A PR in main branch which needs to be backported to release-1.1 labels Aug 3, 2022
@AkihiroSuda
Copy link
Member

@kolyshkin
Copy link
Contributor Author

@AkihiroSuda from what I see, we need to add a check for CAP_DAC_OVERRIDE -- it it is set, than the lack of x bit can be ignored. I will look at it tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.1-done A PR in main branch which has been backported to release-1.1 kind/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runc run failure logging when the binary is on noexec fs
4 participants