diff options
| author | Christian Brauner <brauner@kernel.org> | 2026-09-22 13:40:12 +0200 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-10-05 13:02:41 +0200 |
| commit | c73c0e243836d5dfd1c617f73b6003b1ad40b2d1 (patch) | |
| tree | 0dbbe2d22ab8dc1d281dd3de402863870816750f /tools/lib/python | |
| parent | fd73f4a6659897191fa0d40695fe370925dd3780 (diff) | |
| parent | 0a0f88fcb434f58fc5b444e7c9eeae791cdbbeda (diff) | |
| download | linux-next-c73c0e243836d5dfd1c617f73b6003b1ad40b2d1.tar.gz linux-next-c73c0e243836d5dfd1c617f73b6003b1ad40b2d1.zip | |
Merge patch series "files,close_range: add CLOSE_RANGE_{CLOEXEC_ONLY,EXCEPT}"
Christian Brauner <brauner@kernel.org> says:
close_range(CLOSE_RANGE_CLOEXEC) marks a range of file descriptors
close-on-exec. It only marks them. The file descriptors are only ever
closed during an exec. This series adds two new flags to extend the
abilities of close_range():
(1) CLOSE_RANGE_EXCEPT
While regular close_range() operates on all file descriptors in the
range [fd, max_fd] and not on any others, CLOSE_RANGE_EXCEPT makes
close_range() operate on all file descriptors outside of the range.
When combined with CLOSE_RANGE_UNSHARE dup_fd() never takes a
reference on what is dropped.
A task between clone(CLONE_FILES | CLONE_VM | CLONE_VFORK) and
execve() that has the descriptors for the child in one window can
shed the rest of the shared table in one call:
close_range(lo, hi, CLOSE_RANGE_UNSHARE | CLOSE_RANGE_EXCEPT)
Nothing outside of the window is referenced by the child at any point.
(2) CLOSE_RANGE_CLOEXEC_ONLY closes the close-on-exec file descriptors
in the range
Whatever the caller deliberately passes down, stdio, LISTEN_FDS, an
inherited pipe, remains where it is.
The handful of close-on-exec descriptors the caller still needs for the
exec such as the executable, an error pipe, can sit in a specific
range. A task between clone(CLONE_FILES) and execve() may do:
clone(CLONE_FILES | CLONE_VM | CLONE_VFORK)
child: close_range(lo, hi, CLOSE_RANGE_UNSHARE |
CLOSE_RANGE_CLOEXEC_ONLY |
CLOSE_RANGE_EXCEPT)
child: rearrange descriptors in the now private table
child: execve()
Between the clone and the close_range() the child holds no reference of
its own on any file because copy_files() only bumps the fdtable
refcount. So a close() in the parent takes effect immediately. The
unshare also never takes a reference on the fds it leaves behind either.
* patches from https://patch.msgid.link/20260921-work-file-close_range_except-v1-0-c20d0b49270d@kernel.org:
selftests/core: test CLOSE_RANGE_CLOEXEC_ONLY
file: add CLOSE_RANGE_CLOEXEC_ONLY
file: let dup_fd() drop only close-on-exec descriptors
selftests/core: test CLOSE_RANGE_EXCEPT
file: add CLOSE_RANGE_EXCEPT
close_range: turn the flags into an enum
file: let dup_fd() drop everything outside of the range
file: rename dup_fd()'s punch_hole to range
selftests/core: test the hole CLOSE_RANGE_UNSHARE leaves behind
file: let dup_fd() leave the punched hole behind
Link: https://patch.msgid.link/20260921-work-file-close_range_except-v1-0-c20d0b49270d@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
