-
Notifications
You must be signed in to change notification settings - Fork 7.3k
how to prevent open file descriptors from leaking to child processes? #6905
Comments
I think, it should be |
I cannot think of many cases where you wouldn't want |
Agree. Libuv does this (almost) always by default on all platforms, but uv_fs_open on unix doesn't for some reason. This looks like just an oversight and should be easy to fix (*), patch welcome.
I don't think this is necessary. uv_spawn provides an alternative means to specify explicitly which FDs should be inherited by the child process. (*) The only caveat is that since opening files happens in the thread pool, a race condition may exist so that an fd may still be leaked if |
Yeah, just calling cloexec always is probably fine, then. I'd forgotten about the explicit stdio fd sharing. Better to just use that rather than rely on implicit junk. |
Should be fixed by joyent/libuv#1091 |
Every file descriptor opened using libuv should be automatically marked as CLOEXEC to prevent it from leaking to a child process. Note that since we are opening fds in a thread pool, there is a possible race condition between `uv_spawn()` and the `open()` + `uv__cloexec()`. The rwlock was added to avoid it. see nodejs/node-v0.x-archive#6905
Consider it fixed in joyent/libuv@6abe1e4 |
Hi,
There's no obvious way right now to prevent a child process forked from a node process from having access to a file descriptor (e.g., calling fs.open with O_CLOEXEC).
This is a security risk and very likely a resource leak (not sure if the child process FD handles are counted against open fd limits).
Example code to illustrate what I'm talking about, which leaks access to /tmp/sensitive_file: https://gist.github.com/jandre/8485608
Supporting evidence as to why this is bad: http://www.python.org/dev/peps/pep-0446/#security-vulnerability
Anyway, I may be missing something, but the only workaround I think is to call fs.open with hardcoded O_CLOEXEC, or to write a C++ addon that exposes uv__cloexec-like functionality for a file descriptor.
As far as a real fix, maybe consider the following options:
The text was updated successfully, but these errors were encountered: