Skip to content

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

Closed
@kolyshkin

Description

@kolyshkin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Proposalcompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Done

    Status

    Declined

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions