Nim/tools
alaviss 1bdc30bdb1
Make file descriptors from stdlib non-inheritable by default (#13201)
* io: make file descriptors non-inheritable by default

This prevents file descriptors/handles leakage to child processes
that might cause issues like running out of file descriptors, or potential
security issues like leaking a file descriptor to a restricted file.

While this breaks backward compatibility, I'm rather certain that not
many programs (if any) actually make use of this implementation detail.
A new API `setInheritable` is provided for the few that actually want to
use this functionality.

* io: disable inheritance at file creation time for supported platforms

Some platforms provide extension to fopen-family of functions to allow
for disabling descriptor inheritance atomically during File creation.
This guards against possible leaks when a child process is spawned
before we managed to disable the file descriptor inheritance
(ie. in a multi-threaded program).

* net, nativesockets: make sockets non inheritable by default

With this commit, sockets will no longer leak to child processes when
you don't want it to. Should solves a lot of "address in use" that might
occur when your server has just restarted.

All APIs that create sockets in these modules now expose a `inheritable`
flag that allow users to toggle inheritance for the resulting sockets.
An implementation of `setInheritance()` is also provided for SocketHandle.

While atomically disabling inheritance at creation time is supported on
Windows, it's only implemented by native winsock2, which is too much for
now. This support can be implemented in a future patch.

* posix: add F_DUPFD_CLOEXEC

This command duplicates file descriptor with close-on-exec flag set.

Defined in POSIX.1-2008.

* ioselectors_kqueue: don't leak file descriptors

File descriptors internally used by ioselectors on BSD/OSX are now
shielded from leakage.

* posix: add O_CLOEXEC

This flag allows file descriptors to be open() with close-on-exec flag
set atomically.

This flag is specified in POSIX.1-2008

* tfdleak: test for selectors leakage

Also simplified the test by using handle-type agnostic APIs to test for
validity.

* ioselectors_epoll: mark all fd created close-on-exec

File descriptors from ioselectors should no longer leaks on Linux.

* tfdleak: don't check for selector leakage on Windows

The getFd proc for ioselectors_select returns a hardcoded -1

* io: add NoInheritFlag at compile time

* io: add support for ioctl-based close-on-exec

This allows for the flag to be set/unset in one syscall. While the
performance gains might be negliable, we have one less failure point
to deal with.

* tfdleak: add a test for setInheritable

* stdlib: add nimInheritHandles to restore old behaviors

* memfiles: make file handle not inheritable by default for posix

* io: setInheritable now operates on OS file handle

On Windows, the native handle is the only thing that's inheritable, thus
we can assume that users of this function will already have the handle
available to them. This also allows users to pass down file descriptors
from memfiles on Windows with ease, should that be desired.

With this, nativesockets.setInheritable can be made much simpler.

* changelog: clarify

* nativesockets: document setInheritable return value

* posix_utils: atomically disable fd inheritance for mkstemp
2020-04-20 17:09:59 +02:00
..
detect Make file descriptors from stdlib non-inheritable by default (#13201) 2020-04-20 17:09:59 +02:00
dochack make fuzzy search a bit less fuzzy (#13996) [backport:1.2] 2020-04-16 20:22:32 +02:00
niminst Add arm/arm64 for FreeBSD (#13822) 2020-03-31 22:55:25 +02:00
vccexe Make vccexe parse response files (#13329) 2020-02-11 12:05:47 +01:00
ci_testresults.nim miscellaneous bug fixes (part 3) (#13304) 2020-02-07 16:37:40 +01:00
cmerge.nim minor style changes 2019-07-10 23:55:56 +02:00
deps.nim move tinyc to a separate repo and allow installing external dependencency (eg tinyc) from koch / library code (#13850) 2020-04-03 09:10:45 +02:00
downloader.nim Switch mingw links (#12561) 2019-10-31 11:13:32 +01:00
fakedeps.nim tools: Trim .nim files trailing whitespace 2015-09-04 23:04:17 +02:00
finish.nim fixes #12319 - change exception handling for finish.exe (#12413) 2019-11-15 13:28:55 +01:00
grammar_nanny.nim fixes #10665 (#13141) [backport] 2020-01-14 13:51:28 +01:00
heapdump2dot.nim further progress on --gc:v2 2016-02-17 14:52:02 +01:00
heapdumprepl.nim Fix spellings (#12277) [backport] 2019-09-27 07:02:54 +02:00
kochdocs.nim posix: add full Haiku support (#13931) 2020-04-09 15:56:08 +02:00
nim-gdb.py add $nimeq for gdb (#12909) 2019-12-17 11:30:01 +01:00
nim.bash-completion remove dead code elimination option (#7669) 2018-04-23 11:02:38 +02:00
nim.zsh-completion Fixes #11431 (#11451) [bugfix] 2019-06-10 10:53:34 +02:00
nimblepkglist.nim complete removal of web folder, fixes #9304 (#9310) 2018-10-12 17:27:04 +02:00
nimfind.nim [backport] Fix style issues in lib/, tools/, and testament/. Fixes #12687. (#12754) 2019-11-28 08:32:11 +01:00
nimfind.nims add nimCompile to simplify koch; add nimfind to koch tools (#9723) 2018-11-15 20:32:31 +01:00
nimgrab.nim Fixes #5532 win async write (#5791) 2017-05-14 17:10:39 +02:00
nimgrep.nim Improve #12920 fix (#13958) 2020-04-12 21:08:16 +02:00
nimgrep.nim.cfg renamed babelcmd to nimblecmd; config files are now nim.cfg; other renamings 2014-08-29 09:03:00 +02:00
nimgrind.supp koch: better valgrind support 2017-03-17 08:29:52 +01:00
nimrepl.nim nimrepl compiles again (but doesn't work) 2015-06-29 02:48:32 +02:00
nimweb.nim fix #9647 tmpl=>nimf (#9658) 2018-11-14 08:27:48 +01:00
restorecc.nim tools: Trim .nim files trailing whitespace 2015-09-04 23:04:17 +02:00
start.bat set the codepage to UTF-8 for start.bat; refs #2348 2017-09-02 09:27:39 +02:00
trimcc.nim attempt to re-enable trimcc tool 2017-01-06 13:11:17 +01:00
unicode_parsedata.nim update unicode.nim (#10921) 2019-03-31 08:36:04 +02:00
UnicodeData.txt update unicode.nim (#10921) 2019-03-31 08:36:04 +02:00
urldownloader.nim Switch mingw links (#12561) 2019-10-31 11:13:32 +01:00
website.nimf fix #9647 tmpl=>nimf (#9658) 2018-11-14 08:27:48 +01:00
winrelease.nim moved winrelease to its own tool to fix #6147 2017-09-03 16:26:02 +02:00