Skip to content

pidfd monitor can watch an unrelated process after host pid reuse #401

Description

@xalestar

pidfd_monitor_thread checks the target with kill(hpid, 0) and then registers EVFILT_PROC on hpid, the host pid recorded when the pidfd was created. If the target exits and macOS reuses that host pid before the monitor registers, the monitor ends up watching an unrelated process. The pidfd then reports the exit of that process, or waits on it, and not on the guest's target.

The window is between pidfd_create recording the host pid and the kevent() registration succeeding, so it needs fast pid reuse and is unlikely in practice. It is not specific to the pidfd table: anything in elfuse that holds a host pid across a gap has the same exposure, so the fix may belong with however the rest of the process layer tracks host pids.

Found while reviewing #399.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions