VFS: prevent FD inheritance for the kernel completely.
* Each io_context now has a "inherit_fds" member that decides whether or not this context allows to inherit FDs to its children. * This replaces the former O_CLOEXEC mechanism.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011, Axel Dörfler, [email protected].
|
||||
* Copyright 2002-2015, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||
@@ -58,6 +58,7 @@ typedef struct io_context {
|
||||
struct list node_monitors;
|
||||
uint32 num_monitors;
|
||||
uint32 max_monitors;
|
||||
bool inherit_fds;
|
||||
} io_context;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2005-2013, Ingo Weinhold, [email protected].
|
||||
* Copyright 2002-2014, Axel Dörfler, [email protected].
|
||||
* Copyright 2002-2015, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||
@@ -4820,7 +4820,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
MutexLocker parentLocker;
|
||||
|
||||
size_t tableSize;
|
||||
if (parentContext) {
|
||||
if (parentContext != NULL) {
|
||||
parentLocker.SetTo(parentContext->io_mutex, false);
|
||||
tableSize = parentContext->table_size;
|
||||
} else
|
||||
@@ -4847,7 +4847,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
|
||||
// Copy all parent file descriptors
|
||||
|
||||
if (parentContext) {
|
||||
if (parentContext != NULL) {
|
||||
size_t i;
|
||||
|
||||
mutex_lock(&sIOContextRootLock);
|
||||
@@ -4860,6 +4860,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
if (context->cwd)
|
||||
inc_vnode_ref_count(context->cwd);
|
||||
|
||||
if (parentContext->inherit_fds) {
|
||||
for (i = 0; i < tableSize; i++) {
|
||||
struct file_descriptor* descriptor = parentContext->fds[i];
|
||||
|
||||
@@ -4879,6 +4880,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
fd_set_close_on_exec(context, i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parentLocker.Unlock();
|
||||
} else {
|
||||
@@ -4893,6 +4895,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
}
|
||||
|
||||
context->table_size = tableSize;
|
||||
context->inherit_fds = parentContext != NULL;
|
||||
|
||||
list_init(&context->node_monitors);
|
||||
context->max_monitors = DEFAULT_NODE_MONITORS;
|
||||
@@ -8143,7 +8146,7 @@ _kern_open(int fd, const char* path, int openMode, int perms)
|
||||
if (openMode & O_CREAT)
|
||||
return file_create(fd, pathBuffer.LockBuffer(), openMode, perms, true);
|
||||
|
||||
return file_open(fd, pathBuffer.LockBuffer(), openMode | O_CLOEXEC, true);
|
||||
return file_open(fd, pathBuffer.LockBuffer(), openMode, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user