Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

A dup of a timerfd, signalfd, inotify or netlink fd has no state behind it

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

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

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

評価

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

調査の方向性

Start with duplicate_guest_fd in src/syscall/fs.c, then read the side-table lookup and cleanup paths for timerfd, signalfd, inotify, and netlink. Compare the alias mapping and reference-counting approach in eventfd_dup_fd and pidfd_dup_ref/pidfd_map. Done means aliases share the original state until the last descriptor closes, and the listed operations work through either fd.

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

説明

bug

dup(2) returns a second fd for the same open file description, so on Linux every operation works through either fd and the object lives until the last one is closed. Under elfuse a dup of a timerfd, signalfd, inotify or netlink fd is an fd of the right type with no state behind it.

duplicate_guest_fd (src/syscall/fs.c) copies these four types through the generic path: a new slot of the same type on a dup of the host fd, with the type's cleanup callback. Each type keeps its state in a side table whose entries record one guest fd number, the one the create call returned, and timerfd_find, signalfd_find, inotify_find and nl_find match on that number. A lookup by the alias's number finds no entry.

Single-threaded, on 9f12c41 and on Linux 6.12 (the qemu reference VM):

int fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
int alias = dup(fd);
struct itimerspec its = {.it_value = {.tv_nsec = 50 * 1000 * 1000}};

                                       /* Linux      elfuse */
timerfd_settime(alias, 0, &its, NULL); /* 0          EBADF  */
timerfd_settime(fd, 0, &its, NULL);    /* 0          0      */
timerfd_gettime(alias, &cur);          /* 0          EBADF  */
poll(&(struct pollfd){alias, POLLIN}, 1, 500);
                                       /* 1, POLLIN  1, POLLIN */
read(alias, &n, 8);                    /* 8          EBADF  */
read(fd, &n, 8);                       /* EAGAIN     8      */
close(fd);
timerfd_settime(alias, 0, &its, NULL); /* 0          EBADF  */

The alias shares the host kqueue, so poll reports it readable, and the read that follows fails. A loop that polls the alias and reads on POLLIN does not block again.

The other three fail the same way through the alias, with the original open or closed, where Linux 6.12 succeeds in both:

  • signalfd: signalfd(alias, &mask, 0) returns EINVAL.
  • inotify: inotify_add_watch(alias, ...) returns EBADF.
  • netlink: getsockname(alias, ...) returns EBADF.

Closing the original frees the entry, and the alias stays as it was. Closing the alias leaves the original working: the cleanup callback matches the entry by fd generation and the alias has none.

eventfd and pidfd are the shape a fix takes. eventfd_dup_fd and pidfd_dup_ref with pidfd_map (#408) map each alias to the source's entry and count the references, and the entry is released with the last one. usbdev is separate: duplicate_guest_fd refuses the dup with EBADF, under a TODO(stage 3) in the same function.

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

環境構築

はじめの一歩

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

sysprog21/elfuse のほかの issue

sysprog21/elfuse の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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