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

proposal: runtime: add a way to check if fd is used by go runtime #67639

Open
kolyshkin opened this issue May 24, 2024 · 1 comment
Open

proposal: runtime: add a way to check if fd is used by go runtime #67639

kolyshkin opened this issue May 24, 2024 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Proposal
Milestone

Comments

@kolyshkin
Copy link
Contributor

Proposal Details

While working on fixing CVE-2024-21626, we had to implement a function that closes all file descriptors above a specific one (similar to what close_range(2) does). Once we did that, we found out that closing go's internal poll fds results in subsequent panic from go runtime, so we had to exclude those.

The only way possible way to do so was to use internal/poll.IsPollDescriptor (via go:linkname kludge). You can see the code doing this here (initially added by this commit).

We'd like this functionality as a part of public Go API. Perhaps something like this:

package runtime

// IsInternalDescriptor reports whether fd is a
// descriptor being used by Go runtime internally.
func IsInternalDescriptor(fd uintptr) bool

Cc @cyphar

@gopherbot gopherbot added this to the Proposal milestone May 24, 2024
@ianlancetaylor ianlancetaylor added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 24, 2024
@kolyshkin
Copy link
Contributor Author

Adding a bit of context here as the CVE text referenced above is quite long.

There exists a container-specific (chroot-specific) attack vector, for which having CLOEXEC flag for an open (directory) FD is not a remediation. Those FDs had to be explicitly closed before spawning a child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Proposal
Projects
Status: No status
Status: Incoming
Development

No branches or pull requests

3 participants