fork() succeeds with a descriptor missing when its pin cannot be allocated
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
調査の方向性
まず src/runtime/fork-state.c の fork_ipc_send_fd_table() から始め、fd_lifetime_pin_locked() の NULL 返りをどのように処理するかを確認してください。次に src/syscall/fdtable.c の fd_lifetime_pin_spare() を確認し、割り当て失敗のケースを理解してください。修正により、ピンの割り当てができない場合に fork() が ENOMEM 付きで -1 を返すようにする必要があり、説明されているフォールトインジェクションの再現手順で検証できます。
索引モデルが issue の本文から書いたものです。
説明
fork_ipc_send_fd_table() (src/runtime/fork-state.c) skips a slot when fd_lifetime_pin_locked() returns NULL:
pin = fd_lifetime_pin_locked(i);
if (!pin)
continue;
fd_lifetime_pin_spare() returns NULL for a closed slot, for a slot with no host descriptor, and when malloc fails. The loop has already skipped FD_CLOSED under the same fd_lock hold, so on an open slot with a host descriptor NULL means the allocation failed. The slot is then left out of the table sent to the child, the send completes, and the parent's fork() returns the child pid. Nothing is logged.
Linux fork() either gives the child every descriptor or fails with ENOMEM.
Reproduction
The allocation cannot be made to fail from the guest, so this uses fault injection on b57f367. In fd_lifetime_pin_spare() (src/syscall/fdtable.c):
- lifetime = malloc(sizeof(*lifetime));
+ lifetime = (fd == 5 && getenv("PINFAIL"))
+ ? NULL
+ : malloc(sizeof(*lifetime));
Guest:
for (int i = 0; i < 5; i++)
open("/dev/null", O_RDONLY); /* fds 3..7 */
pid_t pid = fork();
printf("[%s] fork returned %d\n", pid ? "parent" : "child", (int) pid);
if (pid == 0) {
for (int fd = 3; fd <= 7; fd++)
printf("child fd %d: %s\n", fd,
fcntl(fd, F_GETFD) >= 0 ? "open" : strerror(errno));
_exit(0);
}
waitpid(pid, NULL, 0);
With PINFAIL=1:
[parent] fork returned 2
[child] fork returned 0
child fd 3: open
child fd 4: open
child fd 5: Bad file descriptor
child fd 6: open
child fd 7: open
Without the variable, fd 5 is open in the child.
Expected
fork() returns -1 with ENOMEM and no child is left running.
The skip is older than the pin. At 628181b, where this loop still calls dup(), a guest holding 1021 descriptors under ulimit -n 1280 gets a successful fork() and a child with descriptors missing.
- 主要言語
- C
- スター
- 271
- フォーク
- 28
- 平均マージ
- 2日 18時間
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sysprog21/elfuse のほかの issue
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
sysprog21/elfuse の issue をすべて見る
似ている issue
-
area:http-gateway good first issue priority:low type:docs
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
crazy-goat/php-fpm-ng#828 ·
メンテナーはふだん 1 日以内に返信
-
area:docs good first issue type:docs
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
CVE-2026-18839 popt: size_t underflow in `singleOptionHelp`対応中かも @pmatilai が 34 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
rpm-software-management/popt#143 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100