A dup of a timerfd, signalfd, inotify or netlink fd has no state behind it
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, linux
- Domain
- operating-systems
Research direction
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.
Written by the indexing model from the issue text.
Description
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)returnsEINVAL. - inotify:
inotify_add_watch(alias, ...)returnsEBADF. - netlink:
getsockname(alias, ...)returnsEBADF.
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.
- Dominant language
- C
- Stars
- 271
- Forks
- 28
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sysprog21/elfuse
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 2 days
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
Maintainers usually reply within 2 days
All issues in sysprog21/elfuse
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kovidgoyal/kitty#10625 ·
Maintainers usually reply within 1 day
-
Feature Status: Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
本機相簿無法上傳webm檔案Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
xiaojieonly/Ehviewer_CN_SXJ#2893 ·