Skip to contentSkip to conversation

futex: Add compat_sys_futex_waitv for 32bit compatibility

PATCH In review Wei Gao 4 participants 8 messages Nov 23, 2023 – Dec 1, 2023

Subsystems (3)
lore
Share & tools
lore

Wei Gao

author
#0 lore raw

PATCH 1/1 futex: Add compat_sys_futex_waitv for 32bit compatibility

From: wei gao <[email protected]>

Current implementation lead LTP test case futex_waitv failed when compiled with -m32. This patch add new compat_sys_futex_waitv to handle m32 mode syscall.

The failure reason is futex_waitv in m32 mode will deliver kernel with struct old_timespec32 timeout, but this struct type can not directly used by current sys_futex_waitv implementation.

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

---
 arch/x86/entry/syscalls/syscall_32.tbl |  2 +-
 kernel/futex/syscalls.c                | 61 ++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -1
index c8fac5205803..11bd927dd417 100644
@@ -453,7 +453,7 @@
 446	i386	landlock_restrict_self	sys_landlock_restrict_self
 447	i386	memfd_secret		sys_memfd_secret
 448	i386	process_mrelease	sys_process_mrelease
-449	i386	futex_waitv		sys_futex_waitv
+449	i386	futex_waitv		sys_futex_waitv  compat_sys_futex_waitv
 450	i386	set_mempolicy_home_node		sys_set_mempolicy_home_node
 451	i386	cachestat		sys_cachestat
 452	i386	fchmodat2		sys_fchmodat2
kernel/futex/syscalls.c +61 -0

67 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

[+CC Arnd]

Hi Wei,

Em 23/11/2023 02:31, Wei Gao escreveu:

Quoted 5 lines

From: wei gao <[email protected]>

Current implementation lead LTP test case futex_waitv failed when compiled with -m32. This patch add new compat_sys_futex_waitv to handle m32 mode syscall.

Quoted 8 lines

The failure reason is futex_waitv in m32 mode will deliver kernel with struct old_timespec32 timeout, but this struct type can not directly used by current sys_futex_waitv implementation.

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

From, what I recall, we don't want to add new syscalls with old_timespec32, giving that they will have a limited lifetime. Instead, userspace should be able to come up with a 64-bit timespec implementation for -m32.

Thanks,
André

author
#2 lore raw
Quoted 19 lines · André Almeida

[+CC Arnd]

Hi Wei,

Em 23/11/2023 02:31, Wei Gao escreveu:

Quoted 5 lines

From: wei gao <[email protected]>

Current implementation lead LTP test case futex_waitv failed when compiled with -m32. This patch add new compat_sys_futex_waitv to handle m32 mode syscall.

Quoted 8 lines

The failure reason is futex_waitv in m32 mode will deliver kernel with struct old_timespec32 timeout, but this struct type can not directly used by current sys_futex_waitv implementation.

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

Quoted 6 lines

From, what I recall, we don't want to add new syscalls with old_timespec32, giving that they will have a limited lifetime. Instead, userspace should be able to come up with a 64-bit timespec implementation for -m32.

Thanks,
André

Just a comment, I have checked the glibc latest code but do not see any implemention(*.c) on futex_waitv syscall. So normally you have to do syscall directly with __NR_futex_waitv from userspace. So i guess glibc-side can not covert this struct correctly currently. Correct me if any misunderstanding.

Thanks
Wei Gao

#3 lore raw

Hi Wei,

Em 27/11/2023 09:15, Wei Gao escreveu:

Quoted 24 lines · André Almeida
Quoted 23 lines

[+CC Arnd]

Hi Wei,

Em 23/11/2023 02:31, Wei Gao escreveu:

Quoted 5 lines

From: wei gao <[email protected]>

Current implementation lead LTP test case futex_waitv failed when compiled with -m32. This patch add new compat_sys_futex_waitv to handle m32 mode syscall.

Quoted 8 lines

The failure reason is futex_waitv in m32 mode will deliver kernel with struct old_timespec32 timeout, but this struct type can not directly used by current sys_futex_waitv implementation.

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

From, what I recall, we don't want to add new syscalls with old_timespec32, giving that they will have a limited lifetime. Instead, userspace should be able to come up with a 64-bit timespec implementation for -m32.

Quoted 8 lines
Quoted 2 lines

Thanks,
André

Just a comment, I have checked the glibc latest code but do not see any implemention(*.c) on futex_waitv syscall. So normally you have to do syscall directly with __NR_futex_waitv from userspace. So i guess glibc-side can not covert this struct correctly currently. Correct me if any misunderstanding.

futex() has no syscall wrappers in glibc. Userspace needs to figure out everything by themselves, including which struct they should use, and I don't think that glibc does any conversion. If you create manually a timespec64 that works in -m32, and pass this to sycall(__NR_futex_waitv, ..., &timeout, ...), it should work correctly. You can read more about how glibc is planning to deal with this at [1]. Please let me know if now it's more clear :)

[1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Quoted 2 lines

Thanks
Wei Gao

author
#4 lore raw
Quoted 44 lines · André Almeida

Hi Wei,

Em 27/11/2023 09:15, Wei Gao escreveu:

Quoted 24 lines · André Almeida
Quoted 23 lines

[+CC Arnd]

Hi Wei,

Em 23/11/2023 02:31, Wei Gao escreveu:

Quoted 5 lines

From: wei gao <[email protected]>

Current implementation lead LTP test case futex_waitv failed when compiled with -m32. This patch add new compat_sys_futex_waitv to handle m32 mode syscall.

Quoted 8 lines

The failure reason is futex_waitv in m32 mode will deliver kernel with struct old_timespec32 timeout, but this struct type can not directly used by current sys_futex_waitv implementation.

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

From, what I recall, we don't want to add new syscalls with old_timespec32, giving that they will have a limited lifetime. Instead, userspace should be able to come up with a 64-bit timespec implementation for -m32.

Quoted 8 lines
Quoted 2 lines

Thanks,
André

Just a comment, I have checked the glibc latest code but do not see any implemention(*.c) on futex_waitv syscall. So normally you have to do syscall directly with __NR_futex_waitv from userspace. So i guess glibc-side can not covert this struct correctly currently. Correct me if any misunderstanding.

futex() has no syscall wrappers in glibc. Userspace needs to figure out everything by themselves, including which struct they should use, and I don't think that glibc does any conversion. If you create manually a timespec64 that works in -m32, and pass this to sycall(__NR_futex_waitv, ..., &timeout, ...), it should work correctly. You can read more about how glibc is planning to deal with this at [1]. Please let me know if now it's more clear :)

Quoted 1 line

[1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Thanks a lot for your detail explaination and good learning link, it's more clear to me now : )

Quoted 3 lines
Quoted 3 lines

Thanks
Wei Gao

#5 lore raw
In reply to Wei Gao
kernel test robot noticed the following build errors:

Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/asm]
[also build test ERROR on tip/locking/core linus/master v6.7-rc2 next-20231124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Gao/futex-Add-compat_sys_futex_waitv-for-32bit-compatibility/20231123-133427
base:   tip/x86/asm
patch link:    https://lore.kernel.org/r/20231123053140.16062-1-wegao%40suse.com
patch subject: [PATCH v1] futex: Add compat_sys_futex_waitv for 32bit compatibility
config: x86_64-buildonly-randconfig-005-20231123 (https://download.01.org/0day-ci/archive/20231124/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231124/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> ld: arch/x86/entry/syscall_32.o:(.rodata+0xe08): undefined reference to `__ia32_compat_sys_futex_waitv'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw
In reply to Wei Gao
Quoted 4 lines · Wei Gao

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

That's not how it works.

struct __kernel_timespec is the same on 64bit and 32bit syscalls.

User space has to use the proper type when invoking a syscall and and not just decide that it can use something arbitrary.

All new syscalls which deal with time use the Y2038 aware data types and do not have compat fallbacks because there is no requirement to have them.

If user space want's to use struct timespec on 32bit nevertheless in the programm for a new syscall, which is obviously stupid in the context of Y2038, then it's a user space problem to convert back and forth between the two data types.

Fix LTP to be Y2038 safe instead.

Thanks,

tglx

author
#7 lore raw
Quoted 17 lines · Thomas Gleixner
Quoted 4 lines · Wei Gao

The new function copy main logic of current sys_futex_waitv, just update parameter type from "struct __kernel_timespec __user *" to "struct old_timespec32 __user *," and use get_old_timespec32 within the new function to get timeout value.

That's not how it works.

struct __kernel_timespec is the same on 64bit and 32bit syscalls.

User space has to use the proper type when invoking a syscall and and not just decide that it can use something arbitrary.

All new syscalls which deal with time use the Y2038 aware data types and do not have compat fallbacks because there is no requirement to have them.

Quoted 6 lines

If user space want's to use struct timespec on 32bit nevertheless in the programm for a new syscall, which is obviously stupid in the context of Y2038, then it's a user space problem to convert back and forth between the two data types.

Fix LTP to be Y2038 safe instead.

Thanks a lot for your suggestion, will check it.

Quoted 4 lines

Thanks,

tglx