-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
clone3: validate stack arguments
Validate the stack arguments and setup the stack depening on whether or not
it is growing down or up.
Legacy clone() required userspace to know in which direction the stack is
growing and pass down the stack pointer appropriately. To make things more
confusing microblaze uses a variant of the clone() syscall selected by
CONFIG_CLONE_BACKWARDS3 that takes an additional stack_size argument.
IA64 has a separate clone2() syscall which also takes an additional
stack_size argument. Finally, parisc has a stack that is growing upwards.
Userspace therefore has a lot nasty code like the following:
#define __STACK_SIZE (8 * 1024 * 1024)
pid_t sys_clone(int (*fn)(void *), void *arg, int flags, int *pidfd)
stack = malloc(__STACK_SIZE);
ret = __clone2(fn, stack, __STACK_SIZE, flags | SIGCHLD, arg, pidfd);
#elif defined(__parisc__) /* stack grows up */
ret = clone(fn, stack, flags | SIGCHLD, arg, pidfd);
ret = clone(fn, stack + __STACK_SIZE, flags | SIGCHLD, arg, pidfd);
or even crazier variants such as .
With clone3() we have the ability to validate the stack. We can check that
when stack_size is passed, the stack pointer is valid and the other way
around. We can also check that the memory area userspace gave us is fine to
use via access_ok(). Furthermore, we probably should not require
userspace to know in which direction the stack is growing. It is easy
for us to do this in the kernel and I couldn't find the original
reasoning behind exposing this detail to userspace.
/* Intentional user visible API change */
clone3() was released with 5.3. Currently, it is not documented and very
unclear to userspace how the stack and stack_size argument have to be
passed. After talking to glibc folks we concluded that trying to change
clone3() to setup the stack instead of requiring userspace to do this is
the right course of action.
Note, that this is an explicit change in user visible behavior we introduce
with this patch. If it breaks someone's use-case we will revert! (And then
e.g. place the new behavior under an appropriate flag.)
Breaking someone's use-case is very unlikely though. First, neither glibc
nor musl currently expose a wrapper for clone3(). Second, there is no real
motivation for anyone to use clone3() directly since it does not provide
features that legacy clone doesn't. New features for clone3() will first
happen in v5.5 which is why v5.4 is still a good time to try and make that
change now and backport it to v5.3. Searches on  did not reveal any
packages calling clone3().
Fixes: 7f192e3cd316 ("fork: add clone3")
Cc: Kees Cook <firstname.lastname@example.org>
Cc: Jann Horn <email@example.com>
Cc: David Howells <firstname.lastname@example.org>
Cc: Ingo Molnar <email@example.com>
Cc: Oleg Nesterov <firstname.lastname@example.org>
Cc: Linus Torvalds <email@example.com>
Cc: Florian Weimer <firstname.lastname@example.org>
Cc: Peter Zijlstra <email@example.com>
Cc: <firstname.lastname@example.org> # 5.3
Cc: GNU C Library <email@example.com>
Signed-off-by: Christian Brauner <firstname.lastname@example.org>
Acked-by: Arnd Bergmann <email@example.com>
Acked-by: Aleksa Sarai <firstname.lastname@example.org>
2 files changed