Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-20190715' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux

Pull pidfd and clone3 fixes from Christian Brauner:
"This contains a bugfix for CLONE_PIDFD when used with the legacy clone
syscall, two fixes to ensure that syscall numbering and clone3
entrypoint implementations will stay consistent, and an update for the
maintainers file:

- The addition of clone3 broke CLONE_PIDFD for legacy clone on all
architectures that use do_fork() directly instead of calling the
clone syscall itself. (Fwiw, cleaning do_fork() up is on my todo.)

The reason this happened was that during conversion of _do_fork()
to use struct kernel_clone_args we missed that do_fork() is called
directly by various architectures. This is fixed by making sure
that the pidfd argument in struct kernel_clone_args is correctly
initialized with the parent_tidptr argument passed down from
do_fork(). Additionally, do_fork() missed a check to make
CLONE_PIDFD and CLONE_PARENT_SETTID mutually exclusive just a
clone() does. This is now fixed too.

- When clone3() was introduced we skipped architectures that require
special handling for fork-like syscalls. Their syscall tables did
not contain any mention of clone3().

To make sure that Arnd's work to make syscall numbers on all
architectures identical (minus alpha) was not for naught we are
placing a comment in all syscall tables that do not yet implement
clone3(). The comment makes it clear that 435 is reserved for
clone3 and should not be used.

- Also, this contains a patch to make the clone3() syscall definition
in asm-generic/unist.h conditional on __ARCH_WANT_SYS_CLONE3. This
lets us catch new architectures that implicitly make use of clone3
without setting __ARCH_WANT_SYS_CLONE3 which is a good indicator
that they did not check whether it needs special treatment or not.

- Finally, this contains a patch to add me as maintainer for pidfd
stuff so people can start blaming me (more)"

* tag 'for-linus-20190715' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux:
MAINTAINERS: add new entry for pidfd api
unistd: protect clone3 via __ARCH_WANT_SYS_CLONE3
arch: mark syscall number 435 reserved for clone3
clone: fix CLONE_PIDFD support

+44 -2
+11
MAINTAINERS
··· 12611 12611 F: arch/arm/mach-picoxcell/ 12612 12612 F: drivers/crypto/picoxcell* 12613 12613 12614 + PIDFD API 12615 + M: Christian Brauner <christian@brauner.io> 12616 + L: linux-kernel@vger.kernel.org 12617 + S: Maintained 12618 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git 12619 + F: samples/pidfd/ 12620 + F: tools/testing/selftests/pidfd/ 12621 + K: (?i)pidfd 12622 + K: (?i)clone3 12623 + K: \b(clone_args|kernel_clone_args)\b 12624 + 12614 12625 PIN CONTROL SUBSYSTEM 12615 12626 M: Linus Walleij <linus.walleij@linaro.org> 12616 12627 L: linux-gpio@vger.kernel.org
+1
arch/alpha/kernel/syscalls/syscall.tbl
··· 474 474 542 common fsmount sys_fsmount 475 475 543 common fspick sys_fspick 476 476 544 common pidfd_open sys_pidfd_open 477 + # 545 reserved for clone3
+1
arch/ia64/kernel/syscalls/syscall.tbl
··· 355 355 432 common fsmount sys_fsmount 356 356 433 common fspick sys_fspick 357 357 434 common pidfd_open sys_pidfd_open 358 + # 435 reserved for clone3
+1
arch/m68k/kernel/syscalls/syscall.tbl
··· 434 434 432 common fsmount sys_fsmount 435 435 433 common fspick sys_fspick 436 436 434 common pidfd_open sys_pidfd_open 437 + # 435 reserved for clone3
+1
arch/mips/kernel/syscalls/syscall_n32.tbl
··· 373 373 432 n32 fsmount sys_fsmount 374 374 433 n32 fspick sys_fspick 375 375 434 n32 pidfd_open sys_pidfd_open 376 + # 435 reserved for clone3
+1
arch/mips/kernel/syscalls/syscall_n64.tbl
··· 349 349 432 n64 fsmount sys_fsmount 350 350 433 n64 fspick sys_fspick 351 351 434 n64 pidfd_open sys_pidfd_open 352 + # 435 reserved for clone3
+1
arch/mips/kernel/syscalls/syscall_o32.tbl
··· 422 422 432 o32 fsmount sys_fsmount 423 423 433 o32 fspick sys_fspick 424 424 434 o32 pidfd_open sys_pidfd_open 425 + # 435 reserved for clone3
+1
arch/parisc/kernel/syscalls/syscall.tbl
··· 431 431 432 common fsmount sys_fsmount 432 432 433 common fspick sys_fspick 433 433 434 common pidfd_open sys_pidfd_open 434 + # 435 reserved for clone3
+1
arch/powerpc/kernel/syscalls/syscall.tbl
··· 516 516 432 common fsmount sys_fsmount 517 517 433 common fspick sys_fspick 518 518 434 common pidfd_open sys_pidfd_open 519 + # 435 reserved for clone3
+1
arch/s390/kernel/syscalls/syscall.tbl
··· 437 437 432 common fsmount sys_fsmount sys_fsmount 438 438 433 common fspick sys_fspick sys_fspick 439 439 434 common pidfd_open sys_pidfd_open sys_pidfd_open 440 + # 435 reserved for clone3
+1
arch/sh/kernel/syscalls/syscall.tbl
··· 437 437 432 common fsmount sys_fsmount 438 438 433 common fspick sys_fspick 439 439 434 common pidfd_open sys_pidfd_open 440 + # 435 reserved for clone3
+1
arch/sparc/kernel/syscalls/syscall.tbl
··· 480 480 432 common fsmount sys_fsmount 481 481 433 common fspick sys_fspick 482 482 434 common pidfd_open sys_pidfd_open 483 + # 435 reserved for clone3
+4
arch/x86/ia32/sys_ia32.c
··· 239 239 { 240 240 struct kernel_clone_args args = { 241 241 .flags = (clone_flags & ~CSIGNAL), 242 + .pidfd = parent_tidptr, 242 243 .child_tid = child_tidptr, 243 244 .parent_tid = parent_tidptr, 244 245 .exit_signal = (clone_flags & CSIGNAL), 245 246 .stack = newsp, 246 247 .tls = tls_val, 247 248 }; 249 + 250 + if (!legacy_clone_args_valid(&args)) 251 + return -EINVAL; 248 252 249 253 return _do_fork(&args); 250 254 }
+1
include/linux/sched/task.h
··· 89 89 extern void exit_itimers(struct signal_struct *); 90 90 91 91 extern long _do_fork(struct kernel_clone_args *kargs); 92 + extern bool legacy_clone_args_valid(const struct kernel_clone_args *kargs); 92 93 extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); 93 94 struct task_struct *fork_idle(int); 94 95 struct mm_struct *copy_init_mm(void);
+2
include/uapi/asm-generic/unistd.h
··· 846 846 __SYSCALL(__NR_fspick, sys_fspick) 847 847 #define __NR_pidfd_open 434 848 848 __SYSCALL(__NR_pidfd_open, sys_pidfd_open) 849 + #ifdef __ARCH_WANT_SYS_CLONE3 849 850 #define __NR_clone3 435 850 851 __SYSCALL(__NR_clone3, sys_clone3) 852 + #endif 851 853 852 854 #undef __NR_syscalls 853 855 #define __NR_syscalls 436
+15 -2
kernel/fork.c
··· 2405 2405 return nr; 2406 2406 } 2407 2407 2408 + bool 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 2418 #ifndef CONFIG_HAVE_COPY_THREAD_TLS 2409 2419 /* For compatibility with architectures that call do_fork directly rather than 2410 2420 * using the syscall entry points below. */ ··· 2426 2416 { 2427 2417 struct kernel_clone_args args = { 2428 2418 .flags = (clone_flags & ~CSIGNAL), 2419 + .pidfd = parent_tidptr, 2429 2420 .child_tid = child_tidptr, 2430 2421 .parent_tid = parent_tidptr, 2431 2422 .exit_signal = (clone_flags & CSIGNAL), 2432 2423 .stack = stack_start, 2433 2424 .stack_size = stack_size, 2434 2425 }; 2426 + 2427 + if (!legacy_clone_args_valid(&args)) 2428 + return -EINVAL; 2435 2429 2436 2430 return _do_fork(&args); 2437 2431 } ··· 2518 2504 .tls = tls, 2519 2505 }; 2520 2506 2521 - /* clone(CLONE_PIDFD) uses parent_tidptr to return a pidfd */ 2522 - if ((clone_flags & CLONE_PIDFD) && (clone_flags & CLONE_PARENT_SETTID)) 2507 + if (!legacy_clone_args_valid(&args)) 2523 2508 return -EINVAL; 2524 2509 2525 2510 return _do_fork(&args);