linux/tools/testing/selftests/core
Christian Brauner 0a0f88fcb4
selftests/core: test CLOSE_RANGE_CLOEXEC_ONLY
Cover closing what is marked:

- close-on-exec descriptors in the range go, the ones outside stay, and
  a range above the table closes nothing

- with CLOSE_RANGE_EXCEPT it is the other way around, and the kept ones
  keep their flag, for a window in the middle, at the top and at the
  bottom

- descriptors without close-on-exec are never touched, in or out of the
  range

- a range that cannot hold an open descriptor keeps nothing, one that
  covers everything keeps everything, in place and in a clone

- the unshare form leaves the table it was cloned from alone, with and
  without CLOSE_RANGE_EXCEPT

- the unshare form keeps the descriptors without the flag that sit in
  the range it drops from, and hands the dropped slots out again

- a kept range above the last descriptor without close-on-exec still
  comes back, so the clone is sized off the range too

Also check that asking for CLOSE_RANGE_CLOEXEC at the same time is
refused, whatever else is asked for, and that the bounds are still
checked.

The extra cases came out of the same walk with the close-on-exec mask
on top: a marked and an unmarked descriptor on each side of every window
position, and the size of the clone when only unmarked ones are left in
the range it drops from.

Link: https://patch.msgid.link/20260921-work-file-close_range_except-v1-10-c20d0b49270d@kernel.org
Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-05 13:02:41 +02:00
..
.gitignore selftests: core: add unshare_test to gitignore 2024-09-30 11:42:11 -06:00
close_range_test.c selftests/core: test CLOSE_RANGE_CLOEXEC_ONLY 2026-10-05 13:02:41 +02:00
Makefile selftests:core: test coverage for dup_fd() failure handling in unshare_fd() 2024-08-22 00:45:55 -06:00
unshare_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00