Skip to content

os: racy use of pidfd #67641

@prattmic

Description

@prattmic

https://go.dev/cl/570036 started using a pidfd for Process operations in order to avoid races with wait/signal targeting the wrong process. The pidfd is stored in the Process.handle field.

Unfortunately there still exists a race with Release. Release does an atomic swap of the handle with invalidHandle, then closes the handle. However, a Wait or Signal call may have loaded the handle prior to the swap and will proceed to use it after the close completes.

This will most likely result in EBADF from the syscalls, but in the worst case a concurrent FindProcess/etc could open a new pidfd which receives the same FD number we retrieved from handle, and then our syscalls will succeed but target the wrong process.

We could come up with a bespoke little custom lock with atomics to make this safe, but these operations are pretty heavy-weight. I think sync.RWMutex will be more than sufficient. I will work on a fix.

cc @kolyshkin @golang/runtime

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions