Skip to content

remove in-kernel calls to syscalls

Dominik Brodowski kexec linux-arch linux-fsdevel linux-mm linux-s390 linux-um lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest109 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/109syscalls: define and explain goal to not call syscalls in the kernelDocumentation/process/adding-syscalls.rst include/linux/syscalls.h+39 -00 replies
2/109kernel: use kernel_wait4() instead of sys_wait4()kernel/exit.c kernel/pid_namespace.c kernel/umh.c+6 -61 reply
3/109kernel: open-code sys_rt_sigpending() in sys_sigpending()include/linux/syscalls.h kernel/signal.c+13 -40 replies
4/109kexec: call do_kexec_load() in compat syscall directlykernel/kexec.c+39 -130 replies
5/109mm: use do_futex() instead of sys_futex() in mm_release()include/linux/futex.h kernel/fork.c+12 -50 replies
6/109x86: use _do_fork() in compat_sys_x86_clone()arch/x86/ia32/sys_ia32.c+2 -10 replies
7/109x86: remove compat_sys_x86_waitpid()arch/x86/entry/syscalls/syscall_32.tbl arch/x86/ia32/sys_ia32.c arch/x86/include/asm/sys_ia32.h+1 -100 replies
8/109net: socket: add __sys_recvfrom() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+21 -90 replies
9/109net: socket: add __sys_sendto() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+17 -80 replies
10/109net: socket: add __sys_accept4() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+17 -90 replies
11/109net: socket: add __sys_socket() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+9 -30 replies
12/109net: socket: add __sys_bind() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+9 -30 replies
13/109net: socket: add __sys_connect() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+11 -40 replies
14/109net: socket: add __sys_listen() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+9 -30 replies
15/109net: socket: add __sys_getsockname() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+13 -50 replies
16/109net: socket: add __sys_getpeername() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+13 -50 replies
17/109net: socket: add __sys_socketpair() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+11 -40 replies
18/109net: socket: add __sys_shutdown() helper; remove in-kernel call to syscallinclude/linux/socket.h net/compat.c net/socket.c+9 -30 replies
19/109net: socket: add __sys_setsockopt() helper; remove in-kernel call to syscallinclude/linux/socket.h net/socket.c+11 -30 replies
20/109net: socket: add __sys_getsockopt() helper; remove in-kernel call to syscallnet/socket.c+10 -40 replies
21/109net: socket: add do_sys_recvmmsg() helper; remove in-kernel call to syscallnet/socket.c+12 -50 replies
22/109net: socket: move check for forbid_cmsg_compat to __sys_...msg()include/linux/socket.h net/compat.c net/socket.c+37 -220 replies
23/109net: socket: replace calls to sys_send() with __sys_sendto()net/compat.c net/socket.c+3 -20 replies
24/109net: socket: replace call to sys_recv() with __sys_recvfrom()net/compat.c net/socket.c+4 -20 replies
25/109net: socket: add __compat_sys_recvfrom() helper; remove in-kernel call to compat syscallnet/compat.c+16 -70 replies
26/109net: socket: add __compat_sys_setsockopt() helper; remove in-kernel call to compat syscallnet/compat.c+10 -40 replies
27/109net: socket: add __compat_sys_getsockopt() helper; remove in-kernel call to compat syscallnet/compat.c+12 -40 replies
28/109net: socket: add __compat_sys_recvmmsg() helper; remove in-kernel call to compat syscallnet/compat.c+12 -50 replies
29/109net: socket: add __compat_sys_...msg() helpers; remove in-kernel calls to compat syscallsnet/compat.c+30 -70 replies
30/109ipc: add semtimedop syscall/compat_syscall wrappersipc/sem.c ipc/syscall.c ipc/util.h+41 -120 replies
31/109ipc: add semget syscall wrapperipc/sem.c ipc/syscall.c ipc/util.h+9 -30 replies
32/109ipc: add semctl syscall/compat_syscall wrappersipc/sem.c ipc/syscall.c ipc/util.h+16 -40 replies
33/109ipc: add msgget syscall wrapperipc/msg.c ipc/syscall.c ipc/util.h+9 -30 replies
34/109ipc: add shmget syscall wrapperipc/shm.c ipc/syscall.c ipc/util.h+9 -30 replies
35/109ipc: add shmdt syscall wrapperipc/shm.c ipc/syscall.c ipc/util.h+9 -30 replies
36/109ipc: add shmctl syscall/compat_syscall wrappersipc/shm.c ipc/syscall.c ipc/util.h+16 -40 replies
37/109ipc: add msgctl syscall/compat_syscall wrappersipc/msg.c ipc/syscall.c ipc/util.h+17 -40 replies
38/109ipc: add msgrcv syscall/compat_syscall wrappersipc/msg.c ipc/syscall.c ipc/util.h+24 -70 replies
39/109ipc: add msgsnd syscall/compat_syscall wrappersipc/msg.c ipc/syscall.c ipc/util.h+22 -60 replies
40/109kernel: add do_getpgid() helper; remove internal call to sys_getpgid()kernel/sys.c+7 -20 replies
41/109kernel: add do_compat_sigaltstack() helper; remove in-kernel call to compat syscallkernel/signal.c+10 -40 replies
42/109kernel: provide ksys_*() wrappers for syscalls called by kernel/uid16.ckernel/sys.c kernel/uid16.c kernel/uid16.h+74 -170 replies
43/109sched: add do_sched_yield() helper; remove in-kernel call to sched_yield()kernel/sched/core.c+6 -21 reply
44/109mm: add kernel_migrate_pages() helper, move compat syscall to mm/mempolicy.ckernel/compat.c mm/mempolicy.c+44 -370 replies
45/109mm: add kernel_move_pages() helper, move compat syscall to mm/migrate.ckernel/compat.c mm/migrate.c+35 -260 replies
46/109mm: add kernel_mbind() helper; remove in-kernel call to syscallmm/mempolicy.c+11 -40 replies
47/109mm: add kernel_[sg]et_mempolicy() helpers; remove in-kernel calls to syscallsmm/mempolicy.c+22 -70 replies
48/109fs: add do_readlinkat() helper; remove internal call to sys_readlinkat()fs/stat.c+9 -30 replies
49/109fs: add do_pipe2() helper; remove internal call to sys_pipe2()fs/pipe.c+7 -20 replies
50/109fs: add do_renameat2() helper; remove internal call to sys_renameat2()fs/namei.c+10 -40 replies
51/109fs: add do_futimesat() helper; remove internal call to sys_futimesat()fs/utimes.c+10 -30 replies
52/109fs: add do_epoll_*() helpers; remove internal calls to sys_epoll_*()fs/eventpoll.c+17 -60 replies
53/109fs: add do_signalfd4() helper; remove internal calls to sys_signalfd4()fs/signalfd.c+10 -40 replies
54/109fs: add do_eventfd() helper; remove internal call to sys_eventfd()fs/eventfd.c+7 -20 replies
55/109fs: add do_lookup_dcookie() helper; remove in-kernel call to syscallfs/dcookies.c+8 -30 replies
56/109fs: add do_vmsplice() helper; remove in-kernel call to syscallfs/splice.c+9 -30 replies
57/109fs: add kern_select() helper; remove in-kernel call to sys_select()fs/select.c+9 -30 replies
58/109fs: add do_compat_fcntl64() helper; remove in-kernel call to compat syscallfs/fcntl.c+9 -30 replies
59/109fs: add do_compat_select() helper; remove in-kernel call to compat syscallfs/select.c+12 -50 replies
60/109fs: add do_compat_signalfd4() helper; remove in-kernel call to compat syscallfs/signalfd.c+12 -50 replies
61/109fs: add do_compat_futimesat() helper; remove in-kernel call to compat syscallfs/utimes.c+10 -20 replies
62/109inotify: add do_inotify_init() helper; remove in-kernel call to syscallfs/notify/inotify/inotify_user.c+7 -20 replies
63/109fanotify: add do_fanotify_mark() helper; remove in-kernel call to syscallfs/notify/fanotify/fanotify_user.c+10 -40 replies
64/109fs/quota: add kernel_quotactl() helper; remove in-kernel call to syscallfs/quota/compat.c fs/quota/quota.c include/linux/quotaops.h+15 -60 replies
65/109fs/quota: use COMPAT_SYSCALL_DEFINE for sys32_quotactl()arch/x86/entry/syscalls/syscall_32.tbl fs/quota/compat.c include/linux/compat.h +2 more+8 -60 replies
66/109fs: add ksys_mount() helper; remove in-kernel calls to sys_mount()drivers/base/devtmpfs.c fs/namespace.c include/linux/syscalls.h +2 more+19 -90 replies
67/109fs: add ksys_umount() helper; remove in-kernel call to sys_umount()fs/namespace.c include/linux/syscalls.h init/do_mounts_initrd.c+9 -30 replies
68/109fs: add ksys_dup{,3}() helper; remove in-kernel calls to sys_dup{,3}()fs/file.c include/linux/syscalls.h init/do_mounts_initrd.c +1 more+18 -70 replies
69/109fs: add ksys_chroot() helper; remove-in kernel calls to sys_chroot()drivers/base/devtmpfs.c fs/open.c include/linux/syscalls.h +2 more+11 -50 replies
70/109fs: add ksys_write() helper; remove in-kernel calls to sys_write()arch/s390/kernel/compat_linux.c fs/read_write.c include/linux/syscalls.h +2 more+12 -60 replies
71/109fs: add ksys_chdir() helper; remove in-kernel calls to sys_chdir()drivers/base/devtmpfs.c fs/open.c include/linux/syscalls.h +2 more+13 -70 replies
72/109fs: add ksys_unlink() wrapper; remove in-kernel calls to sys_unlink()include/linux/syscalls.h init/do_mounts.h init/do_mounts_initrd.c +2 more+17 -60 replies
73/109hostfs: rename do_rmdir() to hostfs_do_rmdir()fs/hostfs/hostfs.h fs/hostfs/hostfs_kern.c fs/hostfs/hostfs_user.c+3 -30 replies
74/109fs: add ksys_rmdir() wrapper; remove in-kernel calls to sys_rmdir()fs/internal.h fs/namei.c include/linux/syscalls.h +1 more+11 -30 replies
75/109fs: add do_mkdirat() helper and ksys_mkdir() wrapper; remove in-kernel calls to syscallfs/internal.h fs/namei.c include/linux/syscalls.h +3 more+19 -60 replies
76/109fs: add do_symlinkat() helper and ksys_symlink() wrapper; remove in-kernel calls to syscallfs/internal.h fs/namei.c include/linux/syscalls.h +1 more+21 -40 replies
77/109fs: add do_mknodat() helper and ksys_mknod() wrapper; remove in-kernel calls to syscallfs/internal.h fs/namei.c include/linux/syscalls.h +3 more+23 -60 replies
78/109fs: add do_linkat() helper and ksys_link() wrapper; remove in-kernel calls to syscallfs/internal.h fs/namei.c include/linux/syscalls.h +1 more+21 -40 replies
79/109fs: add ksys_fchmod() and do_fchmodat() helpers and ksys_chmod() wrapper; remove in-kernel calls to syscallfs/internal.h fs/open.c include/linux/syscalls.h +1 more+27 -60 replies
80/109fs: add do_faccessat() helper and ksys_access() wrapper; remove in-kernel calls to syscallfs/internal.h fs/open.c include/linux/syscalls.h +1 more+17 -30 replies
81/109fs: add do_fchownat(), ksys_fchown() helpers and ksys_{,l}chown() wrappersarch/s390/kernel/compat_linux.c fs/internal.h fs/open.c +3 more+46 -160 replies
82/109fs: add ksys_ftruncate() wrapper; remove in-kernel calls to sys_ftruncate()arch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +7 more+17 -90 replies
83/109fs: add ksys_close() wrapper; remove in-kernel calls to sys_close()fs/autofs4/dev-ioctl.c fs/binfmt_misc.c fs/file.c +7 more+29 -170 replies
84/109fs: add ksys_open() wrapper; remove in-kernel calls to sys_open()fs/open.c include/linux/syscalls.h init/do_mounts.c +5 more+26 -150 replies
85/109fs: add ksys_getdents64() helper; remove in-kernel calls to sys_getdents64()fs/readdir.c include/linux/syscalls.h init/initramfs.c+13 -40 replies
86/109fs: add ksys_ioctl() helper; remove in-kernel calls to sys_ioctl()fs/ioctl.c include/linux/syscalls.h init/do_mounts.c +3 more+22 -150 replies
87/109fs: add ksys_lseek() helper; remove in-kernel calls to sys_lseek()fs/read_write.c include/linux/syscalls.h init/do_mounts_rd.c+12 -60 replies
88/109fs: add ksys_read() helper; remove in-kernel calls to sys_read()arch/s390/kernel/compat_linux.c fs/read_write.c include/linux/syscalls.h +2 more+14 -80 replies
89/109fs: add ksys_sync() helper; remove in-kernel calls to sys_sync()arch/sparc/kernel/setup_32.c drivers/tty/sysrq.c fs/sync.c +4 more+12 -60 replies
90/109kernel: add ksys_unshare() helper; remove in-kernel calls to sys_unshare()drivers/base/devtmpfs.c include/linux/syscalls.h init/do_mounts_initrd.c +1 more+9 -30 replies
91/109kernel: add ksys_setsid() helper; remove in-kernel call to sys_setsid()include/linux/syscalls.h init/do_mounts_initrd.c kernel/sys.c+8 -20 replies
92/109fs: add ksys_sync_file_range helper(); remove in-kernel calls to syscallarch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +5 more+19 -110 replies
93/109fs: add ksys_truncate() wrapper; remove in-kernel calls to sys_truncate()arch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +5 more+17 -90 replies
94/109fs: add ksys_p{read,write}64() helpers; remove in-kernel calls to syscallsarch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +6 more+36 -200 replies
95/109fs: add ksys_fallocate() wrapper; remove in-kernel calls to sys_fallocate()arch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +5 more+18 -120 replies
96/109mm: add ksys_fadvise64_64() helper; remove in-kernel call to sys_fadvise64_64()arch/arm/kernel/sys_arm.c arch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c +9 more+43 -270 replies
97/109mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff()arch/alpha/kernel/osf_sys.c arch/arm64/kernel/sys.c arch/ia64/kernel/sys_ia64.c +18 more+60 -410 replies
98/109mm: add ksys_readahead() helper; remove in-kernel calls to sys_readahead()arch/mips/kernel/linux32.c arch/parisc/kernel/sys_parisc.c arch/powerpc/kernel/sys_ppc32.c +5 more+13 -70 replies
99/109x86/ioport: add ksys_ioperm() helper; remove in-kernel calls to sys_ioperm()arch/x86/include/asm/syscalls.h arch/x86/kernel/ioport.c drivers/tty/vt/vt_ioctl.c+10 -40 replies
100/109x86: fix sys_sigreturn() return type to be long, not unsigned longarch/x86/include/asm/syscalls.h arch/x86/kernel/signal.c+2 -20 replies
101/109x86/sigreturn: use SYSCALL_DEFINE0arch/x86/kernel/signal.c+3 -20 replies
102/109kexec: move sys_kexec_load() prototype to syscalls.hinclude/linux/kexec.h include/linux/syscalls.h+4 -40 replies
103/109syscalls: sort syscall prototypes in include/linux/syscalls.hinclude/linux/syscalls.h+678 -5480 replies
104/109net: remove compat_sys_*() prototypes from net/compat.hinclude/net/compat.h+0 -110 replies
105/109syscalls: sort syscall prototypes in include/linux/compat.hinclude/linux/compat.h+378 -2770 replies
106/109syscalls/x86: auto-create compat_sys_*() prototypesarch/x86/ia32/ia32_signal.c arch/x86/ia32/sys_ia32.c arch/x86/include/asm/sys_ia32.h +1 more+4 -800 replies
107/109kernel/sys_ni: sort cond_syscall() entrieskernel/sys_ni.c+332 -1740 replies
108/109kernel/sys_ni: remove {sys_,sys_compat} from cond_syscall definitionsDocumentation/process/adding-syscalls.rst kernel/sys_ni.c+219 -2160 replies
109/109bpf: whitelist all syscalls for error injectioninclude/linux/compat.h include/linux/syscalls.h+6 -00 replies

Reviews trailers per patch

13 of 109 patches have a Reviewed-by or Acked-by.

PatchThomas GleixnerJan KaraRichard WeinbergerGreg Kroah-HartmanPeter Zijlstra (Intel)Luis R. Rodriguez
1/109
2/109A-b
3/109
4/109
5/109R-b
6/109R-b
7/109R-b
8/109
9/109
10/109
11/109
12/109
13/109
14/109
15/109
16/109
17/109
18/109
19/109
20/109
21/109
22/109
23/109
24/109
25/109
26/109
27/109
28/109
29/109
30/109
31/109
32/109
33/109
34/109
35/109
36/109
37/109
38/109
39/109
40/109
41/109
42/109
43/109A-b
44/109
45/109
46/109
47/109
48/109
49/109
50/109
51/109
52/109
53/109
54/109
55/109
56/109
57/109
58/109
59/109
60/109
61/109
62/109A-b
63/109A-b
64/109A-b
65/109A-b
66/109
67/109
68/109
69/109
70/109
71/109
72/109
73/109A-b
74/109
75/109
76/109
77/109
78/109
79/109
80/109
81/109
82/109
83/109
84/109
85/109
86/109
87/109
88/109
89/109
90/109
91/109
92/109
93/109
94/109
95/109
96/109
97/109
98/109
99/109R-b A-b
100/109R-b
101/109R-b
102/109
103/109
104/109
105/109
106/109
107/109
108/109
109/109

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 6 reviewers.

Read the v1 thread

Cover letter [PATCH 000/109] remove in-kernel calls to syscalls

[ While most parts of this patch set have been sent out already at least
once, I send out *all* patches to lkml once again as this whole series touches several different subsystems in sensitive areas. ]

System calls are interaction points between userspace and the kernel. Therefore, system call functions such as sys_xyzzy() or compat_sys_xyzzy() should only be called from userspace via the syscall table, but not from elsewhere in the kernel.

At least on 64-bit x86, it will likely be a hard requirement from v4.17 onwards to not call system call functions in the kernel: It is better to use use a different calling convention for system calls there, where struct pt_regs is decoded on-the-fly in a syscall wrapper which then hands processing over to the actual syscall function. This means that only those parameters which are actually needed for a specific syscall are passed on during syscall entry, instead of filling in six CPU registers with random user space content all the time (which may cause serious trouble down the call chain).[*]

Moreover, rules on how data may be accessed may differ between kernel data and user data. This is another reason why calling sys_xyzzy() is generally a bad idea, and -- at most -- acceptable in arch-specific code.

This patchset removes all in-kernel calls to syscall functions in the
kernel with the exception of arch/. On top of this, it cleans up the
three places where many syscalls are referenced or prototyped, namely
kernel/sys_ni.c, include/linux/syscalls.h and include/linux/compat.h.
Patches 1 to 101 have been sent out earlier, namely
- part 1 ( http://lkml.kernel.org/r/20180315190529.20943-1-linux-X3ehHDuj6sIIGcDfoQAp7OTW4wlIGRCZ@public.gmane.org )
- part 2 ( http://lkml.kernel.org/r/20180316170614.5392-1-linux-X3ehHDuj6sIIGcDfoQAp7OTW4wlIGRCZ@public.gmane.org )
- part 3 ( http://lkml.kernel.org/r/20180322090059.19361-1-linux-X3ehHDuj6sIIGcDfoQAp7OTW4wlIGRCZ@public.gmane.org ).

Changes since these earlier versions are:

- I have added a lot more documentation and improved the commit messages, namely to explain the naming convention and the rationale of this patches.

- ACKs/Reviewed-by (thanks!) were added .

- Shuffle the patches around to have them grouped together systematically:

First goes a patch which defines the goal and explains the rationale:

syscalls: define and explain goal to not call syscalls in the kernel

A few codepaths can trivially be converted to existing in-kernel interfaces:

kernel: use kernel_wait4() instead of sys_wait4()
kernel: open-code sys_rt_sigpending() in sys_sigpending()
kexec: call do_kexec_load() in compat syscall directly
mm: use do_futex() instead of sys_futex() in mm_release()
x86: use _do_fork() in compat_sys_x86_clone()
x86: remove compat_sys_x86_waitpid()

Then follow many patches which only affect specfic subsystems each, and replace sys_*() with internal helpers named __sys_*() or do_sys_*(). Let's start with net/:

net: socket: add __sys_recvfrom() helper; remove in-kernel call to syscall
net: socket: add __sys_sendto() helper; remove in-kernel call to syscall
net: socket: add __sys_accept4() helper; remove in-kernel call to syscall
net: socket: add __sys_socket() helper; remove in-kernel call to syscall
net: socket: add __sys_bind() helper; remove in-kernel call to syscall
net: socket: add __sys_connect() helper; remove in-kernel call to syscall
net: socket: add __sys_listen() helper; remove in-kernel call to syscall
net: socket: add __sys_getsockname() helper; remove in-kernel call to syscall
net: socket: add __sys_getpeername() helper; remove in-kernel call to syscall
net: socket: add __sys_socketpair() helper; remove in-kernel call to syscall
net: socket: add __sys_shutdown() helper; remove in-kernel call to syscall
net: socket: add __sys_setsockopt() helper; remove in-kernel call to syscall
net: socket: add __sys_getsockopt() helper; remove in-kernel call to syscall
net: socket: add do_sys_recvmmsg() helper; remove in-kernel call to syscall
net: socket: move check for forbid_cmsg_compat to __sys_...msg()
net: socket: replace calls to sys_send() with __sys_sendto()
net: socket: replace call to sys_recv() with __sys_recvfrom()
net: socket: add __compat_sys_recvfrom() helper; remove in-kernel call to compat syscall
net: socket: add __compat_sys_setsockopt() helper; remove in-kernel call to compat syscall
net: socket: add __compat_sys_getsockopt() helper; remove in-kernel call to compat syscall
net: socket: add __compat_sys_recvmmsg() helper; remove in-kernel call to compat syscall
net: socket: add __compat_sys_...msg() helpers; remove in-kernel calls to compat syscalls

The changes in ipc/ are limited to this specific subsystem. The wrappers are named ksys_*() to denote that these functions are meant as a drop-in replacement for the syscalls.

ipc: add semtimedop syscall/compat_syscall wrappers
ipc: add semget syscall wrapper
ipc: add semctl syscall/compat_syscall wrappers
ipc: add msgget syscall wrapper
ipc: add shmget syscall wrapper
ipc: add shmdt syscall wrapper
ipc: add shmctl syscall/compat_syscall wrappers
ipc: add msgctl syscall/compat_syscall wrappers
ipc: add msgrcv syscall/compat_syscall wrappers
ipc: add msgsnd syscall/compat_syscall wrappers

A few mindless conversions in kernel/ and mm/:

kernel: add do_getpgid() helper; remove internal call to sys_getpgid()
kernel: add do_compat_sigaltstack() helper; remove in-kernel call to compat syscall
kernel: provide ksys_*() wrappers for syscalls called by kernel/uid16.c
sched: add do_sched_yield() helper; remove in-kernel call to sched_yield()
mm: add kernel_migrate_pages() helper, move compat syscall to mm/mempolicy.c
mm: add kernel_move_pages() helper, move compat syscall to mm/migrate.c
mm: add kernel_mbind() helper; remove in-kernel call to syscall
mm: add kernel_[sg]et_mempolicy() helpers; remove in-kernel calls to syscalls

Then, let's handle those instances internal to fs/ which call syscalls:

fs: add do_readlinkat() helper; remove internal call to sys_readlinkat()
fs: add do_pipe2() helper; remove internal call to sys_pipe2()
fs: add do_renameat2() helper; remove internal call to sys_renameat2()
fs: add do_futimesat() helper; remove internal call to sys_futimesat()
fs: add do_epoll_*() helpers; remove internal calls to sys_epoll_*()
fs: add do_signalfd4() helper; remove internal calls to sys_signalfd4()
fs: add do_eventfd() helper; remove internal call to sys_eventfd()
fs: add do_lookup_dcookie() helper; remove in-kernel call to syscall
fs: add do_vmsplice() helper; remove in-kernel call to syscall
fs: add kern_select() helper; remove in-kernel call to sys_select()
fs: add do_compat_fcntl64() helper; remove in-kernel call to compat syscall
fs: add do_compat_select() helper; remove in-kernel call to compat syscall
fs: add do_compat_signalfd4() helper; remove in-kernel call to compat syscall
fs: add do_compat_futimesat() helper; remove in-kernel call to compat syscall
inotify: add do_inotify_init() helper; remove in-kernel call to syscall
fanotify: add do_fanotify_mark() helper; remove in-kernel call to syscall fs/quota: add kernel_quotactl() helper; remove in-kernel call to syscall fs/quota: use COMPAT_SYSCALL_DEFINE for sys32_quotactl()

Several fs- and some mm-related syscalls are called in initramfs, initrd and init, devtmpfs, and pm code. While at least many of these instances should be converted to use proper in-kernel VFS interfaces in future, convert them mindlessly to ksys_*() helpers or wrappers for now.

fs: add ksys_mount() helper; remove in-kernel calls to sys_mount()
fs: add ksys_umount() helper; remove in-kernel call to sys_umount()
fs: add ksys_dup{,3}() helper; remove in-kernel calls to sys_dup{,3}()
fs: add ksys_chroot() helper; remove-in kernel calls to sys_chroot()
fs: add ksys_write() helper; remove in-kernel calls to sys_write()
fs: add ksys_chdir() helper; remove in-kernel calls to sys_chdir()
fs: add ksys_unlink() wrapper; remove in-kernel calls to sys_unlink()
hostfs: rename do_rmdir() to hostfs_do_rmdir()
fs: add ksys_rmdir() wrapper; remove in-kernel calls to sys_rmdir()
fs: add do_mkdirat() helper and ksys_mkdir() wrapper; remove in-kernel calls to syscall
fs: add do_symlinkat() helper and ksys_symlink() wrapper; remove in-kernel calls to syscall
fs: add do_mknodat() helper and ksys_mknod() wrapper; remove in-kernel calls to syscall
fs: add do_linkat() helper and ksys_link() wrapper; remove in-kernel calls to syscall
fs: add ksys_fchmod() and do_fchmodat() helpers and ksys_chmod() wrapper; remove in-kernel calls to syscall
fs: add do_faccessat() helper and ksys_access() wrapper; remove in-kernel calls to syscall
fs: add do_fchownat(), ksys_fchown() helpers and ksys_{,l}chown() wrappers
fs: add ksys_ftruncate() wrapper; remove in-kernel calls to sys_ftruncate()
fs: add ksys_close() wrapper; remove in-kernel calls to sys_close()
fs: add ksys_open() wrapper; remove in-kernel calls to sys_open()
fs: add ksys_getdents64() helper; remove in-kernel calls to sys_getdents64()
fs: add ksys_ioctl() helper; remove in-kernel calls to sys_ioctl()
fs: add ksys_lseek() helper; remove in-kernel calls to sys_lseek()
fs: add ksys_read() helper; remove in-kernel calls to sys_read()
fs: add ksys_sync() helper; remove in-kernel calls to sys_sync()
kernel: add ksys_unshare() helper; remove in-kernel calls to sys_unshare()
kernel: add ksys_setsid() helper; remove in-kernel call to sys_setsid()

To reach the goal to get rid of all in-kernel calls to syscalls for x86, we need to handle a few further syscalls called from compat syscalls in x86 and (mostly) from other architectures. Those could be made generic making use of Al Viro's macro trickery. For v4.17, I'd suggest to keep it simple:

fs: add ksys_sync_file_range helper(); remove in-kernel calls to syscall
fs: add ksys_truncate() wrapper; remove in-kernel calls to sys_truncate()
fs: add ksys_p{read,write}64() helpers; remove in-kernel calls to syscalls
fs: add ksys_fallocate() wrapper; remove in-kernel calls to sys_fallocate()
mm: add ksys_fadvise64_64() helper; remove in-kernel call to sys_fadvise64_64()
mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff()
mm: add ksys_readahead() helper; remove in-kernel calls to sys_readahead() x86/ioport: add ksys_ioperm() helper; remove in-kernel calls to sys_ioperm()

Then, throw in two fixes for x86:

x86: fix sys_sigreturn() return type to be long, not unsigned long x86/sigreturn: use SYSCALL_DEFINE0 (by Michael Tautschnig)

... and clean up the three places where many syscalls are referenced or prototyped (kernel/sys_ni.c, include/linux/syscalls.h and include/linux/compat.h):

kexec: move sys_kexec_load() prototype to syscalls.h
syscalls: sort syscall prototypes in include/linux/syscalls.h
net: remove compat_sys_*() prototypes from net/compat.h
syscalls: sort syscall prototypes in include/linux/compat.h syscalls/x86: auto-create compat_sys_*() prototypes kernel/sys_ni: sort cond_syscall() entries
kernel/sys_ni: remove {sys_,sys_compat} from cond_syscall definitions

Last but not least, add a patch by Howard McLauchlan to whitelist all syscalls for error injection:

bpf: whitelist all syscalls for error injection (by Howard McLauchlan)

Tze whole series is available at

https://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux.git syscalls-next

and I intend to push this upstream early in the v4.17-rc1 cycle.

Thanks,
Dominik

 Documentation/process/adding-syscalls.rst |   34 +-
 arch/alpha/kernel/osf_sys.c               |    2 +-
 arch/arm/kernel/sys_arm.c                 |    2 +-
 arch/arm64/kernel/sys.c                   |    2 +-
 arch/ia64/kernel/sys_ia64.c               |    4 +-
 arch/m68k/kernel/sys_m68k.c               |    2 +-
 arch/microblaze/kernel/sys_microblaze.c   |    6 +-
 arch/mips/kernel/linux32.c                |   22 +-
 arch/mips/kernel/syscall.c                |    6 +-
 arch/parisc/kernel/sys_parisc.c           |   30 +-
 arch/powerpc/kernel/sys_ppc32.c           |   18 +-
 arch/powerpc/kernel/syscalls.c            |    6 +-
 arch/riscv/kernel/sys_riscv.c             |    4 +-
 arch/s390/kernel/compat_linux.c           |   37 +-
 arch/s390/kernel/sys_s390.c               |    2 +-
 arch/sh/kernel/sys_sh.c                   |    4 +-
 arch/sh/kernel/sys_sh32.c                 |   12 +-
 arch/sparc/kernel/setup_32.c              |    2 +-
 arch/sparc/kernel/sys_sparc32.c           |   26 +-
 arch/sparc/kernel/sys_sparc_32.c          |    6 +-
 arch/sparc/kernel/sys_sparc_64.c          |    2 +-
 arch/um/kernel/syscall.c                  |    2 +-
 arch/x86/entry/syscalls/syscall_32.tbl    |    4 +-
 arch/x86/ia32/ia32_signal.c               |    1 -
 arch/x86/ia32/sys_ia32.c                  |   50 +-
 arch/x86/include/asm/sys_ia32.h           |   67 --
 arch/x86/include/asm/syscalls.h           |    3 +-
 arch/x86/kernel/ioport.c                  |    7 +-
 arch/x86/kernel/signal.c                  |    5 +-
 arch/x86/kernel/sys_x86_64.c              |    2 +-
 arch/xtensa/kernel/syscall.c              |    2 +-
 drivers/base/devtmpfs.c                   |   11 +-
 drivers/tty/sysrq.c                       |    2 +-
 drivers/tty/vt/vt_ioctl.c                 |    6 +-
 fs/autofs4/dev-ioctl.c                    |    2 +-
 fs/binfmt_misc.c                          |    2 +-
 fs/dcookies.c                             |   11 +-
 fs/eventfd.c                              |    9 +-
 fs/eventpoll.c                            |   23 +-
 fs/fcntl.c                                |   12 +-
 fs/file.c                                 |   17 +-
 fs/hostfs/hostfs.h                        |    2 +-
 fs/hostfs/hostfs_kern.c                   |    2 +-
 fs/hostfs/hostfs_user.c                   |    2 +-
 fs/internal.h                             |   14 +
 fs/ioctl.c                                |    7 +-
 fs/namei.c                                |   61 +-
 fs/namespace.c                            |   19 +-
 fs/notify/fanotify/fanotify_user.c        |   14 +-
 fs/notify/inotify/inotify_user.c          |    9 +-
 fs/open.c                                 |   77 +-
 fs/pipe.c                                 |    9 +-
 fs/quota/compat.c                         |   13 +-
 fs/quota/quota.c                          |   10 +-
 fs/read_write.c                           |   45 +-
 fs/readdir.c                              |   11 +-
 fs/select.c                               |   29 +-
 fs/signalfd.c                             |   31 +-
 fs/splice.c                               |   12 +-
 fs/stat.c                                 |   12 +-
 fs/sync.c                                 |   19 +-
 fs/utimes.c                               |   25 +-
 include/linux/compat.h                    |  644 ++++++------
 include/linux/futex.h                     |   13 +-
 include/linux/kexec.h                     |    4 -
 include/linux/quotaops.h                  |    3 +
 include/linux/socket.h                    |   37 +-
 include/linux/syscalls.h                  | 1511 +++++++++++++++++------------
 include/net/compat.h                      |   11 -
 init/do_mounts.c                          |   26 +-
 init/do_mounts.h                          |    4 +-
 init/do_mounts_initrd.c                   |   42 +-
 init/do_mounts_md.c                       |   29 +-
 init/do_mounts_rd.c                       |   40 +-
 init/initramfs.c                          |   52 +-
 init/main.c                               |    9 +-
 init/noinitramfs.c                        |    6 +-
 ipc/msg.c                                 |   60 +-
 ipc/sem.c                                 |   44 +-
 ipc/shm.c                                 |   28 +-
 ipc/syscall.c                             |   58 +-
 ipc/util.h                                |   31 +
 kernel/compat.c                           |   55 --
 kernel/exit.c                             |    2 +-
 kernel/fork.c                             |   11 +-
 kernel/kexec.c                            |   52 +-
 kernel/pid_namespace.c                    |    6 +-
 kernel/power/hibernate.c                  |    2 +-
 kernel/power/suspend.c                    |    2 +-
 kernel/power/user.c                       |    2 +-
 kernel/sched/core.c                       |    8 +-
 kernel/signal.c                           |   29 +-
 kernel/sys.c                              |   74 +-
 kernel/sys_ni.c                           |  617 +++++++-----
 kernel/uid16.c                            |   25 +-
 kernel/uid16.h                            |   14 +
 kernel/umh.c                              |    4 +-
 mm/fadvise.c                              |   10 +-
 mm/mempolicy.c                            |   92 +-
 mm/migrate.c                              |   39 +-
 mm/mmap.c                                 |   17 +-
 mm/nommu.c                                |   17 +-
 mm/readahead.c                            |    7 +-
 net/compat.c                              |  136 ++-
 net/socket.c                              |  234 +++--
 105 files changed, 3129 insertions(+), 1868 deletions(-)
 delete mode 100644 arch/x86/include/asm/sys_ia32.h
 create mode 100644 kernel/uid16.h

[*] An early, not-yet-ready version and partly untested (i386, x32) of the patches required to implement this on top of this series is available at
https://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux.git syscalls-WIP

Signature · 1 line
2.16.3