Skip to content

x/sys/unix: ParseSocketControlMessage error invalid argument  #56384

@v-byte-cpu

Description

@v-byte-cpu

What version of Go are you using (go version)?

$ go version
go version go1.19.2 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
...
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2418195348=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to pass file descriptor over unix domain socket

for sending process:

// fd int
rights := unix.UnixRights(fd)
unix.Sendmsg(socketFd, nil, rights, nil, 0)

for receiving process:

// receive socket control message
b := make([]byte, unix.CmsgSpace(4))
if _, _, _, _, err = unix.Recvmsg(socketFd, nil, b, 0); err != nil {
	return
}

// parse socket control message
cmsgs, err := unix.ParseSocketControlMessage(b)
if err != nil {
	return 0, fmt.Errorf("parse socket control message: %w", err)
}

fds, err := unix.ParseUnixRights(&cmsgs[0])
...

What did you expect to see?

unix.ParseSocketControlMessage successfully parses the message

What did you see instead?

unix.ParseSocketControlMessage fails with invalid argument error

I performed a research and found out that the problem occurred after this commit golang/sys@87e55d7

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions