[process][v2] close_range() ENOSYS at runtime silently leaves descriptors open (binary built against newer kernel headers, run on an older kernel)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 58/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cpp, linux
- Bereich
- operating-systems
Rechercherichtung
Start in src/posix/close_handles.cpp, in the Linux close_all, where the three ::close_range(..., CLOSE_RANGE_UNSHARE) calls ignore their return value and the #else branch holds the /dev/fd iteration fallback. Check how the compile-time LINUX_VERSION_CODE guard chooses between the two paths. Done means a failed close_range (ENOSYS) falls through to the /proc/self/fd or /dev/fd iteration at runtime, with a cached flag so the syscall is not retried on every spawn.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
On POSIX, default_launcher relies on detail::close_all() (src/posix/close_handles.cpp) to close the descriptors a child should not inherit. On Linux that is done with close_range(2). The code path is selected at compile time from LINUX_VERSION_CODE (i.e. the kernel headers present in the build environment) and the presence of SYS_close_range. The return value of close_range() is not checked, and there is no runtime fallback.
When a binary is built against kernel headers >= 5.9 but runs on an older kernel (close_range was added in Linux 5.9), the syscall returns ENOSYS at runtime, the failure is ignored, and no descriptors are closed. Every non-FD_CLOEXEC descriptor open in the parent then leaks into the spawned process and into anything it detaches.
This is easy to hit with portable static binaries (e.g. musl static builds) that are compiled in a modern CI container and deployed to older hosts. In our case the binary is built against modern headers and deployed to Ubuntu 18.04 (kernel 4.15).
Symptom
A command that spawns a detached worker (setsid cmd </dev/null >>log 2>&1 & disown) keeps a process_stdio pipe end open inside that worker, because the write end that should have been closed in the child was never closed. Reading the command's stdout therefore never reaches EOF and the read hangs until the whole detached subtree exits, long after the command itself returned.
Affected code
src/posix/close_handles.cpp, the Linux close_all:
- The three
::close_range(..., CLOSE_RANGE_UNSHARE);calls are bare statements; theerror_code ¶meter is unnamed and unused. - The
/dev/fditeration fallback lives in the#elsebranch, selected at compile time when theclose_rangepath is not compiled in. It is never reached whenclose_rangeis compiled in but fails at runtime. - The compile-time guard keys off
LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)(build headers) rather than a runtime capability.
Confirmed present in 1.90 and still on develop. Both glibc and musl are affected (under musl the non-glibc branch supplies a raw ::syscall(SYS_close_range, ...) wrapper, with the same outcome).
Suggested fix
Make the fallback a runtime decision: check the result of close_range(), and on ENOSYS (or any failure) fall back to the /proc/self/fd (or /dev/fd) iteration that already exists in the #else branch, rather than choosing between them only at compile time. A process-wide "close_range unavailable" flag can avoid retrying the syscall on every spawn.
Related
- #549 (same ENOSYS-at-runtime pattern, for
pidfd_open) - #400 (
close_rangeavailability on FreeBSD) - #517 (
/dev/fdnot present on every Linux system, relevant to the fallback)
Environment
Boost 1.90; Linux; static binary built against kernel headers >= 5.9 and run on kernel 4.15.
- Vorherrschende Sprache
- C++
- Sterne
- 147
- Forks
- 153
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus boostorg/process
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
Alle Issues in boostorg/process
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
open-astro/AlpacaBridge#2606 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Refactor force_torque_system integration test to use EcmScopeEvtl. vergeben @patelshivani2283-lab hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Niko1221/Strata#6731 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 6 Tagen
-
good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100