History

fs, close_range: add flag CLOSE_RANGE_CLOEXEC

When the flag CLOSE_RANGE_CLOEXEC is set, close_range doesn't immediately close the files but it sets the close-on-exec bit. It is useful for e.g. container runtimes that usually install a seccomp profile "as late as possible" before execv'ing the container process itself. The container runtime could either do: 1 2 - install_seccomp_profile(); - close_range(MIN_FD, MAX_INT, 0); - close_range(MIN_FD, MAX_INT, 0); - install_seccomp_profile(); - execve(...); - execve(...); Both alternative have some disadvantages. In the first variant the seccomp_profile cannot block the close_range syscall, as well as opendir/read/close/... for the fallback on older kernels. In the second variant, close_range() can be used only on the fds that are not going to be needed by the runtime anymore, and it must be potentially called multiple times to account for the different ranges that must be closed. Using close_range(..., ..., CLOSE_RANGE_CLOEXEC) solves these issues. The runtime is able to use the existing open fds, the seccomp profile can block close_range() and the syscalls used for its fallback.

Giuseppe Scrivano committed 5 years ago

Commit 582f1fb1 parent 4e62d552 files · +37 −10Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/close_range.h+3−0
@@ -5,5 +5,8 @@ · 4 unmodified lines
5/* Unshare the file descriptor table before closing file descriptors. */5/* Unshare the file descriptor table before closing file descriptors. */
6#define CLOSE_RANGE_UNSHARE (1U << 1)6#define CLOSE_RANGE_UNSHARE (1U << 1)
7 7
8/* Set the FD_CLOEXEC bit instead of closing the file descriptor. */
9#define CLOSE_RANGE_CLOEXEC (1U << 2)
10
8#endif /* _UAPI_LINUX_CLOSE_RANGE_H */11#endif /* _UAPI_LINUX_CLOSE_RANGE_H */
9 12

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t