History

clone: fix CLONE_PIDFD support

The introduction of clone3 syscall accidentally broke CLONE_PIDFD support in traditional clone syscall on compat x86 and those architectures that use do_fork to implement clone syscall. This bug was found by strace test suite.

Dmitry V. Levin committed 7 years ago

Commit 028b6e81 parent 964a4ea3 files · +20 −2Browse files

Unified · Split

3 files
  1. arch/x86/ia32/sys_ia32.c +4 −0
  2. include/linux/sched/task.h +1 −0
  3. kernel/fork.c +15 −2
arch/x86/ia32/sys_ia32.c+4−0
@@ -239,6 +239,7 @@ COMPAT_SYSCALL_DEFINE5(x86_clone, unsigned long, clone_flags, · 238 unmodified lines
239239 {
240240 struct kernel_clone_args args = {
241241 .flags = (clone_flags & ~CSIGNAL),
242+ .pidfd = parent_tidptr,
242243 .child_tid = child_tidptr,
243244 .parent_tid = parent_tidptr,
244245 .exit_signal = (clone_flags & CSIGNAL),
@@ -246,5 +247,8 @@ COMPAT_SYSCALL_DEFINE5(x86_clone, unsigned long, clone_flags, · 1 unmodified line
246247 .tls = tls_val,
247248 };
248249
250+ if (!legacy_clone_args_valid(&args))
251+ return -EINVAL;
252+
249253 return _do_fork(&args);
250254 }
include/linux/sched/task.h+1−0
@@ -89,6 +89,7 @@ extern void exit_files(struct task_struct *); · 88 unmodified lines
8989 extern void exit_itimers(struct signal_struct *);
9090
9191 extern long _do_fork(struct kernel_clone_args *kargs);
92+extern bool legacy_clone_args_valid(const struct kernel_clone_args *kargs);
9293 extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
9394 struct task_struct *fork_idle(int);
9495 struct mm_struct *copy_init_mm(void);
kernel/fork.c+15−2
@@ -2406,6 +2406,16 @@ long _do_fork(struct kernel_clone_args *args) · 2405 unmodified lines
24062406 return nr;
24072407 }
24082408
2409+bool legacy_clone_args_valid(const struct kernel_clone_args *kargs)
2410+{
2411+ /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */
2412+ if ((kargs->flags & CLONE_PIDFD) &&
2413+ (kargs->flags & CLONE_PARENT_SETTID))
2414+ return false;
2415+
2416+ return true;
2417+}
2418+
24092419 #ifndef CONFIG_HAVE_COPY_THREAD_TLS
24102420 /* For compatibility with architectures that call do_fork directly rather than
24112421 * using the syscall entry points below. */
@@ -2417,6 +2427,7 @@ long do_fork(unsigned long clone_flags, · 5 unmodified lines
24172427 {
24182428 struct kernel_clone_args args = {
24192429 .flags = (clone_flags & ~CSIGNAL),
2430+ .pidfd = parent_tidptr,
24202431 .child_tid = child_tidptr,
24212432 .parent_tid = parent_tidptr,
24222433 .exit_signal = (clone_flags & CSIGNAL),
@@ -2424,6 +2435,9 @@ long do_fork(unsigned long clone_flags, · 1 unmodified line
24242435 .stack_size = stack_size,
24252436 };
24262437
2438+ if (!legacy_clone_args_valid(&args))
2439+ return -EINVAL;
2440+
24272441 return _do_fork(&args);
24282442 }
24292443 #endif
@@ -2505,8 +2519,7 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, · 75 unmodified lines
25052519 .tls = tls,
25062520 };
25072521
2508− /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */
2509− if ((clone_flags & CLONE_PIDFD) && (clone_flags & CLONE_PARENT_SETTID))
2522+ if (!legacy_clone_args_valid(&args))
25102523 return -EINVAL;
25112524
25122525 return _do_fork(&args);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t