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

オープン
#539 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
287
フォーク
33
平均マージ
2日 17時間
マージ済み PR(30日)
18

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sysprog21/elfuse のほかの issue

sysprog21/elfuse の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。