Unverified Commit 18a405ee by Christian Brauner Committed by GitHub

Merge pull request #2987 from tych0/pass-zero-to-clone

Pass zero to clone
parents 0cfec4f7 3df90604
...@@ -1722,6 +1722,12 @@ dev/null proc/kcore none bind,relative 0 0 ...@@ -1722,6 +1722,12 @@ dev/null proc/kcore none bind,relative 0 0
process wants to inherit the other's network namespace it usually process wants to inherit the other's network namespace it usually
needs to inherit the user namespace as well. needs to inherit the user namespace as well.
</para> </para>
<para>
Note that without careful additional configuration of an LSM,
sharing user+pid namespaces with a task may allow that task to
escalate privileges to that of the task calling liblxc.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
......
...@@ -42,33 +42,22 @@ ...@@ -42,33 +42,22 @@
lxc_log_define(namespace, lxc); lxc_log_define(namespace, lxc);
struct clone_arg { #define __LXC_STACK_SIZE (8 * 1024 * 1024)
int (*fn)(void *);
void *arg;
};
static int do_clone(void *arg)
{
struct clone_arg *clone_arg = arg;
return clone_arg->fn(clone_arg->arg);
}
#define __LXC_STACK_SIZE 4096
pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd) pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd)
{ {
size_t stack_size;
pid_t ret; pid_t ret;
struct clone_arg clone_arg = { void *stack;
.fn = fn,
.arg = arg, stack = malloc(__LXC_STACK_SIZE);
}; if (!stack) {
char *stack[__LXC_STACK_SIZE] = {0}; SYSERROR("Failed to allocate clone stack");
stack_size = __LXC_STACK_SIZE; return -ENOMEM;
}
#ifdef __ia64__ #ifdef __ia64__
ret = __clone2(do_clone, stack, stack_size, flags | SIGCHLD, &clone_arg, pidfd); ret = __clone2(fn, stack, __LXC_STACK_SIZE, flags | SIGCHLD, arg, pidfd);
#else #else
ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg, pidfd); ret = clone(fn, stack + __LXC_STACK_SIZE, flags | SIGCHLD, arg, pidfd);
#endif #endif
if (ret < 0) if (ret < 0)
SYSERROR("Failed to clone (%#x)", flags); SYSERROR("Failed to clone (%#x)", flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment