aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/dcrt0.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2019-01-29 20:37:00 +0100
committerCorinna Vinschen <corinna@vinschen.de>2019-01-29 20:37:00 +0100
commit4d738e0f62403c3f1b082abf927aab00056230c5 (patch)
tree03720baec7164389183cce562ed268cd421edb28 /winsup/cygwin/dcrt0.cc
parent5a0f2c00aa019de73a6077ca3017b594c43184a4 (diff)
downloadnewlib-4d738e0f62403c3f1b082abf927aab00056230c5.zip
newlib-4d738e0f62403c3f1b082abf927aab00056230c5.tar.gz
newlib-4d738e0f62403c3f1b082abf927aab00056230c5.tar.bz2
Cygwin: execve: reduce parent handle to non-inheritable SYNCHRONIZE
Keeping an inheritable handle open results in that handle being spilled over into grandchild processes, which is not desired. Duplicate original parent handle into a non-inheritable one with minimal SYNCHRONIZE permissions and close the original handle. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/dcrt0.cc')
-rw-r--r--winsup/cygwin/dcrt0.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 6b564dc..463df31 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -685,14 +685,30 @@ child_info_spawn::handle_spawn ()
ready (true);
- /* Keep pointer to parent open if we've execed so that pid will not be reused.
- Otherwise, we no longer need this handle so close it.
- Need to do this after debug_fixup_after_fork_exec or DEBUGGING handling of
- handles might get confused. */
- if (type != _CH_EXEC && child_proc_info->parent)
+ if (child_proc_info->parent)
{
- CloseHandle (child_proc_info->parent);
- child_proc_info->parent = NULL;
+ if (type == _CH_EXEC)
+ {
+ /* Keep pointer to parent open if we've execed so that pid will not be
+ reused. Try to Urther reduce permissions. */
+ HANDLE new_parent;
+
+ if (DuplicateHandle (GetCurrentProcess (), child_proc_info->parent,
+ GetCurrentProcess (), &new_parent,
+ SYNCHRONIZE, FALSE, 0))
+ {
+ CloseHandle (child_proc_info->parent);
+ child_proc_info->parent = new_parent;
+ }
+ }
+ else
+ {
+ /* Otherwise, we no longer need this handle so close it. Need to do
+ this after debug_fixup_after_fork_exec or DEBUGGING handling of
+ handles might get confused. */
+ CloseHandle (child_proc_info->parent);
+ child_proc_info->parent = NULL;
+ }
}
signal_fixup_after_exec ();