* [PATCH 01/15] ftruncate: pass a signed offset [not found] <20240620162316.3674955-1-arnd@kernel.org> @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-21 7:47 ` Christian Brauner 2024-06-20 16:23 ` [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage Arnd Bergmann ` (4 subsequent siblings) 5 siblings, 1 reply; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> The old ftruncate() syscall, using the 32-bit off_t misses a sign extension when called in compat mode on 64-bit architectures. As a result, passing a negative length accidentally succeeds in truncating to file size between 2GiB and 4GiB. Changing the type of the compat syscall to the signed compat_off_t changes the behavior so it instead returns -EINVAL. The native entry point, the truncate() syscall and the corresponding loff_t based variants are all correct already and do not suffer from this mistake. Fixes: 3f6d078d4acc ("fix compat truncate/ftruncate") Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- fs/open.c | 4 ++-- include/linux/compat.h | 2 +- include/linux/syscalls.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/open.c b/fs/open.c index 89cafb572061..50e45bc7c4d8 100644 --- a/fs/open.c +++ b/fs/open.c @@ -202,13 +202,13 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small) return error; } -SYSCALL_DEFINE2(ftruncate, unsigned int, fd, unsigned long, length) +SYSCALL_DEFINE2(ftruncate, unsigned int, fd, off_t, length) { return do_sys_ftruncate(fd, length, 1); } #ifdef CONFIG_COMPAT -COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_ulong_t, length) +COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_off_t, length) { return do_sys_ftruncate(fd, length, 1); } diff --git a/include/linux/compat.h b/include/linux/compat.h index 233f61ec8afc..56cebaff0c91 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -608,7 +608,7 @@ asmlinkage long compat_sys_fstatfs(unsigned int fd, asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf); asmlinkage long compat_sys_truncate(const char __user *, compat_off_t); -asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t); +asmlinkage long compat_sys_ftruncate(unsigned int, compat_off_t); /* No generic prototype for truncate64, ftruncate64, fallocate */ asmlinkage long compat_sys_openat(int dfd, const char __user *filename, int flags, umode_t mode); diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 9104952d323d..ba9337709878 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -418,7 +418,7 @@ asmlinkage long sys_listmount(const struct mnt_id_req __user *req, u64 __user *mnt_ids, size_t nr_mnt_ids, unsigned int flags); asmlinkage long sys_truncate(const char __user *path, long length); -asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length); +asmlinkage long sys_ftruncate(unsigned int fd, off_t length); #if BITS_PER_LONG == 32 asmlinkage long sys_truncate64(const char __user *path, loff_t length); asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length); -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 01/15] ftruncate: pass a signed offset 2024-06-20 16:23 ` [PATCH 01/15] ftruncate: pass a signed offset Arnd Bergmann @ 2024-06-21 7:47 ` Christian Brauner 0 siblings, 0 replies; 16+ messages in thread From: Christian Brauner @ 2024-06-21 7:47 UTC (permalink / raw) To: Arnd Bergmann Cc: linux-arch, linux-kernel, Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, linux-fsdevel, libc-alpha, musl, ltp, stable On Thu, Jun 20, 2024 at 06:23:02PM GMT, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The old ftruncate() syscall, using the 32-bit off_t misses a sign > extension when called in compat mode on 64-bit architectures. As a > result, passing a negative length accidentally succeeds in truncating > to file size between 2GiB and 4GiB. > > Changing the type of the compat syscall to the signed compat_off_t > changes the behavior so it instead returns -EINVAL. > > The native entry point, the truncate() syscall and the corresponding > loff_t based variants are all correct already and do not suffer > from this mistake. > > Fixes: 3f6d078d4acc ("fix compat truncate/ftruncate") > Cc: stable@vger.kernel.org > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- Looks good to me, Reviewed-by: Christian Brauner <brauner@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage [not found] <20240620162316.3674955-1-arnd@kernel.org> 2024-06-20 16:23 ` [PATCH 01/15] ftruncate: pass a signed offset Arnd Bergmann @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-21 14:19 ` Heiko Carstens 2024-06-24 12:52 ` Arnd Bergmann 2024-06-20 16:23 ` [PATCH 09/15] sh: rework sync_file_range ABI Arnd Bergmann ` (3 subsequent siblings) 5 siblings, 2 replies; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> Using sys_io_pgetevents() as the entry point for compat mode tasks works almost correctly, but misses the sign extension for the min_nr and nr arguments. This was addressed on parisc by switching to compat_sys_io_pgetevents_time64() in commit 6431e92fc827 ("parisc: io_pgetevents_time64() needs compat syscall in 32-bit compat mode"), as well as by using more sophisticated system call wrappers on x86 and s390. However, arm64, mips, powerpc, sparc and riscv still have the same bug. Changes all of them over to use compat_sys_io_pgetevents_time64() like parisc already does. This was clearly the intention when the function was originally added, but it got hooked up incorrectly in the tables. Cc: stable@vger.kernel.org Fixes: 48166e6ea47d ("y2038: add 64-bit time_t syscalls to all 32-bit architectures") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- arch/arm64/include/asm/unistd32.h | 2 +- arch/mips/kernel/syscalls/syscall_n32.tbl | 2 +- arch/mips/kernel/syscalls/syscall_o32.tbl | 2 +- arch/powerpc/kernel/syscalls/syscall.tbl | 2 +- arch/s390/kernel/syscalls/syscall.tbl | 2 +- arch/sparc/kernel/syscalls/syscall.tbl | 2 +- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- include/uapi/asm-generic/unistd.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index 266b96acc014..1386e8e751f2 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -840,7 +840,7 @@ __SYSCALL(__NR_pselect6_time64, compat_sys_pselect6_time64) #define __NR_ppoll_time64 414 __SYSCALL(__NR_ppoll_time64, compat_sys_ppoll_time64) #define __NR_io_pgetevents_time64 416 -__SYSCALL(__NR_io_pgetevents_time64, sys_io_pgetevents) +__SYSCALL(__NR_io_pgetevents_time64, compat_sys_io_pgetevents_time64) #define __NR_recvmmsg_time64 417 __SYSCALL(__NR_recvmmsg_time64, compat_sys_recvmmsg_time64) #define __NR_mq_timedsend_time64 418 diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl index cc869f5d5693..953f5b7dc723 100644 --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -354,7 +354,7 @@ 412 n32 utimensat_time64 sys_utimensat 413 n32 pselect6_time64 compat_sys_pselect6_time64 414 n32 ppoll_time64 compat_sys_ppoll_time64 -416 n32 io_pgetevents_time64 sys_io_pgetevents +416 n32 io_pgetevents_time64 compat_sys_io_pgetevents_time64 417 n32 recvmmsg_time64 compat_sys_recvmmsg_time64 418 n32 mq_timedsend_time64 sys_mq_timedsend 419 n32 mq_timedreceive_time64 sys_mq_timedreceive diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl index 008ebe60263e..85751c9b9cdb 100644 --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -403,7 +403,7 @@ 412 o32 utimensat_time64 sys_utimensat sys_utimensat 413 o32 pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 414 o32 ppoll_time64 sys_ppoll compat_sys_ppoll_time64 -416 o32 io_pgetevents_time64 sys_io_pgetevents sys_io_pgetevents +416 o32 io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 417 o32 recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 418 o32 mq_timedsend_time64 sys_mq_timedsend sys_mq_timedsend 419 o32 mq_timedreceive_time64 sys_mq_timedreceive sys_mq_timedreceive diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl index 3656f1ca7a21..c6b0546b284d 100644 --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -502,7 +502,7 @@ 412 32 utimensat_time64 sys_utimensat sys_utimensat 413 32 pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 414 32 ppoll_time64 sys_ppoll compat_sys_ppoll_time64 -416 32 io_pgetevents_time64 sys_io_pgetevents sys_io_pgetevents +416 32 io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 417 32 recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 418 32 mq_timedsend_time64 sys_mq_timedsend sys_mq_timedsend 419 32 mq_timedreceive_time64 sys_mq_timedreceive sys_mq_timedreceive diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index bd0fee24ad10..01071182763e 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -418,7 +418,7 @@ 412 32 utimensat_time64 - sys_utimensat 413 32 pselect6_time64 - compat_sys_pselect6_time64 414 32 ppoll_time64 - compat_sys_ppoll_time64 -416 32 io_pgetevents_time64 - sys_io_pgetevents +416 32 io_pgetevents_time64 - compat_sys_io_pgetevents_time64 417 32 recvmmsg_time64 - compat_sys_recvmmsg_time64 418 32 mq_timedsend_time64 - sys_mq_timedsend 419 32 mq_timedreceive_time64 - sys_mq_timedreceive diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl index ac6c281ccfe0..b354139b40be 100644 --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -461,7 +461,7 @@ 412 32 utimensat_time64 sys_utimensat sys_utimensat 413 32 pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 414 32 ppoll_time64 sys_ppoll compat_sys_ppoll_time64 -416 32 io_pgetevents_time64 sys_io_pgetevents sys_io_pgetevents +416 32 io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 417 32 recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 418 32 mq_timedsend_time64 sys_mq_timedsend sys_mq_timedsend 419 32 mq_timedreceive_time64 sys_mq_timedreceive sys_mq_timedreceive diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 7fd1f57ad3d3..d6ebcab1d8b2 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -420,7 +420,7 @@ 412 i386 utimensat_time64 sys_utimensat 413 i386 pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 414 i386 ppoll_time64 sys_ppoll compat_sys_ppoll_time64 -416 i386 io_pgetevents_time64 sys_io_pgetevents +416 i386 io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 417 i386 recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 418 i386 mq_timedsend_time64 sys_mq_timedsend 419 i386 mq_timedreceive_time64 sys_mq_timedreceive diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index d983c48a3b6a..3fdaa573d661 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -737,7 +737,7 @@ __SC_COMP(__NR_pselect6_time64, sys_pselect6, compat_sys_pselect6_time64) #define __NR_ppoll_time64 414 __SC_COMP(__NR_ppoll_time64, sys_ppoll, compat_sys_ppoll_time64) #define __NR_io_pgetevents_time64 416 -__SYSCALL(__NR_io_pgetevents_time64, sys_io_pgetevents) +__SYSCALL(__NR_io_pgetevents_time64, sys_io_pgetevents, compat_sys_io_pgetevents_time64) #define __NR_recvmmsg_time64 417 __SC_COMP(__NR_recvmmsg_time64, sys_recvmmsg, compat_sys_recvmmsg_time64) #define __NR_mq_timedsend_time64 418 -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-06-20 16:23 ` [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage Arnd Bergmann @ 2024-06-21 14:19 ` Heiko Carstens 2024-06-24 12:52 ` Arnd Bergmann 1 sibling, 0 replies; 16+ messages in thread From: Heiko Carstens @ 2024-06-21 14:19 UTC (permalink / raw) To: Arnd Bergmann Cc: linux-arch, linux-kernel, Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable On Thu, Jun 20, 2024 at 06:23:03PM +0200, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > Using sys_io_pgetevents() as the entry point for compat mode tasks > works almost correctly, but misses the sign extension for the min_nr > and nr arguments. > > This was addressed on parisc by switching to > compat_sys_io_pgetevents_time64() in commit 6431e92fc827 ("parisc: > io_pgetevents_time64() needs compat syscall in 32-bit compat mode"), > as well as by using more sophisticated system call wrappers on x86 and > s390. However, arm64, mips, powerpc, sparc and riscv still have the > same bug. > > Changes all of them over to use compat_sys_io_pgetevents_time64() > like parisc already does. This was clearly the intention when the > function was originally added, but it got hooked up incorrectly in > the tables. > > Cc: stable@vger.kernel.org > Fixes: 48166e6ea47d ("y2038: add 64-bit time_t syscalls to all 32-bit architectures") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > arch/arm64/include/asm/unistd32.h | 2 +- > arch/mips/kernel/syscalls/syscall_n32.tbl | 2 +- > arch/mips/kernel/syscalls/syscall_o32.tbl | 2 +- > arch/powerpc/kernel/syscalls/syscall.tbl | 2 +- > arch/s390/kernel/syscalls/syscall.tbl | 2 +- > arch/sparc/kernel/syscalls/syscall.tbl | 2 +- > arch/x86/entry/syscalls/syscall_32.tbl | 2 +- > include/uapi/asm-generic/unistd.h | 2 +- > 8 files changed, 8 insertions(+), 8 deletions(-) Acked-by: Heiko Carstens <hca@linux.ibm.com> # s390 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-06-20 16:23 ` [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage Arnd Bergmann 2024-06-21 14:19 ` Heiko Carstens @ 2024-06-24 12:52 ` Arnd Bergmann 1 sibling, 0 replies; 16+ messages in thread From: Arnd Bergmann @ 2024-06-24 12:52 UTC (permalink / raw) To: Arnd Bergmann, Linux-Arch, linux-kernel Cc: Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S . Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N. Rao, linuxppc-dev, Brian Cain, linux-hexagon, guoren, linux-csky@vger.kernel.org, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, Xi Ruoyao, musl@lists.openwall.com, LTP List, stable On Thu, Jun 20, 2024, at 18:23, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > Using sys_io_pgetevents() as the entry point for compat mode tasks > works almost correctly, but misses the sign extension for the min_nr > and nr arguments. > > This was addressed on parisc by switching to > compat_sys_io_pgetevents_time64() in commit 6431e92fc827 ("parisc: > io_pgetevents_time64() needs compat syscall in 32-bit compat mode"), > as well as by using more sophisticated system call wrappers on x86 and > s390. However, arm64, mips, powerpc, sparc and riscv still have the > same bug. > > Changes all of them over to use compat_sys_io_pgetevents_time64() > like parisc already does. This was clearly the intention when the > function was originally added, but it got hooked up incorrectly in > the tables. > > Cc: stable@vger.kernel.org > Fixes: 48166e6ea47d ("y2038: add 64-bit time_t syscalls to all 32-bit > architectures") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > arch/arm64/include/asm/unistd32.h | 2 +- > arch/mips/kernel/syscalls/syscall_n32.tbl | 2 +- > arch/mips/kernel/syscalls/syscall_o32.tbl | 2 +- > arch/powerpc/kernel/syscalls/syscall.tbl | 2 +- > arch/s390/kernel/syscalls/syscall.tbl | 2 +- > arch/sparc/kernel/syscalls/syscall.tbl | 2 +- > arch/x86/entry/syscalls/syscall_32.tbl | 2 +- > include/uapi/asm-generic/unistd.h | 2 +- > 8 files changed, 8 insertions(+), 8 deletions(-) The build bot reported a randconfig regressions with this patch, which I've now fixed up like this: diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index d7eee421d4bc..b696b85ac63e 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -46,8 +46,8 @@ COND_SYSCALL(io_getevents_time32); COND_SYSCALL(io_getevents); COND_SYSCALL(io_pgetevents_time32); COND_SYSCALL(io_pgetevents); -COND_SYSCALL_COMPAT(io_pgetevents_time32); COND_SYSCALL_COMPAT(io_pgetevents); +COND_SYSCALL_COMPAT(io_pgetevents_time64); COND_SYSCALL(io_uring_setup); COND_SYSCALL(io_uring_enter); COND_SYSCALL(io_uring_register); This was already broken on parisc the same way, but the mistake in sys_ni.c turned into a link failure for every compat architecture after my patch. Arnd ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 09/15] sh: rework sync_file_range ABI [not found] <20240620162316.3674955-1-arnd@kernel.org> 2024-06-20 16:23 ` [PATCH 01/15] ftruncate: pass a signed offset Arnd Bergmann 2024-06-20 16:23 ` [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage Arnd Bergmann @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-21 8:44 ` John Paul Adrian Glaubitz 2024-06-20 16:23 ` [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range Arnd Bergmann ` (2 subsequent siblings) 5 siblings, 1 reply; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> The unusual function calling conventions on superh ended up causing sync_file_range to have the wrong argument order, with the 'flags' argument getting sorted before 'nbytes' by the compiler. In userspace, I found that musl, glibc, uclibc and strace all expect the normal calling conventions with 'nbytes' last, so changing the kernel to match them should make all of those work. In order to be able to also fix libc implementations to work with existing kernels, they need to be able to tell which ABI is used. An easy way to do this is to add yet another system call using the sync_file_range2 ABI that works the same on all architectures. Old user binaries can now work on new kernels, and new binaries can try the new sync_file_range2() to work with new kernels or fall back to the old sync_file_range() version if that doesn't exist. Cc: stable@vger.kernel.org Fixes: 75c92acdd5b1 ("sh: Wire up new syscalls.") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- arch/sh/kernel/sys_sh32.c | 11 +++++++++++ arch/sh/kernel/syscalls/syscall.tbl | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/sh/kernel/sys_sh32.c b/arch/sh/kernel/sys_sh32.c index 9dca568509a5..d5a4f7c697d8 100644 --- a/arch/sh/kernel/sys_sh32.c +++ b/arch/sh/kernel/sys_sh32.c @@ -59,3 +59,14 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1, (u64)len0 << 32 | len1, advice); #endif } + +/* + * swap the arguments the way that libc wants it instead of + * moving flags ahead of the 64-bit nbytes argument + */ +SYSCALL_DEFINE6(sh_sync_file_range6, int, fd, SC_ARG64(offset), + SC_ARG64(nbytes), unsigned int, flags) +{ + return ksys_sync_file_range(fd, SC_VAL64(loff_t, offset), + SC_VAL64(loff_t, nbytes), flags); +} diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl index bbf83a2db986..c55fd7696d40 100644 --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -321,7 +321,7 @@ 311 common set_robust_list sys_set_robust_list 312 common get_robust_list sys_get_robust_list 313 common splice sys_splice -314 common sync_file_range sys_sync_file_range +314 common sync_file_range sys_sh_sync_file_range6 315 common tee sys_tee 316 common vmsplice sys_vmsplice 317 common move_pages sys_move_pages @@ -395,6 +395,7 @@ 385 common pkey_alloc sys_pkey_alloc 386 common pkey_free sys_pkey_free 387 common rseq sys_rseq +388 common sync_file_range2 sys_sync_file_range2 # room for arch specific syscalls 393 common semget sys_semget 394 common semctl sys_semctl -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 09/15] sh: rework sync_file_range ABI 2024-06-20 16:23 ` [PATCH 09/15] sh: rework sync_file_range ABI Arnd Bergmann @ 2024-06-21 8:44 ` John Paul Adrian Glaubitz 2024-06-21 9:41 ` Arnd Bergmann 2024-06-21 19:57 ` [musl] " Rich Felker 0 siblings, 2 replies; 16+ messages in thread From: John Paul Adrian Glaubitz @ 2024-06-21 8:44 UTC (permalink / raw) To: Arnd Bergmann, linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable Hi Arnd, thanks for your patch! On Thu, 2024-06-20 at 18:23 +0200, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The unusual function calling conventions on superh ended up causing ^^^^^^ It's spelled SuperH > sync_file_range to have the wrong argument order, with the 'flags' > argument getting sorted before 'nbytes' by the compiler. > > In userspace, I found that musl, glibc, uclibc and strace all expect the > normal calling conventions with 'nbytes' last, so changing the kernel > to match them should make all of those work. > > In order to be able to also fix libc implementations to work with existing > kernels, they need to be able to tell which ABI is used. An easy way > to do this is to add yet another system call using the sync_file_range2 > ABI that works the same on all architectures. > > Old user binaries can now work on new kernels, and new binaries can > try the new sync_file_range2() to work with new kernels or fall back > to the old sync_file_range() version if that doesn't exist. > > Cc: stable@vger.kernel.org > Fixes: 75c92acdd5b1 ("sh: Wire up new syscalls.") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > arch/sh/kernel/sys_sh32.c | 11 +++++++++++ > arch/sh/kernel/syscalls/syscall.tbl | 3 ++- > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/arch/sh/kernel/sys_sh32.c b/arch/sh/kernel/sys_sh32.c > index 9dca568509a5..d5a4f7c697d8 100644 > --- a/arch/sh/kernel/sys_sh32.c > +++ b/arch/sh/kernel/sys_sh32.c > @@ -59,3 +59,14 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1, > (u64)len0 << 32 | len1, advice); > #endif > } > + > +/* > + * swap the arguments the way that libc wants it instead of I think "swap the arguments to the order that libc wants them" would be easier to understand here. > + * moving flags ahead of the 64-bit nbytes argument > + */ > +SYSCALL_DEFINE6(sh_sync_file_range6, int, fd, SC_ARG64(offset), > + SC_ARG64(nbytes), unsigned int, flags) > +{ > + return ksys_sync_file_range(fd, SC_VAL64(loff_t, offset), > + SC_VAL64(loff_t, nbytes), flags); > +} > diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl > index bbf83a2db986..c55fd7696d40 100644 > --- a/arch/sh/kernel/syscalls/syscall.tbl > +++ b/arch/sh/kernel/syscalls/syscall.tbl > @@ -321,7 +321,7 @@ > 311 common set_robust_list sys_set_robust_list > 312 common get_robust_list sys_get_robust_list > 313 common splice sys_splice > -314 common sync_file_range sys_sync_file_range > +314 common sync_file_range sys_sh_sync_file_range6 ^^^^^^ Why the suffix 6 here? > 315 common tee sys_tee > 316 common vmsplice sys_vmsplice > 317 common move_pages sys_move_pages > @@ -395,6 +395,7 @@ > 385 common pkey_alloc sys_pkey_alloc > 386 common pkey_free sys_pkey_free > 387 common rseq sys_rseq > +388 common sync_file_range2 sys_sync_file_range2 > # room for arch specific syscalls > 393 common semget sys_semget > 394 common semctl sys_semctl I wonder how you discovered this bug. Did you look up the calling convention on SuperH and compare the argument order for the sys_sync_file_range system call documented there with the order in the kernel? Did you also check what order libc uses? I would expect libc on SuperH misordering the arguments as well unless I am missing something. Or do we know that the code is actually currently broken? Thanks, Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 09/15] sh: rework sync_file_range ABI 2024-06-21 8:44 ` John Paul Adrian Glaubitz @ 2024-06-21 9:41 ` Arnd Bergmann 2024-06-24 6:14 ` John Paul Adrian Glaubitz 2024-06-21 19:57 ` [musl] " Rich Felker 1 sibling, 1 reply; 16+ messages in thread From: Arnd Bergmann @ 2024-06-21 9:41 UTC (permalink / raw) To: John Paul Adrian Glaubitz, Arnd Bergmann, Linux-Arch, linux-kernel Cc: Rich Felker, Andreas Larsson, guoren, Christophe Leroy, H. Peter Anvin, sparclinux, linux-s390, Helge Deller, linux-sh, linux-csky@vger.kernel.org, Naveen N. Rao, Heiko Carstens, musl@lists.openwall.com, Nicholas Piggin, Alexander Viro, LTP List, Brian Cain, Christian Brauner, Thomas Bogendoerfer, Xi Ruoyao, linux-parisc, linux-mips, stable, linux-hexagon, linux-fsdevel, linuxppc-dev, David S . Miller On Fri, Jun 21, 2024, at 10:44, John Paul Adrian Glaubitz wrote: > On Thu, 2024-06-20 at 18:23 +0200, Arnd Bergmann wrote: >> From: Arnd Bergmann <arnd@arndb.de> >> >> The unusual function calling conventions on superh ended up causing > ^^^^^^ > It's spelled SuperH Fixed now. >> diff --git a/arch/sh/kernel/sys_sh32.c b/arch/sh/kernel/sys_sh32.c >> index 9dca568509a5..d5a4f7c697d8 100644 >> --- a/arch/sh/kernel/sys_sh32.c >> +++ b/arch/sh/kernel/sys_sh32.c >> @@ -59,3 +59,14 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1, >> (u64)len0 << 32 | len1, advice); >> #endif >> } >> + >> +/* >> + * swap the arguments the way that libc wants it instead of > > I think "swap the arguments to the order that libc wants them" would > be easier to understand here. Done >> diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl >> index bbf83a2db986..c55fd7696d40 100644 >> --- a/arch/sh/kernel/syscalls/syscall.tbl >> +++ b/arch/sh/kernel/syscalls/syscall.tbl >> @@ -321,7 +321,7 @@ >> 311 common set_robust_list sys_set_robust_list >> 312 common get_robust_list sys_get_robust_list >> 313 common splice sys_splice >> -314 common sync_file_range sys_sync_file_range >> +314 common sync_file_range sys_sh_sync_file_range6 > ^^^^^^ > Why the suffix 6 here? In a later part of my cleanup, I'm consolidating all the copies of this function (arm64, mips, parisc, powerpc, s390, sh, sparc, x86) and picked the name sys_sync_file_range6() for common implementation. I end up with four entry points here, so the naming is a bit confusing: - sys_sync_file_range() is only used on 64-bit architectures, on x32 and on mips-n32. This uses four arguments, including two 64-bit wide ones. - sys_sync_file_range2() continues to be used on arm, powerpc, xtensa and now on sh, hexagon and csky. I change the implementation to take six 32-bit arguments, but the ABI remains the same as before, with the flags before offset. - sys_sync_file_range6() is used for most other 32-bit ABIs: arc, m68k, microblaze, nios2, openrisc, parisc, s390, sh, sparc and x86. This also has six 32-bit arguments but in the default order (fd, offset, nbytes, flags). - sys_sync_file_range7() is exclusive to mips-o32, this one has an unused argument and is otherwise the same as sys_sync_file_range6(). My plan is to then have some infrastructure to ensure userspace tools (libc, strace, qemu, rust, ...) use the same calling conventions as the kernel. I'm doing the same thing for all other syscalls that have architecture specific calling conventions, so far I'm using fadvise64_64_7 fanotify_mark6 truncate3 truncate4 ftruncate3 ftruncate4 fallocate6 pread5 pread6 pwrite5 pwrite6 preadv5 preadv6 pwritev5 pwritev6 sync_file_range6 fadvise64_64_2 fadvise64_64_6 fadvise64_5 fadvise64_6 readahead4 readahead5 The last number here is usually the number of 32-bit arguments, except for fadvise64_64_2 that uses the same argument reordering trick as sync_file_range2. I'm not too happy with the naming but couldn't come up with anything clearer either, so let me know if you have any ideas there. >> 315 common tee sys_tee >> 316 common vmsplice sys_vmsplice >> 317 common move_pages sys_move_pages >> @@ -395,6 +395,7 @@ >> 385 common pkey_alloc sys_pkey_alloc >> 386 common pkey_free sys_pkey_free >> 387 common rseq sys_rseq >> +388 common sync_file_range2 sys_sync_file_range2 >> # room for arch specific syscalls >> 393 common semget sys_semget >> 394 common semctl sys_semctl > > I wonder how you discovered this bug. Did you look up the calling > convention on SuperH > and compare the argument order for the sys_sync_file_range system call > documented there > with the order in the kernel? I had to categorize all architectures based on their calling conventions to see if 64-bit arguments need aligned pairs or not, so I wrote a set of simple C files that I compiled for all architectures to see in which cases they insert unused arguments or swap the order of the upper and lower halves. SuperH, parisc and s390 are each slightly different from all the others here, so I ended up reading the ELF psABI docs and/or the compiler sources to be sure. I also a lot of git history. > Did you also check what order libc uses? I would expect libc on SuperH > misordering the > arguments as well unless I am missing something. Or do we know that the > code is actually > currently broken? Yes, I checked glibc, musl and uclibc-ng for all the cases in which the ABI made no sense, as well as to check that my analysis of the kernel sources matches the expectations of the libc. Arnd ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 09/15] sh: rework sync_file_range ABI 2024-06-21 9:41 ` Arnd Bergmann @ 2024-06-24 6:14 ` John Paul Adrian Glaubitz 2024-06-24 12:49 ` Arnd Bergmann 0 siblings, 1 reply; 16+ messages in thread From: John Paul Adrian Glaubitz @ 2024-06-24 6:14 UTC (permalink / raw) To: Arnd Bergmann, Arnd Bergmann, Linux-Arch, linux-kernel Cc: Rich Felker, Andreas Larsson, guoren, Christophe Leroy, H. Peter Anvin, sparclinux, linux-s390, Helge Deller, linux-sh, linux-csky@vger.kernel.org, Naveen N. Rao, Heiko Carstens, musl@lists.openwall.com, Nicholas Piggin, Alexander Viro, LTP List, Brian Cain, Christian Brauner, Thomas Bogendoerfer, Xi Ruoyao, linux-parisc, linux-mips, stable, linux-hexagon, linux-fsdevel, linuxppc-dev, David S . Miller Hi Arnd, On Fri, 2024-06-21 at 11:41 +0200, Arnd Bergmann wrote: > On Fri, Jun 21, 2024, at 10:44, John Paul Adrian Glaubitz wrote: > > On Thu, 2024-06-20 at 18:23 +0200, Arnd Bergmann wrote: > > > From: Arnd Bergmann <arnd@arndb.de> > > > > > > The unusual function calling conventions on superh ended up causing > > ^^^^^^ > > It's spelled SuperH > > Fixed now. > > > > diff --git a/arch/sh/kernel/sys_sh32.c b/arch/sh/kernel/sys_sh32.c > > > index 9dca568509a5..d5a4f7c697d8 100644 > > > --- a/arch/sh/kernel/sys_sh32.c > > > +++ b/arch/sh/kernel/sys_sh32.c > > > @@ -59,3 +59,14 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1, > > > (u64)len0 << 32 | len1, advice); > > > #endif > > > } > > > + > > > +/* > > > + * swap the arguments the way that libc wants it instead of > > > > I think "swap the arguments to the order that libc wants them" would > > be easier to understand here. > > Done Thanks for the two improvements! > > > diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl > > > index bbf83a2db986..c55fd7696d40 100644 > > > --- a/arch/sh/kernel/syscalls/syscall.tbl > > > +++ b/arch/sh/kernel/syscalls/syscall.tbl > > > @@ -321,7 +321,7 @@ > > > 311 common set_robust_list sys_set_robust_list > > > 312 common get_robust_list sys_get_robust_list > > > 313 common splice sys_splice > > > -314 common sync_file_range sys_sync_file_range > > > +314 common sync_file_range sys_sh_sync_file_range6 > > ^^^^^^ > > Why the suffix 6 here? > > In a later part of my cleanup, I'm consolidating all the > copies of this function (arm64, mips, parisc, powerpc, > s390, sh, sparc, x86) and picked the name > sys_sync_file_range6() for common implementation. > > I end up with four entry points here, so the naming is a bit > confusing: > > - sys_sync_file_range() is only used on 64-bit architectures, > on x32 and on mips-n32. This uses four arguments, including > two 64-bit wide ones. > > - sys_sync_file_range2() continues to be used on arm, powerpc, > xtensa and now on sh, hexagon and csky. I change the > implementation to take six 32-bit arguments, but the ABI > remains the same as before, with the flags before offset. > > - sys_sync_file_range6() is used for most other 32-bit ABIs: > arc, m68k, microblaze, nios2, openrisc, parisc, s390, sh, sparc > and x86. This also has six 32-bit arguments but in the > default order (fd, offset, nbytes, flags). > > - sys_sync_file_range7() is exclusive to mips-o32, this one > has an unused argument and is otherwise the same as > sys_sync_file_range6(). > > My plan is to then have some infrastructure to ensure > userspace tools (libc, strace, qemu, rust, ...) use the > same calling conventions as the kernel. I'm doing the > same thing for all other syscalls that have architecture > specific calling conventions, so far I'm using > > fadvise64_64_7 > fanotify_mark6 > truncate3 > truncate4 > ftruncate3 > ftruncate4 > fallocate6 > pread5 > pread6 > pwrite5 > pwrite6 > preadv5 > preadv6 > pwritev5 > pwritev6 > sync_file_range6 > fadvise64_64_2 > fadvise64_64_6 > fadvise64_5 > fadvise64_6 > readahead4 > readahead5 > > The last number here is usually the number of 32-bit > arguments, except for fadvise64_64_2 that uses the > same argument reordering trick as sync_file_range2. > > I'm not too happy with the naming but couldn't come up with > anything clearer either, so let me know if you have any > ideas there. OK, gotcha. I thought the 6 suffix was for SH only. I'm fine with the naming scheme. > > > 315 common tee sys_tee > > > 316 common vmsplice sys_vmsplice > > > 317 common move_pages sys_move_pages > > > @@ -395,6 +395,7 @@ > > > 385 common pkey_alloc sys_pkey_alloc > > > 386 common pkey_free sys_pkey_free > > > 387 common rseq sys_rseq > > > +388 common sync_file_range2 sys_sync_file_range2 > > > # room for arch specific syscalls > > > 393 common semget sys_semget > > > 394 common semctl sys_semctl > > > > I wonder how you discovered this bug. Did you look up the calling > > convention on SuperH > > and compare the argument order for the sys_sync_file_range system call > > documented there > > with the order in the kernel? > > I had to categorize all architectures based on their calling > conventions to see if 64-bit arguments need aligned pairs or > not, so I wrote a set of simple C files that I compiled for > all architectures to see in which cases they insert unused > arguments or swap the order of the upper and lower halves. > > SuperH, parisc and s390 are each slightly different from all the > others here, so I ended up reading the ELF psABI docs and/or > the compiler sources to be sure. > I also a lot of git history. Great job, thanks for doing the extra work to verify the ABI. > > Did you also check what order libc uses? I would expect libc on SuperH > > misordering the > > arguments as well unless I am missing something. Or do we know that the > > code is actually > > currently broken? > > Yes, I checked glibc, musl and uclibc-ng for all the cases in > which the ABI made no sense, as well as to check that my analysis > of the kernel sources matches the expectations of the libc. OK, awesome. Will you send a v2 so I can ack the updated version of the patch? I'm also fine with the patch going through your tree, as I would like to start with the changes for v6.11 this week. Thanks, Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 09/15] sh: rework sync_file_range ABI 2024-06-24 6:14 ` John Paul Adrian Glaubitz @ 2024-06-24 12:49 ` Arnd Bergmann 0 siblings, 0 replies; 16+ messages in thread From: Arnd Bergmann @ 2024-06-24 12:49 UTC (permalink / raw) To: John Paul Adrian Glaubitz, Arnd Bergmann, Linux-Arch, linux-kernel Cc: Rich Felker, Andreas Larsson, guoren, linux-csky@vger.kernel.org, H. Peter Anvin, sparclinux, linux-s390, linux-hexagon, Helge Deller, linux-sh, Christophe Leroy, Naveen N. Rao, Heiko Carstens, musl@lists.openwall.com, Nicholas Piggin, Alexander Viro, LTP List, Brian Cain, Christian Brauner, Thomas Bogendoerfer, Xi Ruoyao, linux-parisc, linux-mips, stable, linux-fsdevel, linuxppc-dev, David S . Miller On Mon, Jun 24, 2024, at 08:14, John Paul Adrian Glaubitz wrote: > On Fri, 2024-06-21 at 11:41 +0200, Arnd Bergmann wrote: >> On Fri, Jun 21, 2024, at 10:44, John Paul Adrian Glaubitz wrote: >> > Did you also check what order libc uses? I would expect libc on SuperH >> > misordering the >> > arguments as well unless I am missing something. Or do we know that the >> > code is actually >> > currently broken? >> >> Yes, I checked glibc, musl and uclibc-ng for all the cases in >> which the ABI made no sense, as well as to check that my analysis >> of the kernel sources matches the expectations of the libc. > > OK, awesome. > > Will you send a v2 so I can ack the updated version of the patch? > > I'm also fine with the patch going through your tree, as I would > like to start with the changes for v6.11 this week. I should be able to get a v2 out today and apply that to my asm-generic tree to have in linux-next before I send the pull request. Arnd ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [musl] Re: [PATCH 09/15] sh: rework sync_file_range ABI 2024-06-21 8:44 ` John Paul Adrian Glaubitz 2024-06-21 9:41 ` Arnd Bergmann @ 2024-06-21 19:57 ` Rich Felker 1 sibling, 0 replies; 16+ messages in thread From: Rich Felker @ 2024-06-21 19:57 UTC (permalink / raw) To: John Paul Adrian Glaubitz Cc: Arnd Bergmann, linux-arch, linux-kernel, Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable On Fri, Jun 21, 2024 at 10:44:39AM +0200, John Paul Adrian Glaubitz wrote: > Hi Arnd, > > thanks for your patch! > > On Thu, 2024-06-20 at 18:23 +0200, Arnd Bergmann wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > The unusual function calling conventions on superh ended up causing > ^^^^^^ > It's spelled SuperH > > > sync_file_range to have the wrong argument order, with the 'flags' > > argument getting sorted before 'nbytes' by the compiler. > > > > In userspace, I found that musl, glibc, uclibc and strace all expect the > > normal calling conventions with 'nbytes' last, so changing the kernel > > to match them should make all of those work. > > > > In order to be able to also fix libc implementations to work with existing > > kernels, they need to be able to tell which ABI is used. An easy way > > to do this is to add yet another system call using the sync_file_range2 > > ABI that works the same on all architectures. > > > > Old user binaries can now work on new kernels, and new binaries can > > try the new sync_file_range2() to work with new kernels or fall back > > to the old sync_file_range() version if that doesn't exist. > > > > Cc: stable@vger.kernel.org > > Fixes: 75c92acdd5b1 ("sh: Wire up new syscalls.") > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > > --- > > arch/sh/kernel/sys_sh32.c | 11 +++++++++++ > > arch/sh/kernel/syscalls/syscall.tbl | 3 ++- > > 2 files changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/arch/sh/kernel/sys_sh32.c b/arch/sh/kernel/sys_sh32.c > > index 9dca568509a5..d5a4f7c697d8 100644 > > --- a/arch/sh/kernel/sys_sh32.c > > +++ b/arch/sh/kernel/sys_sh32.c > > @@ -59,3 +59,14 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1, > > (u64)len0 << 32 | len1, advice); > > #endif > > } > > + > > +/* > > + * swap the arguments the way that libc wants it instead of > > I think "swap the arguments to the order that libc wants them" would > be easier to understand here. > > > + * moving flags ahead of the 64-bit nbytes argument > > + */ > > +SYSCALL_DEFINE6(sh_sync_file_range6, int, fd, SC_ARG64(offset), > > + SC_ARG64(nbytes), unsigned int, flags) > > +{ > > + return ksys_sync_file_range(fd, SC_VAL64(loff_t, offset), > > + SC_VAL64(loff_t, nbytes), flags); > > +} > > diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl > > index bbf83a2db986..c55fd7696d40 100644 > > --- a/arch/sh/kernel/syscalls/syscall.tbl > > +++ b/arch/sh/kernel/syscalls/syscall.tbl > > @@ -321,7 +321,7 @@ > > 311 common set_robust_list sys_set_robust_list > > 312 common get_robust_list sys_get_robust_list > > 313 common splice sys_splice > > -314 common sync_file_range sys_sync_file_range > > +314 common sync_file_range sys_sh_sync_file_range6 > ^^^^^^ Why the suffix 6 here? > > > 315 common tee sys_tee > > 316 common vmsplice sys_vmsplice > > 317 common move_pages sys_move_pages > > @@ -395,6 +395,7 @@ > > 385 common pkey_alloc sys_pkey_alloc > > 386 common pkey_free sys_pkey_free > > 387 common rseq sys_rseq > > +388 common sync_file_range2 sys_sync_file_range2 > > # room for arch specific syscalls > > 393 common semget sys_semget > > 394 common semctl sys_semctl > > I wonder how you discovered this bug. Did you look up the calling convention on SuperH > and compare the argument order for the sys_sync_file_range system call documented there > with the order in the kernel? > > Did you also check what order libc uses? I would expect libc on SuperH misordering the > arguments as well unless I am missing something. Or do we know that the code is actually > currently broken? No, there's no reason libc would misorder them because syscalls aren't function calls, and aren't subject to function call ABI. We have to explicitly bind the arguments to registers and make a syscall instruction. The only reason this bug happened on the kernel side is that someone thought it would be a smart idea to save maybe 10 instructions by treating the register state on entry as directly suitable to jump from asm to a C function rather than explicitly marshalling the arguments out of the user-kernel syscall ABI positions into actual arguments to a C function call. Rich ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range [not found] <20240620162316.3674955-1-arnd@kernel.org> ` (2 preceding siblings ...) 2024-06-20 16:23 ` [PATCH 09/15] sh: rework sync_file_range ABI Arnd Bergmann @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-23 17:10 ` Guo Ren 2024-06-20 16:23 ` [PATCH 11/15] hexagon: fix fadvise64_64 calling conventions Arnd Bergmann 2024-06-20 16:23 ` [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling Arnd Bergmann 5 siblings, 1 reply; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> Both of these architectures require u64 function arguments to be passed in even/odd pairs of registers or stack slots, which in case of sync_file_range would result in a seven-argument system call that is not currently possible. The system call is therefore incompatible with all existing binaries. While it would be possible to implement support for seven arguments like on mips, it seems better to use a six-argument version, either with the normal argument order but misaligned as on most architectures or with the reordered sync_file_range2() calling conventions as on arm and powerpc. Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- arch/csky/include/uapi/asm/unistd.h | 1 + arch/hexagon/include/uapi/asm/unistd.h | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/csky/include/uapi/asm/unistd.h b/arch/csky/include/uapi/asm/unistd.h index 7ff6a2466af1..e0594b6370a6 100644 --- a/arch/csky/include/uapi/asm/unistd.h +++ b/arch/csky/include/uapi/asm/unistd.h @@ -6,6 +6,7 @@ #define __ARCH_WANT_SYS_CLONE3 #define __ARCH_WANT_SET_GET_RLIMIT #define __ARCH_WANT_TIME32_SYSCALLS +#define __ARCH_WANT_SYNC_FILE_RANGE2 #include <asm-generic/unistd.h> #define __NR_set_thread_area (__NR_arch_specific_syscall + 0) diff --git a/arch/hexagon/include/uapi/asm/unistd.h b/arch/hexagon/include/uapi/asm/unistd.h index 432c4db1b623..21ae22306b5d 100644 --- a/arch/hexagon/include/uapi/asm/unistd.h +++ b/arch/hexagon/include/uapi/asm/unistd.h @@ -36,5 +36,6 @@ #define __ARCH_WANT_SYS_VFORK #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_TIME32_SYSCALLS +#define __ARCH_WANT_SYNC_FILE_RANGE2 #include <asm-generic/unistd.h> -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range 2024-06-20 16:23 ` [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range Arnd Bergmann @ 2024-06-23 17:10 ` Guo Ren 0 siblings, 0 replies; 16+ messages in thread From: Guo Ren @ 2024-06-23 17:10 UTC (permalink / raw) To: Arnd Bergmann Cc: linux-arch, linux-kernel, Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable On Fri, Jun 21, 2024 at 12:24 AM Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > Both of these architectures require u64 function arguments to be > passed in even/odd pairs of registers or stack slots, which in case of > sync_file_range would result in a seven-argument system call that is > not currently possible. The system call is therefore incompatible with > all existing binaries. > > While it would be possible to implement support for seven arguments > like on mips, it seems better to use a six-argument version, either > with the normal argument order but misaligned as on most architectures > or with the reordered sync_file_range2() calling conventions as on > arm and powerpc. > > Cc: stable@vger.kernel.org > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > arch/csky/include/uapi/asm/unistd.h | 1 + > arch/hexagon/include/uapi/asm/unistd.h | 1 + > 2 files changed, 2 insertions(+) > > diff --git a/arch/csky/include/uapi/asm/unistd.h b/arch/csky/include/uapi/asm/unistd.h > index 7ff6a2466af1..e0594b6370a6 100644 > --- a/arch/csky/include/uapi/asm/unistd.h > +++ b/arch/csky/include/uapi/asm/unistd.h > @@ -6,6 +6,7 @@ > #define __ARCH_WANT_SYS_CLONE3 > #define __ARCH_WANT_SET_GET_RLIMIT > #define __ARCH_WANT_TIME32_SYSCALLS > +#define __ARCH_WANT_SYNC_FILE_RANGE2 For csky part. Acked-by: Guo Ren <guoren@kernel.org> > #include <asm-generic/unistd.h> > > #define __NR_set_thread_area (__NR_arch_specific_syscall + 0) > diff --git a/arch/hexagon/include/uapi/asm/unistd.h b/arch/hexagon/include/uapi/asm/unistd.h > index 432c4db1b623..21ae22306b5d 100644 > --- a/arch/hexagon/include/uapi/asm/unistd.h > +++ b/arch/hexagon/include/uapi/asm/unistd.h > @@ -36,5 +36,6 @@ > #define __ARCH_WANT_SYS_VFORK > #define __ARCH_WANT_SYS_FORK > #define __ARCH_WANT_TIME32_SYSCALLS > +#define __ARCH_WANT_SYNC_FILE_RANGE2 > > #include <asm-generic/unistd.h> > -- > 2.39.2 > -- Best Regards Guo Ren ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 11/15] hexagon: fix fadvise64_64 calling conventions [not found] <20240620162316.3674955-1-arnd@kernel.org> ` (3 preceding siblings ...) 2024-06-20 16:23 ` [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range Arnd Bergmann @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-20 16:23 ` [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling Arnd Bergmann 5 siblings, 0 replies; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> fadvise64_64() has two 64-bit arguments at the wrong alignment for hexagon, which turns them into a 7-argument syscall that is not supported by Linux. The downstream musl port for hexagon actually asks for a 6-argument version the same way we do it on arm, csky, powerpc, so make the kernel do it the same way to avoid having to change both. Link: https://github.com/quic/musl/blob/hexagon/arch/hexagon/syscall_arch.h#L78 Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- arch/hexagon/include/asm/syscalls.h | 6 ++++++ arch/hexagon/kernel/syscalltab.c | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 arch/hexagon/include/asm/syscalls.h diff --git a/arch/hexagon/include/asm/syscalls.h b/arch/hexagon/include/asm/syscalls.h new file mode 100644 index 000000000000..40f2d08bec92 --- /dev/null +++ b/arch/hexagon/include/asm/syscalls.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <asm-generic/syscalls.h> + +asmlinkage long sys_hexagon_fadvise64_64(int fd, int advice, + u32 a2, u32 a3, u32 a4, u32 a5); diff --git a/arch/hexagon/kernel/syscalltab.c b/arch/hexagon/kernel/syscalltab.c index 0fadd582cfc7..5d98bdc494ec 100644 --- a/arch/hexagon/kernel/syscalltab.c +++ b/arch/hexagon/kernel/syscalltab.c @@ -14,6 +14,13 @@ #undef __SYSCALL #define __SYSCALL(nr, call) [nr] = (call), +SYSCALL_DEFINE6(hexagon_fadvise64_64, int, fd, int, advice, + SC_ARG64(offset), SC_ARG64(len)) +{ + return ksys_fadvise64_64(fd, SC_VAL64(loff_t, offset), SC_VAL64(loff_t, len), advice); +} +#define sys_fadvise64_64 sys_hexagon_fadvise64_64 + void *sys_call_table[__NR_syscalls] = { #include <asm/unistd.h> }; -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling [not found] <20240620162316.3674955-1-arnd@kernel.org> ` (4 preceding siblings ...) 2024-06-20 16:23 ` [PATCH 11/15] hexagon: fix fadvise64_64 calling conventions Arnd Bergmann @ 2024-06-20 16:23 ` Arnd Bergmann 2024-06-24 12:36 ` Arnd Bergmann 5 siblings, 1 reply; 16+ messages in thread From: Arnd Bergmann @ 2024-06-20 16:23 UTC (permalink / raw) To: linux-arch, linux-kernel Cc: Arnd Bergmann, Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S. Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N . Rao, linuxppc-dev, Brian Cain, linux-hexagon, Guo Ren, linux-csky, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, libc-alpha, musl, ltp, stable From: Arnd Bergmann <arnd@arndb.de> arch/riscv/ appears to have accidentally enabled the compat time32 syscalls in 64-bit kernels even though the native 32-bit ABI does not expose those. Address this by adding another level of indirection, checking for both the target ABI (32 or 64) and the __ARCH_WANT_TIME32_SYSCALLS macro. The macro arguments are meant to follow the syscall.tbl format, the idea here is that by the end of the series, all other syscalls are changed to the same format to make it possible to move all architectures over to generating the system call table consistently. Only this patch needs to be backported though. Cc: stable@vger.kernel.org # v5.19+ Fixes: 7eb6369d7acf ("RISC-V: Add support for rv32 userspace via COMPAT") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- include/uapi/asm-generic/unistd.h | 146 +++++++++++++++++++----------- 1 file changed, 94 insertions(+), 52 deletions(-) diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 3fdaa573d661..e47c966557d0 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -16,10 +16,32 @@ #define __SYSCALL(x, y) #endif +#ifndef __SC +#define __SC(_cond, _nr, _sys) __SYSCALL_ ## _cond (_nr, _sys) +#endif + +#ifndef __SCC +#ifdef __SYSCALL_COMPAT +#define __SCC(_cond, _nr, _sys, _comp) __SC(_cond, _nr, _comp) +#else +#define __SCC(_cond, _nr, _sys, _comp) __SC(_cond, _nr, _sys) +#endif +#endif + #if __BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT) #define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _32) +#define __SYSCALL_32(_nr, _sys) __SYSCALL(__NR_ ## _nr, _sys) +#define __SYSCALL_64(_nr, _sys) #else #define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _64) +#define __SYSCALL_32(_nr, _sys) +#define __SYSCALL_64(_nr, _sys) __SYSCALL(__NR_ ## _nr, _sys) +#endif + +#if defined(__ARCH_WANT_TIME32_SYSCALLS) +#define __SYSCALL_time32(_nr, _sys) __SYSCALL_32(__NR_ ## _nr, _sys) +#else +#define __SYSCALL_time32(_nr, _sys) #endif #ifdef __SYSCALL_COMPAT @@ -41,7 +63,8 @@ __SYSCALL(__NR_io_cancel, sys_io_cancel) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_io_getevents 4 -__SC_3264(__NR_io_getevents, sys_io_getevents_time32, sys_io_getevents) +__SC(time32, io_getevents, sys_io_getevents_time32) +__SC(64, io_getevents, sys_io_getevents) #endif #define __NR_setxattr 5 @@ -190,9 +213,11 @@ __SYSCALL(__NR3264_sendfile, sys_sendfile64) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_pselect6 72 -__SC_COMP_3264(__NR_pselect6, sys_pselect6_time32, sys_pselect6, compat_sys_pselect6_time32) +__SCC(time32, pselect6, sys_pselect6_time32, compat_sys_pselect6_time32) +__SC(64, pselect6, sys_pselect6) #define __NR_ppoll 73 -__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, compat_sys_ppoll_time32) +__SCC(time32, ppoll, sys_ppoll_time32, compat_sys_ppoll_time32) +__SC(64, ppoll, sys_ppoll) #endif #define __NR_signalfd4 74 @@ -235,16 +260,17 @@ __SYSCALL(__NR_timerfd_create, sys_timerfd_create) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_timerfd_settime 86 -__SC_3264(__NR_timerfd_settime, sys_timerfd_settime32, \ - sys_timerfd_settime) +__SC(time32, timerfd_settime, sys_timerfd_settime32) +__SC(64, timerfd_settime, sys_timerfd_settime) #define __NR_timerfd_gettime 87 -__SC_3264(__NR_timerfd_gettime, sys_timerfd_gettime32, \ - sys_timerfd_gettime) +__SC(time32, timerfd_gettime, sys_timerfd_gettime32) +__SC(64, timerfd_gettime, sys_timerfd_gettime) #endif #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_utimensat 88 -__SC_3264(__NR_utimensat, sys_utimensat_time32, sys_utimensat) +__SC(time32, utimensat, sys_utimensat_time32) +__SC(64, utimensat, sys_utimensat) #endif #define __NR_acct 89 @@ -268,7 +294,8 @@ __SYSCALL(__NR_unshare, sys_unshare) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_futex 98 -__SC_3264(__NR_futex, sys_futex_time32, sys_futex) +__SC(time32, futex, sys_futex_time32) +__SC(64, futex, sys_futex) #endif #define __NR_set_robust_list 99 @@ -280,7 +307,8 @@ __SC_COMP(__NR_get_robust_list, sys_get_robust_list, \ #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_nanosleep 101 -__SC_3264(__NR_nanosleep, sys_nanosleep_time32, sys_nanosleep) +__SC(time32, nanosleep, sys_nanosleep_time32) +__SC(64, nanosleep, sys_nanosleep) #endif #define __NR_getitimer 102 @@ -298,7 +326,8 @@ __SC_COMP(__NR_timer_create, sys_timer_create, compat_sys_timer_create) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_timer_gettime 108 -__SC_3264(__NR_timer_gettime, sys_timer_gettime32, sys_timer_gettime) +__SC(time32, timer_gettime, sys_timer_gettime32) +__SC(64, timer_gettime, sys_timer_gettime) #endif #define __NR_timer_getoverrun 109 @@ -306,7 +335,8 @@ __SYSCALL(__NR_timer_getoverrun, sys_timer_getoverrun) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_timer_settime 110 -__SC_3264(__NR_timer_settime, sys_timer_settime32, sys_timer_settime) +__SC(time32, timer_settime, sys_timer_settime32) +__SC(64, timer_settime, sys_timer_settime) #endif #define __NR_timer_delete 111 @@ -314,14 +344,17 @@ __SYSCALL(__NR_timer_delete, sys_timer_delete) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_clock_settime 112 -__SC_3264(__NR_clock_settime, sys_clock_settime32, sys_clock_settime) +__SC(time32, clock_settime, sys_clock_settime32) +__SC(64, clock_settime, sys_clock_settime) #define __NR_clock_gettime 113 -__SC_3264(__NR_clock_gettime, sys_clock_gettime32, sys_clock_gettime) +__SC(time32, clock_gettime, sys_clock_gettime32) +__SC(64, clock_gettime, sys_clock_gettime) #define __NR_clock_getres 114 -__SC_3264(__NR_clock_getres, sys_clock_getres_time32, sys_clock_getres) +__SC(time32, clock_getres, sys_clock_getres_time32) +__SC(64, clock_getres, sys_clock_getres) #define __NR_clock_nanosleep 115 -__SC_3264(__NR_clock_nanosleep, sys_clock_nanosleep_time32, \ - sys_clock_nanosleep) +__SC(time32, clock_nanosleep, sys_clock_nanosleep_time32) +__SC(64, clock_nanosleep, sys_clock_nanosleep) #endif #define __NR_syslog 116 @@ -351,8 +384,8 @@ __SYSCALL(__NR_sched_get_priority_min, sys_sched_get_priority_min) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_sched_rr_get_interval 127 -__SC_3264(__NR_sched_rr_get_interval, sys_sched_rr_get_interval_time32, \ - sys_sched_rr_get_interval) +__SC(time32, sched_rr_get_interval, sys_sched_rr_get_interval_time32) +__SC(64, sched_rr_get_interval, sys_sched_rr_get_interval) #endif #define __NR_restart_syscall 128 @@ -376,8 +409,8 @@ __SC_COMP(__NR_rt_sigpending, sys_rt_sigpending, compat_sys_rt_sigpending) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_rt_sigtimedwait 137 -__SC_COMP_3264(__NR_rt_sigtimedwait, sys_rt_sigtimedwait_time32, \ - sys_rt_sigtimedwait, compat_sys_rt_sigtimedwait_time32) +__SCC(time32, rt_sigtimedwait, sys_rt_sigtimedwait_time32, compat_sys_rt_sigtimedwait_time32) +__SC(64, rt_sigtimedwait, sys_rt_sigtimedwait) #endif #define __NR_rt_sigqueueinfo 138 @@ -451,11 +484,14 @@ __SYSCALL(__NR_getcpu, sys_getcpu) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_gettimeofday 169 -__SC_COMP(__NR_gettimeofday, sys_gettimeofday, compat_sys_gettimeofday) +__SCC(time32, gettimeofday, sys_gettimeofday, compat_sys_gettimeofday) +__SC(64, gettimeofday, sys_gettimeofday) #define __NR_settimeofday 170 -__SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday) +__SCC(time32, settimeofday, sys_settimeofday, compat_sys_settimeofday) +__SC(64, settimeofday, sys_settimeofday) #define __NR_adjtimex 171 -__SC_3264(__NR_adjtimex, sys_adjtimex_time32, sys_adjtimex) +__SC(time32, adjtimex, sys_adjtimex_time32) +__SC(64, adjtimex, sys_adjtimex) #endif #define __NR_getpid 172 @@ -481,10 +517,11 @@ __SYSCALL(__NR_mq_unlink, sys_mq_unlink) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_mq_timedsend 182 -__SC_3264(__NR_mq_timedsend, sys_mq_timedsend_time32, sys_mq_timedsend) +__SC(time32, mq_timedsend, sys_mq_timedsend_time32) +__SC(64, mq_timedsend, sys_mq_timedsend) #define __NR_mq_timedreceive 183 -__SC_3264(__NR_mq_timedreceive, sys_mq_timedreceive_time32, \ - sys_mq_timedreceive) +__SC(time32, mq_timedreceive, sys_mq_timedreceive_time32) +__SC(64, mq_timedreceive, sys_mq_timedreceive) #endif #define __NR_mq_notify 184 @@ -506,7 +543,8 @@ __SC_COMP(__NR_semctl, sys_semctl, compat_sys_semctl) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_semtimedop 192 -__SC_3264(__NR_semtimedop, sys_semtimedop_time32, sys_semtimedop) +__SC(time32, semtimedop, sys_semtimedop_time32) +__SC(64, semtimedop, sys_semtimedop) #endif #define __NR_semop 193 @@ -618,7 +656,8 @@ __SYSCALL(__NR_accept4, sys_accept4) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_recvmmsg 243 -__SC_COMP_3264(__NR_recvmmsg, sys_recvmmsg_time32, sys_recvmmsg, compat_sys_recvmmsg_time32) +__SCC(time32, recvmmsg, sys_recvmmsg_time32, compat_sys_recvmmsg_time32) +__SC(64, recvmmsg, sys_recvmmsg) #endif /* @@ -629,7 +668,8 @@ __SC_COMP_3264(__NR_recvmmsg, sys_recvmmsg_time32, sys_recvmmsg, compat_sys_recv #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_wait4 260 -__SC_COMP(__NR_wait4, sys_wait4, compat_sys_wait4) +__SCC(time32, wait4, sys_wait4, compat_sys_wait4) +__SC(64, wait4, sys_wait4) #endif #define __NR_prlimit64 261 @@ -645,7 +685,8 @@ __SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_clock_adjtime 266 -__SC_3264(__NR_clock_adjtime, sys_clock_adjtime32, sys_clock_adjtime) +__SC(time32, clock_adjtime, sys_clock_adjtime32) +__SC(64, clock_adjtime, sys_clock_adjtime) #endif #define __NR_syncfs 267 @@ -701,7 +742,8 @@ __SYSCALL(__NR_statx, sys_statx) #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32 #define __NR_io_pgetevents 292 -__SC_COMP_3264(__NR_io_pgetevents, sys_io_pgetevents_time32, sys_io_pgetevents, compat_sys_io_pgetevents) +__SCC(time32, io_pgetevents, sys_io_pgetevents_time32, compat_sys_io_pgetevents) +__SC(64, io_pgetevents, sys_io_pgetevents) #endif #define __NR_rseq 293 @@ -713,45 +755,45 @@ __SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #if defined(__SYSCALL_COMPAT) || __BITS_PER_LONG == 32 #define __NR_clock_gettime64 403 -__SYSCALL(__NR_clock_gettime64, sys_clock_gettime) +__SC(32, clock_gettime64, sys_clock_gettime) #define __NR_clock_settime64 404 -__SYSCALL(__NR_clock_settime64, sys_clock_settime) +__SC(32, clock_settime64, sys_clock_settime) #define __NR_clock_adjtime64 405 -__SYSCALL(__NR_clock_adjtime64, sys_clock_adjtime) +__SC(32, clock_adjtime64, sys_clock_adjtime) #define __NR_clock_getres_time64 406 -__SYSCALL(__NR_clock_getres_time64, sys_clock_getres) +__SC(32, clock_getres_time64, sys_clock_getres) #define __NR_clock_nanosleep_time64 407 -__SYSCALL(__NR_clock_nanosleep_time64, sys_clock_nanosleep) +__SC(32, clock_nanosleep_time64, sys_clock_nanosleep) #define __NR_timer_gettime64 408 -__SYSCALL(__NR_timer_gettime64, sys_timer_gettime) +__SC(32, timer_gettime64, sys_timer_gettime) #define __NR_timer_settime64 409 -__SYSCALL(__NR_timer_settime64, sys_timer_settime) +__SC(32, timer_settime64, sys_timer_settime) #define __NR_timerfd_gettime64 410 -__SYSCALL(__NR_timerfd_gettime64, sys_timerfd_gettime) +__SC(32, timerfd_gettime64, sys_timerfd_gettime) #define __NR_timerfd_settime64 411 -__SYSCALL(__NR_timerfd_settime64, sys_timerfd_settime) +__SC(32, timerfd_settime64, sys_timerfd_settime) #define __NR_utimensat_time64 412 -__SYSCALL(__NR_utimensat_time64, sys_utimensat) +__SC(32, utimensat_time64, sys_utimensat) #define __NR_pselect6_time64 413 -__SC_COMP(__NR_pselect6_time64, sys_pselect6, compat_sys_pselect6_time64) +__SCC(32, pselect6_time64, sys_pselect6, compat_sys_pselect6_time64) #define __NR_ppoll_time64 414 -__SC_COMP(__NR_ppoll_time64, sys_ppoll, compat_sys_ppoll_time64) +__SCC(32, ppoll_time64, sys_ppoll, compat_sys_ppoll_time64) #define __NR_io_pgetevents_time64 416 -__SYSCALL(__NR_io_pgetevents_time64, sys_io_pgetevents, compat_sys_io_pgetevents_time64) +__SCC(32, io_pgetevents_time64, sys_io_pgetevents, compat_sys_io_pgetevents_time64) #define __NR_recvmmsg_time64 417 -__SC_COMP(__NR_recvmmsg_time64, sys_recvmmsg, compat_sys_recvmmsg_time64) +__SCC(32, recvmmsg_time64, sys_recvmmsg, compat_sys_recvmmsg_time64) #define __NR_mq_timedsend_time64 418 -__SYSCALL(__NR_mq_timedsend_time64, sys_mq_timedsend) +__SC(32, mq_timedsend_time64, sys_mq_timedsend) #define __NR_mq_timedreceive_time64 419 -__SYSCALL(__NR_mq_timedreceive_time64, sys_mq_timedreceive) +__SC(32, mq_timedreceive_time64, sys_mq_timedreceive) #define __NR_semtimedop_time64 420 -__SYSCALL(__NR_semtimedop_time64, sys_semtimedop) +__SC(32, semtimedop_time64, sys_semtimedop) #define __NR_rt_sigtimedwait_time64 421 -__SC_COMP(__NR_rt_sigtimedwait_time64, sys_rt_sigtimedwait, compat_sys_rt_sigtimedwait_time64) +__SCC(32, rt_sigtimedwait_time64, sys_rt_sigtimedwait, compat_sys_rt_sigtimedwait_time64) #define __NR_futex_time64 422 -__SYSCALL(__NR_futex_time64, sys_futex) +__SC(32, futex_time64, sys_futex) #define __NR_sched_rr_get_interval_time64 423 -__SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval) +__SC(32, sched_rr_get_interval_time64, sys_sched_rr_get_interval) #endif #define __NR_pidfd_send_signal 424 -- 2.39.2 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling 2024-06-20 16:23 ` [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling Arnd Bergmann @ 2024-06-24 12:36 ` Arnd Bergmann 0 siblings, 0 replies; 16+ messages in thread From: Arnd Bergmann @ 2024-06-24 12:36 UTC (permalink / raw) To: Arnd Bergmann, Linux-Arch, linux-kernel Cc: Thomas Bogendoerfer, linux-mips, Helge Deller, linux-parisc, David S . Miller, Andreas Larsson, sparclinux, Michael Ellerman, Nicholas Piggin, Christophe Leroy, Naveen N. Rao, linuxppc-dev, Brian Cain, linux-hexagon, guoren, linux-csky@vger.kernel.org, Heiko Carstens, linux-s390, Rich Felker, John Paul Adrian Glaubitz, linux-sh, H. Peter Anvin, Alexander Viro, Christian Brauner, linux-fsdevel, Xi Ruoyao, musl@lists.openwall.com, LTP List, stable On Thu, Jun 20, 2024, at 18:23, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > arch/riscv/ appears to have accidentally enabled the compat time32 > syscalls in 64-bit kernels even though the native 32-bit ABI does > not expose those. > > Address this by adding another level of indirection, checking for both > the target ABI (32 or 64) and the __ARCH_WANT_TIME32_SYSCALLS macro. > > The macro arguments are meant to follow the syscall.tbl format, the idea > here is that by the end of the series, all other syscalls are changed > to the same format to make it possible to move all architectures over > to generating the system call table consistently. > Only this patch needs to be backported though. > > Cc: stable@vger.kernel.org # v5.19+ > Fixes: 7eb6369d7acf ("RISC-V: Add support for rv32 userspace via COMPAT") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> I had pulled this in from my longer series, but as the kernel build bot reported, this produced build time regressions, so I'll drop it from the v6.10 fixes and will integrated it back as part of the cleanup series. Arnd ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-06-24 12:53 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240620162316.3674955-1-arnd@kernel.org>
2024-06-20 16:23 ` [PATCH 01/15] ftruncate: pass a signed offset Arnd Bergmann
2024-06-21 7:47 ` Christian Brauner
2024-06-20 16:23 ` [PATCH 02/15] syscalls: fix compat_sys_io_pgetevents_time64 usage Arnd Bergmann
2024-06-21 14:19 ` Heiko Carstens
2024-06-24 12:52 ` Arnd Bergmann
2024-06-20 16:23 ` [PATCH 09/15] sh: rework sync_file_range ABI Arnd Bergmann
2024-06-21 8:44 ` John Paul Adrian Glaubitz
2024-06-21 9:41 ` Arnd Bergmann
2024-06-24 6:14 ` John Paul Adrian Glaubitz
2024-06-24 12:49 ` Arnd Bergmann
2024-06-21 19:57 ` [musl] " Rich Felker
2024-06-20 16:23 ` [PATCH 10/15] csky, hexagon: fix broken sys_sync_file_range Arnd Bergmann
2024-06-23 17:10 ` Guo Ren
2024-06-20 16:23 ` [PATCH 11/15] hexagon: fix fadvise64_64 calling conventions Arnd Bergmann
2024-06-20 16:23 ` [PATCH 14/15] asm-generic: unistd: fix time32 compat syscall handling Arnd Bergmann
2024-06-24 12:36 ` Arnd Bergmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).