From: Linus Torvalds Date: Thu, 30 Jan 2020 03:38:34 +0000 (-0800) Subject: Merge tag 'threads-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner... X-Git-Tag: v5.15~4608 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83fa805bcbfc53ae82eedd65132794ae324798e5;p=platform%2Fkernel%2Flinux-starfive.git Merge tag 'threads-v5.6' of git://git./linux/kernel/git/brauner/linux Pull thread management updates from Christian Brauner: "Sargun Dhillon over the last cycle has worked on the pidfd_getfd() syscall. This syscall allows for the retrieval of file descriptors of a process based on its pidfd. A task needs to have ptrace_may_access() permissions with PTRACE_MODE_ATTACH_REALCREDS (suggested by Oleg and Andy) on the target. One of the main use-cases is in combination with seccomp's user notification feature. As a reminder, seccomp's user notification feature was made available in v5.0. It allows a task to retrieve a file descriptor for its seccomp filter. The file descriptor is usually handed of to a more privileged supervising process. The supervisor can then listen for syscall events caught by the seccomp filter of the supervisee and perform actions in lieu of the supervisee, usually emulating syscalls. pidfd_getfd() is needed to expand its uses. There are currently two major users that wait on pidfd_getfd() and one future user: - Netflix, Sargun said, is working on a service mesh where users should be able to connect to a dns-based VIP. When a user connects to e.g. 1.2.3.4:80 that runs e.g. service "foo" they will be redirected to an envoy process. This service mesh uses seccomp user notifications and pidfd to intercept all connect calls and instead of connecting them to 1.2.3.4:80 connects them to e.g. 127.0.0.1:8080. - LXD uses the seccomp notifier heavily to intercept and emulate mknod() and mount() syscalls for unprivileged containers/processes. With pidfd_getfd() more uses-cases e.g. bridging socket connections will be possible. - The patchset has also seen some interest from the browser corner. Right now, Firefox is using a SECCOMP_RET_TRAP sandbox managed by a broker process. In the future glibc will start blocking all signals during dlopen() rendering this type of sandbox impossible. Hence, in the future Firefox will switch to a seccomp-user-nofication based sandbox which also makes use of file descriptor retrieval. The thread for this can be found at https://sourceware.org/ml/libc-alpha/2019-12/msg00079.html With pidfd_getfd() it is e.g. possible to bridge socket connections for the supervisee (binding to a privileged port) and taking actions on file descriptors on behalf of the supervisee in general. Sargun's first version was using an ioctl on pidfds but various people pushed for it to be a proper syscall which he duely implemented as well over various review cycles. Selftests are of course included. I've also added instructions how to deal with merge conflicts below. There's also a small fix coming from the kernel mentee project to correctly annotate struct sighand_struct with __rcu to fix various sparse warnings. We've received a few more such fixes and even though they are mostly trivial I've decided to postpone them until after -rc1 since they came in rather late and I don't want to risk introducing build warnings. Finally, there's a new prctl() command PR_{G,S}ET_IO_FLUSHER which is needed to avoid allocation recursions triggerable by storage drivers that have userspace parts that run in the IO path (e.g. dm-multipath, iscsi, etc). These allocation recursions deadlock the device. The new prctl() allows such privileged userspace components to avoid allocation recursions by setting the PF_MEMALLOC_NOIO and PF_LESS_THROTTLE flags. The patch carries the necessary acks from the relevant maintainers and is routed here as part of prctl() thread-management." * tag 'threads-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: prctl: PR_{G,S}ET_IO_FLUSHER to support controlling memory reclaim sched.h: Annotate sighand_struct with __rcu test: Add test for pidfd getfd arch: wire up pidfd_getfd syscall pid: Implement pidfd_getfd syscall vfs, fdtable: Add fget_task helper --- 83fa805bcbfc53ae82eedd65132794ae324798e5 diff --cc arch/alpha/kernel/syscalls/syscall.tbl index 4d7f2ff,8230108..36d42da --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@@ -475,4 -475,4 +475,5 @@@ 543 common fspick sys_fspick 544 common pidfd_open sys_pidfd_open # 545 reserved for clone3 +547 common openat2 sys_openat2 + 548 common pidfd_getfd sys_pidfd_getfd diff --cc arch/arm/tools/syscall.tbl index 4ba54bc,ba045e2..4d1cf74 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@@ -449,4 -449,4 +449,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open 435 common clone3 sys_clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/arm64/include/asm/unistd32.h index 57f6f59,a8da97a..c1c6163 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@@ -879,8 -879,8 +879,10 @@@ __SYSCALL(__NR_fspick, sys_fspick __SYSCALL(__NR_pidfd_open, sys_pidfd_open) #define __NR_clone3 435 __SYSCALL(__NR_clone3, sys_clone3) +#define __NR_openat2 437 +__SYSCALL(__NR_openat2, sys_openat2) + #define __NR_pidfd_getfd 438 + __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) /* * Please add new compat syscalls above this comment and update diff --cc arch/ia64/kernel/syscalls/syscall.tbl index 8d36f2e,2b11adf..042911e --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@@ -356,4 -356,4 +356,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open # 435 reserved for clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/m68k/kernel/syscalls/syscall.tbl index b911e0f,44e879e..f4f49fc --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@@ -434,5 -434,5 +434,6 @@@ 432 common fsmount sys_fsmount 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open -# 435 reserved for clone3 +435 common clone3 __sys_clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/microblaze/kernel/syscalls/syscall.tbl index c04385e,7afa001..4c67b11 --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@@ -441,4 -441,4 +441,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open 435 common clone3 sys_clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/mips/kernel/syscalls/syscall_n32.tbl index 68c9ec0,856d5ba..1f9e8ad --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@@ -374,4 -374,4 +374,5 @@@ 433 n32 fspick sys_fspick 434 n32 pidfd_open sys_pidfd_open 435 n32 clone3 __sys_clone3 +437 n32 openat2 sys_openat2 + 438 n32 pidfd_getfd sys_pidfd_getfd diff --cc arch/mips/kernel/syscalls/syscall_n64.tbl index 42a72d0,2db6075..c0b9d80 --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@@ -350,4 -350,4 +350,5 @@@ 433 n64 fspick sys_fspick 434 n64 pidfd_open sys_pidfd_open 435 n64 clone3 __sys_clone3 +437 n64 openat2 sys_openat2 + 438 n64 pidfd_getfd sys_pidfd_getfd diff --cc arch/mips/kernel/syscalls/syscall_o32.tbl index f114c4a,e9f9d4a..ac58677 --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@@ -423,4 -423,4 +423,5 @@@ 433 o32 fspick sys_fspick 434 o32 pidfd_open sys_pidfd_open 435 o32 clone3 __sys_clone3 +437 o32 openat2 sys_openat2 + 438 o32 pidfd_getfd sys_pidfd_getfd diff --cc arch/parisc/kernel/syscalls/syscall.tbl index b550ae9,c58c7eb..52a15f5 --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@@ -433,4 -433,4 +433,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open 435 common clone3 sys_clone3_wrapper +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/powerpc/kernel/syscalls/syscall.tbl index a8b5ecb,707609b..35b61bf --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@@ -517,4 -517,4 +517,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open 435 nospu clone3 ppc_clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/s390/kernel/syscalls/syscall.tbl index 16b571c,185cd62..bd7bd35 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@@ -438,4 -438,4 +438,5 @@@ 433 common fspick sys_fspick sys_fspick 434 common pidfd_open sys_pidfd_open sys_pidfd_open 435 common clone3 sys_clone3 sys_clone3 +437 common openat2 sys_openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd diff --cc arch/sh/kernel/syscalls/syscall.tbl index a7185cc,88f9089..c7a30fc --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@@ -438,4 -438,4 +438,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open # 435 reserved for clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/sparc/kernel/syscalls/syscall.tbl index b11c195,218df6a..f13615e --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@@ -481,4 -481,4 +481,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open # 435 reserved for clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc arch/x86/entry/syscalls/syscall_32.tbl index d22a8b5c,9c3101b..c17cb77 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@@ -440,4 -440,4 +440,5 @@@ 433 i386 fspick sys_fspick __ia32_sys_fspick 434 i386 pidfd_open sys_pidfd_open __ia32_sys_pidfd_open 435 i386 clone3 sys_clone3 __ia32_sys_clone3 +437 i386 openat2 sys_openat2 __ia32_sys_openat2 + 438 i386 pidfd_getfd sys_pidfd_getfd __ia32_sys_pidfd_getfd diff --cc arch/x86/entry/syscalls/syscall_64.tbl index 9035647,cef85db..44d510b --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@@ -357,7 -357,7 +357,8 @@@ 433 common fspick __x64_sys_fspick 434 common pidfd_open __x64_sys_pidfd_open 435 common clone3 __x64_sys_clone3/ptregs +437 common openat2 __x64_sys_openat2 + 438 common pidfd_getfd __x64_sys_pidfd_getfd # # x32-specific system call numbers start at 512 to avoid cache impact diff --cc arch/xtensa/kernel/syscalls/syscall.tbl index f0a68013,ae15183..85a9ab1 --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@@ -406,4 -406,4 +406,5 @@@ 433 common fspick sys_fspick 434 common pidfd_open sys_pidfd_open 435 common clone3 sys_clone3 +437 common openat2 sys_openat2 + 438 common pidfd_getfd sys_pidfd_getfd diff --cc include/uapi/asm-generic/unistd.h index d4122c0,d36ec3d..3a3201e --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@@ -850,12 -850,11 +850,14 @@@ __SYSCALL(__NR_pidfd_open, sys_pidfd_op #define __NR_clone3 435 __SYSCALL(__NR_clone3, sys_clone3) #endif + +#define __NR_openat2 437 +__SYSCALL(__NR_openat2, sys_openat2) + #define __NR_pidfd_getfd 438 + __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) #undef __NR_syscalls - #define __NR_syscalls 438 + #define __NR_syscalls 439 /* * 32 bit systems traditionally used different