aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index dfa78985a6fd..d8ae0f1b4148 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2405,6 +2405,16 @@ long _do_fork(struct kernel_clone_args *args)
2405 return nr; 2405 return nr;
2406} 2406}
2407 2407
2408bool legacy_clone_args_valid(const struct kernel_clone_args *kargs)
2409{
2410 /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */
2411 if ((kargs->flags & CLONE_PIDFD) &&
2412 (kargs->flags & CLONE_PARENT_SETTID))
2413 return false;
2414
2415 return true;
2416}
2417
2408#ifndef CONFIG_HAVE_COPY_THREAD_TLS 2418#ifndef CONFIG_HAVE_COPY_THREAD_TLS
2409/* For compatibility with architectures that call do_fork directly rather than 2419/* For compatibility with architectures that call do_fork directly rather than
2410 * using the syscall entry points below. */ 2420 * using the syscall entry points below. */
@@ -2416,6 +2426,7 @@ long do_fork(unsigned long clone_flags,
2416{ 2426{
2417 struct kernel_clone_args args = { 2427 struct kernel_clone_args args = {
2418 .flags = (clone_flags & ~CSIGNAL), 2428 .flags = (clone_flags & ~CSIGNAL),
2429 .pidfd = parent_tidptr,
2419 .child_tid = child_tidptr, 2430 .child_tid = child_tidptr,
2420 .parent_tid = parent_tidptr, 2431 .parent_tid = parent_tidptr,
2421 .exit_signal = (clone_flags & CSIGNAL), 2432 .exit_signal = (clone_flags & CSIGNAL),
@@ -2423,6 +2434,9 @@ long do_fork(unsigned long clone_flags,
2423 .stack_size = stack_size, 2434 .stack_size = stack_size,
2424 }; 2435 };
2425 2436
2437 if (!legacy_clone_args_valid(&args))
2438 return -EINVAL;
2439
2426 return _do_fork(&args); 2440 return _do_fork(&args);
2427} 2441}
2428#endif 2442#endif
@@ -2504,8 +2518,7 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
2504 .tls = tls, 2518 .tls = tls,
2505 }; 2519 };
2506 2520
2507 /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */ 2521 if (!legacy_clone_args_valid(&args))
2508 if ((clone_flags & CLONE_PIDFD) && (clone_flags & CLONE_PARENT_SETTID))
2509 return -EINVAL; 2522 return -EINVAL;
2510 2523
2511 return _do_fork(&args); 2524 return _do_fork(&args);