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

utils: Handle close_range more gracefully #4596

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

evanphx
Copy link
Contributor

@evanphx evanphx commented Jan 20, 2025

This fixes 2 things:

  1. The last argument needs to be at most a int32, so be sure to pass only that as the max (discovered under gvisor)
  2. If close_range fails, don't error out, instead just close the fds the long way.

@evanphx evanphx force-pushed the evanphx/b-close-range branch 2 times, most recently from d212348 to 0bdf924 Compare January 20, 2025 04:45
return nil
}

logrus.Debugf("close_range failed, closing range one at a time (error: %v)", err)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I get this. If close range fails and we have detected closeRange is available, what does this fallback add?

The errors it can return don't seem like something using the regular close fallback will fix: https://man7.org/linux/man-pages/man2/close_range.2.html.

Am I missing something? Do you see where this new fallback can help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more defensive, given the existing defensive attempts to see if close_range is available at all. We probe if we can use it, and thusly if for some reason the probe was wrong, we've got the fallback functionality at hand so seems prudent to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @evanphx here -- if we can use a fallback, it makes more sense to use it rather than give up and fail right away. Yes, we might still fail later, but oh well, we tried.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! Should be all ready now.

libcontainer/utils/utils_unix.go Show resolved Hide resolved
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

While the fallback makes sense, the call to CloseRange is guarded by haveCloseRangeCloexec, meaning if the former fails, the latter is not an adequate check.

Or is it failing only because gvisor doesn't like MaxUint? Maybe it makes sense to add const closeRangeMaxFD and use it in both CloseExecFrom and haveCloseRangeCloexec?

Also, the first and last arguments of close_range are of unsigned int type in both glibc and the kernel. From a cursory look at the kernel code I don't see how specifying MaxUint64 can break things in the kernel.

@kolyshkin
Copy link
Contributor

Also, the first and last arguments of close_range are of unsigned int type in both glibc and the kernel. From a cursory look at the kernel code I don't see how specifying MaxUint64 can break things in the kernel.

My bad, I forgot that C int is 32-bit even on a 64-bit platform.

@rata
Copy link
Member

rata commented Jan 22, 2025

@kolyshkin how are these PRs related to gvisor? I thought gvisor was used as an OCI runtime, as a runc replacement. But from your comment, it seems that is not what is happening here, is it? How is that runc and gvisor are run together in this scenario?

@evanphx
Copy link
Contributor Author

evanphx commented Jan 22, 2025 via email

@evanphx evanphx force-pushed the evanphx/b-close-range branch from 0bdf924 to 33315a0 Compare January 24, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants