compat: update linux/compat.h and kernel/sys_ni.c
RFC PATCH 1/1 compat: update linux/compat.h and kernel/sys_ni.c
Add conditional syscalls entries in kernel/sys_ni.c for any syscalls that are arch- or config-dependent.
Update the prototype entries in <linux/compat.h>.
--- include/linux/compat.h | 27 ++++++--------------------- kernel/sys_ni.c | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 23 deletions(-)
include/linux/compat.h +6 -21
@@ -610,7 +610,7 @@ asmlinkage long compat_sys_fcntl64(unsigasmlinkage long compat_sys_ioctl (unsigned int fd,unsigned int cmd,compat_ulong_t arg); -/* fs/open.c */ +/* fs/statfs.c */ asmlinkage long compat_sys_statfs (const char __user *pathname,struct compat_statfs __user *buf); asmlinkage long compat_sys_statfs64(const char __user *pathname,
@@ -620,6 +620,8 @@ asmlinkage long compat_sys_fstatfs(unsig struct compat_statfs __user *buf);asmlinkage long compat_sys_fstatfs64 (unsigned int fd,compat_size_t sz,struct compat_statfs64 __user *buf); + +/* fs/open.c */ asmlinkage long compat_sys_truncate (const char __user *,compat_off_t );asmlinkage long compat_sys_ftruncate (unsigned int ,compat_ulong_t );/* No generic prototype for truncate64, ftruncate64, fallocate */
@@ -640,17 +642,12 @@ asmlinkage ssize_t compat_sys_preadv(com asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,const struct iovec __user *vec,compat_ulong_t vlen,u32 pos_low,u32 pos_high); -#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64asmlinkage long compat_sys_preadv64 (unsigned long fd,const struct iovec __user *vec,unsigned long vlen,loff_t pos); -#endif - -#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64asmlinkage long compat_sys_pwritev64 (unsigned long fd,const struct iovec __user *vec,unsigned long vlen,loff_t pos); -#endif /* fs/sendfile.c */ asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
@@ -702,7 +699,7 @@ asmlinkage long compat_sys_waitid(int, c -/* kernel/futex.c */ +/* kernel/futex/syscalls.c */ asmlinkage long compat_sys_set_robust_list (struct compat_robust_list_head __user *head,compat_size_t len);
@@ -816,7 +813,7 @@ asmlinkage long compat_sys_sendmsg(int fasmlinkage long compat_sys_recvmsg (int fd,struct compat_msghdr __user *msg,unsigned int flags); -/* mm/filemap.c: No generic prototype for readahead */ +/* mm/readahead.c: No generic prototype for readahead */ /* security/keys/keyctl.c */ asmlinkage long compat_sys_keyctl(u32 option,
@@ -857,18 +854,12 @@ asmlinkage ssize_t compat_sys_preadv2(co asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,const struct iovec __user *vec,compat_ulong_t vlen,u32 pos_low,u32 pos_high,rwf_t flags); -#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2asmlinkage long compat_sys_preadv64v2 (unsigned long fd,const struct iovec __user *vec,unsigned long vlen,loff_t pos,rwf_t flags); -#endif - -#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2asmlinkage long compat_sys_pwritev64v2 (unsigned long fd,const struct iovec __user *vec,unsigned long vlen,loff_t pos,rwf_t flags); -#endif -/* * Deprecated system calls which are still defined in
@@ -910,19 +901,13 @@ asmlinkage long compat_sys_old_select(stasmlinkage long compat_sys_ipc (u32 ,int ,int ,u32 ,compat_uptr_t ,u32 );/* obsolete: kernel/signal.c */ -#ifdef __ARCH_WANT_SYS_SIGPENDINGasmlinkage long compat_sys_sigpending (compat_old_sigset_t __user *set); -#endif - -#ifdef __ARCH_WANT_SYS_SIGPROCMASKasmlinkage long compat_sys_sigprocmask (int how,compat_old_sigset_t __user *nset,compat_old_sigset_t __user *oset); -#endif -#ifdef CONFIG_COMPAT_OLD_SIGACTION +struct compat_old_sigaction ;asmlinkage long compat_sys_sigaction (int sig,const struct compat_old_sigaction __user *act,struct compat_old_sigaction __user *oact); -#endif /* obsolete: net/socket.c */ asmlinkage long compat_sys_socketcall (int call,u32 __user *args);
kernel/sys_ni.c +18 -2
@@ -63,7 +63,7 @@ COND_SYSCALL_COMPAT(lookup_dcookie);/* fs/eventfd.c */ COND_SYSCALL (eventfd2); -/* fs/eventfd.c */ +/* fs/eventpoll.c */ COND_SYSCALL (epoll_create1);COND_SYSCALL (epoll_ctl);COND_SYSCALL (epoll_pwait);
@@ -94,6 +94,9 @@ COND_SYSCALL(flock);/* fs/nfsctl.c */ /* fs/open.c */ +COND_SYSCALL_COMPAT (truncate64); +COND_SYSCALL_COMPAT (ftruncate64); +COND_SYSCALL_COMPAT (fallocate);/* fs/pipe.c */
@@ -104,6 +107,10 @@ COND_SYSCALL(quotactl_fd);/* fs/readdir.c */ /* fs/read_write.c */ +COND_SYSCALL_COMPAT (preadv64); +COND_SYSCALL_COMPAT (pwritev64); +COND_SYSCALL_COMPAT (pread64); +COND_SYSCALL_COMPAT (pwrite64);/* fs/sendfile.c */
@@ -118,6 +125,7 @@ COND_SYSCALL_COMPAT(signalfd4);/* fs/stat.c */ /* fs/sync.c */ +COND_SYSCALL_COMPAT (sync_file_range);/* fs/timerfd.c */ COND_SYSCALL (timerfd_create);
@@ -173,6 +181,11 @@ COND_SYSCALL(syslog);/* kernel/sched/core.c */ +/* kernel/signal.c */ +COND_SYSCALL_COMPAT (sigpending); +COND_SYSCALL_COMPAT (sigprocmask); +COND_SYSCALL_COMPAT (sigaction); +/* kernel/sys.c */ COND_SYSCALL (setregid);COND_SYSCALL (setgid);
@@ -257,7 +270,8 @@ COND_SYSCALL_COMPAT(sendmsg);COND_SYSCALL (recvmsg);COND_SYSCALL_COMPAT (recvmsg); -/* mm/filemap.c */ +/* mm/readahead.c */ +COND_SYSCALL_COMPAT (readahead);/* mm/nommu.c, also with MMU */ COND_SYSCALL (mremap);
@@ -306,6 +320,8 @@ COND_SYSCALL(recvmmsg);COND_SYSCALL (recvmmsg_time32);COND_SYSCALL_COMPAT (recvmmsg_time32);COND_SYSCALL_COMPAT (recvmmsg_time64); +COND_SYSCALL_COMPAT (preadv64v2); +COND_SYSCALL_COMPAT (pwritev64v2);/* * Architecture specific syscalls: see further below
Quoted 2 lines · On Mon, 22 Aug 2022 12:43:10 -0700 Randy Dunlap <[email protected]> wrote:
Add conditional syscalls entries in
kernel/sys_ni.cfor any syscalls that are arch- or config-dependent.
What is the reason for this? What effects does it have?
Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Mon, 22 Aug 2022 12:43:10 -0700 Randy Dunlap <[email protected]> wrote:
Add conditional syscalls entries in
kernel/sys_ni.cfor any syscalls that are arch- or config-dependent.What is the reason for this? What effects does it have?
Hi Andrew,
For <linux/compat.h> it's mostly a cleanup/completeness change, as suggested by Arnd here:
https://lore.kernel.org/lkml/CAK8P3a140FFhCvrOXbCtYKCW6BR6tEz6uy8Wqd0aG3DdHiZSXg@mail.gmail.com/
For kernel/sys_ni.c, it adds compat syscalls that are arch- or config-dependent, to prevent the possibility of linker errors.
I have successfully built allnoconfig, defconfig, and allmodconfig for around 20 architectures with this patch applied.
Signature · 1 line
~Randy
include/linux/compat.h asmlinkage long compat_sys_old_select(st · line 914
Quoted 8 lines · Randy Dunlap
* Deprecated system calls which are still defined in
include/linux/compat.h +1
-2@@ -910,19 +901,13 @@ asmlinkage long compat_sys_old_select(st -#ifdef CONFIG_COMPAT_OLD_SIGACTION +struct compat_old_sigaction ;asmlinkage long compat_sys_sigaction (int sig,const struct compat_old_sigaction __user *act,struct compat_old_sigaction __user *oact); -#endif
All the removed #ifdef look good to me here, and I checked that there are no conflicting prototypes for the ones you change.
For COND_SYSCALL_COMPAT(), I think they should not be part of this patch, and only added for specific optional calls that would cause a link failure.
kernel/sys_ni.c COND_SYSCALL(flock); · line 99
Quoted 7 lines
kernel/sys_ni.c +3
-0@@ -94,6 +94,9 @@ COND_SYSCALL(flock);/* fs/nfsctl.c */ /* fs/open.c */ +COND_SYSCALL_COMPAT (truncate64); +COND_SYSCALL_COMPAT (ftruncate64); +COND_SYSCALL_COMPAT (fallocate);
COND_SYSCALL_COMPAT() doesn't really make sense for non-optional syscalls like these: if an architecture neither sets __ARCH_WANT_COMPAT_FALLOCATE nor provides its own implementation, then a link failure is the appropriate output, hiding it with a COND_SYSCALL_COMPAT() just turns that into a runtime failure that is harder to analyse.
kernel/sys_ni.c COND_SYSCALL(quotactl_fd); · line 113
Quoted 5 lines
kernel/sys_ni.c +4
-0/* fs/read_write.c */ +COND_SYSCALL_COMPAT (preadv64); +COND_SYSCALL_COMPAT (pwritev64); +COND_SYSCALL_COMPAT (pread64); +COND_SYSCALL_COMPAT (pwrite64);
These are specific to x32, and we don't want to ever add them to another architecture, so they should not get a COND_SYSCALL_COMPAT() either.
Quoted 3 lines
kernel/sys_ni.c +1
-0@@ -118,6 +125,7 @@ COND_SYSCALL_COMPAT(signalfd4);/* fs/sync.c */ +COND_SYSCALL_COMPAT (sync_file_range);
....
Quoted 1 line
+COND_SYSCALL_COMPAT(readahead);
Same as above, but these have an additional angle to them, as there are conflicting prototypes and implementations:
arch/sparc/kernel/systbls.h:long compat_sys_sync_file_range(unsigned int fd,arch/sparc/kernel/systbls.h- unsigned off_high,
unsigned off_low,arch/sparc/kernel/systbls.h- unsigned nb_high,
unsigned nb_low,
include/linux/compat.h:asmlinkage long compat_sys_sync_file_range(int fd, compat_arg_u64(pos),include/linux/compat.h-compat_arg_u64(nbytes), unsigned int flags);
The current code works fine, but if you still want to improve this, it would be great to convert the architecture specific helpers to be shared with the common ones. For those that have non-matching prototypes like
include/linux/compat.h:asmlinkage long compat_sys_pwrite64(unsigned int fd, const char __user *buf, size_t count,include/linux/compat.h- compat_arg_u64(pos));
arch/powerpc/include/asm/syscalls.h:compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count,arch/powerpc/include/asm/syscalls.h- u32
reg6, u32 pos1, u32 pos2);
that have an extra argument in them, I would instead suggest renaming the nonstandard ones.
Arnd