Skip to content

net: ReadMsgUnix should pass MSG_CMSG_CLOEXEC on Linux #42765

@rittneje

Description

@rittneje

The implementation of ReadMsgUnix ultimately does not pass any flags to the recvmsg syscall. This means that any file descriptors sent in via a Unix rights SCM message will not be marked with the close-on-exec flag. For consistent behavior with how Go handles all other file descriptors on Linux, the MSG_CMSG_CLOEXEC flag should be passed. The need for this is the same as all other uses of the various CLOEXEC flags - to prevent a race condition where a child process is forked (and exec'd) after the file descriptor is created and before it can be marked close-on-exec, and is thus leaked.

Unfortunately, I don't think there's any equivalent of this flag on Mac, so there's no easy way to address the inherent race condition there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions