Skip to content

fix: enable close_range on older Linux sysroots and fix fd fallback - #1024

Merged
Robo (deepak1556) merged 1 commit into
mainfrom
robo/fix_close_range
Dec 2, 2026
Merged

Robo (deepak1556) merged 1 commit into
mainfrom
robo/fix_close_range

Conversation

@deepak1556

Copy link
Copy Markdown
Contributor

Fixes #1023

Use __NR_close_range with ABI fallbacks so glibc 2.28 sysroots (including older 4.19 kernel headers) compile in close_range. Fall back to close_range(..., 0) on EINVAL for Linux 5.9-5.10, and replace the fd loop with a bounded RLIMIT_NOFILE scan when /proc/self/fd is unavailable.

Use __NR_close_range and linux/close_range.h with ABI fallbacks so glibc 2.28
sysroots (including older 4.19 kernel headers) compile in close_range() without
requiring newer glibc symbols. Fall back to close_range(..., 0) on EINVAL for
Linux 5.9-5.10, and replace the fd loop with a bounded RLIMIT_NOFILE scan when
/proc/self/fd is unavailable.
@deepak1556 Robo (deepak1556) added this to the 1.150.0 milestone Dec 2, 2026
@deepak1556 Robo (deepak1556) self-assigned this Dec 2, 2026

@anthonykim1 Anthony Kim (anthonykim1) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot verified on Linux arm64 (kernel 7.0.12) with main and this PR built like CI (glibc 2.28 sysroot).

The sysroot build now calls close_range(3, ~0U, CLOSE_RANGE_CLOEXEC) once in the child instead of walking /proc/self/fd. Spawn to exit for sh -c :, median of 30 spawns:

Extra fds main this PR
0 0.41 ms 0.41 ms
1,000 1.71 ms 0.50 ms
10,000 10.95 ms 0.76 ms
100,000 101.81 ms 2.83 ms

To cover the fallbacks, I forced them with seccomp: EINVAL for CLOSE_RANGE_CLOEXEC (Linux 5.9/5.10) and ENOSYS (before 5.9). Neither leaks a pty master into a new shell, and the 20 tests pass. The x64 and arm64 sysroot builds still pass verify-glibc-requirements.sh.

Authored with Copilot on behalf of anthonykim1

@deepak1556
Robo (deepak1556) merged commit f5d790d into main Dec 2, 2026
18 of 19 checks passed
@deepak1556
Robo (deepak1556) deleted the robo/fix_close_range branch December 2, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use close_range in official Linux builds

3 participants