`getppid` names an exited adopter instead of the current one after two quick reparents

Open
#539 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c

Research direction

Start with proc_notify_reparent, lifecycle_reparent_complete, and the child drain in src/syscall/proc.c; compare that flow with proc_lifecycle_sync_self. The issue describes a race where a delayed reparent record can overwrite the child's cached parent after a newer reparent. Reproduce the quick-reparent scenario and verify that getppid reports the current adopter after the drain processes the notification.

Written by the indexing model from the issue text.

Description

bug

What happens

When a process exits, proc_process_exit in src/syscall/proc.c reparents its live children in the lifecycle registry and then calls proc_notify_reparent for each one. That function appends an R <ns> <pid> <ppid> record to the child's signal transport and resends it, up to 20 times over 50 ms, until lifecycle_reparent_complete(pid, ppid) sees the registry ack. The child's drain applies the newest R record it reads (proc_set_ppid), then calls lifecycle_ack_reparent, which acks only when the registry's ppid still equals the record's.

Three processes A, B and C, with C a child of A:

  1. A exits and reparents C to B in the registry, then loops in proc_notify_reparent(C, B).
  2. Before C acks B, B exits and reparents C to D. C drains R ... D and acks D.
  3. A's loop still sees lifecycle_reparent_complete(C, B) as false, because the registry now says D, so A appends R ... B again.
  4. C's next drain applies proc_set_ppid(B). lifecycle_ack_reparent(C, B) is a no-op because the registry says D, and nothing corrects C's cached ppid.

getppid in C then returns B, which has exited. On Linux it returns D.

Evidence

Found by reading proc_notify_reparent, lifecycle_reparent_complete and the drain in src/syscall/proc.c at abd83d1 (#538); not run. Raised in review: https://github.com/sysprog21/elfuse/pull/538#discussion_r4608448061

Cause

The drain trusts the ppid that the R record carries. A record can still arrive after a newer reparent has been acked, and the record carries no generation number. Checked by reading, not by a run.

Reproduce

Not reproduced. A probe would need a parent and its replacement adopter to exit within the 50 ms retry window of proc_notify_reparent, with the grandchild polling getppid.

Possible fix

Treat an R record as a doorbell only. The drain reads the ppid from the process's own registry entry, as proc_lifecycle_sync_self does, and acks that value. #538 already runs the drain's registry work after releasing the transport flock, so the drain can take the registry lock there.

Origin

Follow-up from #538 (https://github.com/sysprog21/elfuse/pull/538#discussion_r4608448061). The race predates #538.

Dominant language
C
Stars
287
Forks
33
Avg merge
2d 17h
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sysprog21/elfuse

All issues in sysprog21/elfuse

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.