y2038: Fixes for compat mode
cover y2038: Fixes for compat mode
I started testing the compat mode on a Ubuntu based system with glibc 2.34 which supports switching to 64 bit based time_t. These are the fixes for problems observed while testing the kernel / cobalt part.
More tests, especially for the libcobalt part will be necessary, especially because the way how glibc implemented the switch to 64 bit time_t affects the function wrapping we use.
Best regards,
Florian
Florian Bezdeka (3):
y2038: posix/mqueue: Fix compat case for mq_timedreceive64
y2038: cobalt: rtdm/fd: Take care of compat mode for recvmmsg64
y2038: cobalt: posix/signal: Take care of compat mode for
sigtimedwait64
.../x86/include/asm/xenomai/syscall32-table.h | 3 +++ kernel/cobalt/posix/mqueue.c | 26 +++++++++---------- kernel/cobalt/posix/mqueue.h | 2 +- kernel/cobalt/posix/syscall32.c | 17 ++++++++++-- kernel/cobalt/posix/syscall32.h | 3 ++- 5 files changed, 34 insertions(+), 17 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/3 y2038: posix/mqueue: Fix compat case for mq_timedreceive64
There is a pointer to ssize_t part of the ABI. The pointer itself is autocorrected by the syscall enter machinery, but when reading/writing we have to care about different sizes between compat and native case.
--- .../x86/include/asm/xenomai/syscall32-table.h | 1 + kernel/cobalt/posix/mqueue.c | 26 +++++++++---------- kernel/cobalt/posix/mqueue.h | 2 +- kernel/cobalt/posix/syscall32.c | 17 ++++++++++-- kernel/cobalt/posix/syscall32.h | 3 ++- 5 files changed, 32 insertions(+), 17 deletions(-)
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1 -0
@@ -63,5 +63,6 @@ __COBALT_CALL32emu_THUNK(recvmsg) __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) +__COBALT_CALL32emu_THUNK(mq_timedreceive64)#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */
kernel/cobalt/posix/mqueue.c +13 -13
@@ -1048,21 +1048,12 @@ fail: }int __cobalt_mq_timedreceive64 (mqd_t uqd,void __user *u_buf, -ssize_t __user *u_len, +ssize_t *len,unsigned int __user *u_prio,const void __user *u_ts) { -ssize_t len; -int ret; - - ret =cobalt_copy_from_user (&len, u_len,sizeof (len)); -if (ret) -return ret; - - ret =__cobalt_mq_timedreceive (uqd, u_buf, &len, u_prio, u_ts, - u_ts ? mq_fetch_timeout64 :NULL ); - -return ret ?:cobalt_copy_to_user (u_len, &len,sizeof (*u_len)); +return __cobalt_mq_timedreceive (uqd, u_buf, len, u_prio, u_ts, + u_ts ? mq_fetch_timeout64 :NULL ); } COBALT_SYSCALL(mq_timedreceive, primary,
@@ -1089,5 +1080,14 @@ COBALT_SYSCALL(mq_timedreceive64, primary,unsigned int __user *u_prio, const struct __kernel_timespec __user *u_ts)) { - return __cobalt_mq_timedreceive64(uqd, u_buf, u_len, u_prio, u_ts); + ssize_t len; +int ret; + + ret =cobalt_copy_from_user (&len, u_len,sizeof (len)); +if (ret) +return ret; + + ret =__cobalt_mq_timedreceive64 (uqd, u_buf, &len, u_prio, u_ts); + +return ret ?:cobalt_copy_to_user (u_len, &len,sizeof (*u_len)); }
kernel/cobalt/posix/mqueue.h +1 -1
@@ -51,7 +51,7 @@ int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf, const void __user *u_ts));int __cobalt_mq_timedreceive64 (mqd_t uqd,void __user *u_buf, -ssize_t __user *u_len, +ssize_t *len,unsigned int __user *u_prio,const void __user *u_ts);
kernel/cobalt/posix/syscall32.c +15 -2
@@ -367,11 +367,24 @@ COBALT_SYSCALL32emu(mq_timedreceive, primary, }COBALT_SYSCALL32emu (mq_timedreceive64, primary, - (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len, + (mqd_t uqd, void __user *u_buf, + compat_ssize_t__user *u_len, unsigned int __user *u_prio, const struct __kernel_timespec __user *u_ts)) { -return __cobalt_mq_timedreceive64 (uqd, u_buf, u_len, u_prio, u_ts); +compat_ssize_t clen; +ssize_t len; +int ret; + + ret =cobalt_copy_from_user (&clen, u_len,sizeof (*u_len)); +if (ret) +return ret; + + len = clen; + ret =__cobalt_mq_timedreceive64 (uqd, u_buf, &len, u_prio, u_ts); + clen = len; + +return ret ?:cobalt_copy_to_user (u_len, &clen,sizeof (*u_len)); } static inline int mq_fetch_timeout(struct timespec64 *ts,
kernel/cobalt/posix/syscall32.h +2 -1
@@ -140,7 +140,8 @@ COBALT_SYSCALL32emu_DECL(mq_timedreceive, const struct old_timespec32 __user *u_ts));COBALT_SYSCALL32emu_DECL (mq_timedreceive64, - (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len, + (mqd_t uqd, void __user *u_buf, + compat_ssize_t__user *u_len, unsigned int __user *u_prio, const struct __kernel_timespec __user *u_ts));
Signature · 1 line
2.35.1
PATCH 2/3 y2038: cobalt: rtdm/fd: Take care of compat mode for recvmmsg64
In reply to Florian BezdekaThe compat syscall was previously routed to the native entrypoint which triggered a failure during mmsghdr validation.
--- kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h | 1 + 1 file changed, 1 insertion(+)
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1 -0
@@ -64,5 +64,6 @@ __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) __COBALT_CALL32emu_THUNK(mq_timedreceive64) +__COBALT_CALL32emu_THUNK(recvmmsg64)#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */
Signature · 1 line
2.35.1
PATCH 3/3 y2038: cobalt: posix/signal: Take care of compat mode for sigtimedwait64
In reply to Florian BezdekaThe compat syscall was previously routed to the native entrypoint. While the timeout is always based on time64_t the siginfo has to be handled different in compat mode.
--- kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h | 1 + 1 file changed, 1 insertion(+)
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1 -0
@@ -64,6 +64,7 @@ __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) __COBALT_CALL32emu_THUNK(mq_timedreceive64) +__COBALT_CALL32emu_THUNK(sigtimedwait64) __COBALT_CALL32emu_THUNK(recvmmsg64)#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */
Signature · 1 line
2.35.1
Re: [PATCH 3/3] y2038: cobalt: posix/signal: Take care of compat mode for sigtimedwait64
Quoted 14 lines · Florian Bezdeka
The compat syscall was previously routed to the native entrypoint. While the timeout is always based on
time64_tthe siginfo has to be handled different in compat mode.Signed-off-by Florian Bezdeka <[email protected]>--- kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h | 1 + 1 file changed, 1 insertion(+)kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +0
-0
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h __COBALT_CALL32emu_THUNK(sendmsg) · line 70
Quoted 7 lines
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1
-0@@ -64,6 +64,7 @@ __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) __COBALT_CALL32emu_THUNK(mq_timedreceive64) +__COBALT_CALL32emu_THUNK(sigtimedwait64) __COBALT_CALL32emu_THUNK(recvmmsg64)#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */
There are way more new 64-bit calls. Matching their original versions against this header, I would say we need more thunks, no?
for time64func in $(git grep 64, kernel/cobalt/posix/syscall32.c | \
sed 's/.*(\([^6]*\)64,.*/\1/'); do
git grep -q $time64func \
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h && \
echo $time64func; donesem_timedwaitclock_getresclock_gettimeclock_settimeclock_nanosleepmutex_timedlockcond_wait_prologuemq_timedsendmq_timedreceive
sigtimedwaitmonitor_waitevent_wait
recvmmsg
We now have mq_timedreceive64, sigtimedwait64 and recvmmsg64 with thunks. There rest is missing, no?
Interestingly, we also have no thunk for old recvmmsg so far. Probably a bug of it own.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH 3/3] y2038: cobalt: posix/signal: Take care of compat mode for sigtimedwait64
Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Florian Bezdeka
The compat syscall was previously routed to the native entrypoint. While the timeout is always based on
time64_tthe siginfo has to be handled different in compat mode.Signed-off-by Florian Bezdeka <[email protected]>--- kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h | 1 + 1 file changed, 1 insertion(+)kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1
-0@@ -64,6 +64,7 @@ __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) __COBALT_CALL32emu_THUNK(mq_timedreceive64) +__COBALT_CALL32emu_THUNK(sigtimedwait64) __COBALT_CALL32emu_THUNK(recvmmsg64)
Quoted 4 lines
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h __COBALT_CALL32emu_THUNK(sendmsg) · line 70
Quoted 1 line
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +0
-0#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */ There are way more new 64-bit calls. Matching their original versions against this header, I would say we need more thunks, no?
They are necessary only if there is special handling for compat mode needed. Most of the y2038 related syscalls do not need special handling in compat mode as "struct timespec" is now the same in both worlds.
I have some cleanup patches pending, which actually will reduce the number of compat stubs. See [1]. It seems I overlooked some header magic adding the compat syscalls into the syscall table at a fixed offset. So we do not have to care "manually".
[1] https://gitlab.com/Xenomai/xenomai-hacker-space/-/commits/florian/y2038
Quoted 29 lines
for time64func in $(git grep 64,
kernel/cobalt/posix/syscall32.c| \
sed 's/.*(\([^6]*\)64,.*/\1/'); dogit grep -q $time64func \ kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h && \ echo $time64func; done
sem_timedwaitclock_getresclock_gettimeclock_settimeclock_nanosleepmutex_timedlockcond_wait_prologuemq_timedsendmq_timedreceive
sigtimedwaitmonitor_waitevent_wait
recvmmsgWe now have
mq_timedreceive64, sigtimedwait64 and recvmmsg64 with thunks. There rest is missing, no?Interestingly, we also have no thunk for old recvmmsg so far. Probably a bug of it own.
Jan
Re: [PATCH 3/3] y2038: cobalt: posix/signal: Take care of compat mode for sigtimedwait64
Quoted 32 lines · Florian Bezdeka
Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Florian Bezdeka
The compat syscall was previously routed to the native entrypoint. While the timeout is always based on
time64_tthe siginfo has to be handled different in compat mode.Signed-off-by Florian Bezdeka <[email protected]>--- kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h | 1 + 1 file changed, 1 insertion(+)kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +1
-0@@ -64,6 +64,7 @@ __COBALT_CALL32emu_THUNK(sendmsg) __COBALT_CALL32emu_THUNK(mmap) __COBALT_CALL32emu_THUNK(backtrace) __COBALT_CALL32emu_THUNK(mq_timedreceive64) +__COBALT_CALL32emu_THUNK(sigtimedwait64) __COBALT_CALL32emu_THUNK(recvmmsg64)Quoted 4 lines
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h __COBALT_CALL32emu_THUNK(sendmsg) · line 70
Quoted 1 line
kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h +0
-0#endif /* !_COBALT_X86_ASM_SYSCALL32_TABLE_H */ There are way more new 64-bit calls. Matching their original versions against this header, I would say we need more thunks, no?
They are necessary only if there is special handling for compat mode needed. Most of the y2038 related syscalls do not need special handling in compat mode as "struct timespec" is now the same in both worlds.
Quoted 7 lines
I have some cleanup patches pending, which actually will reduce the number of compat stubs. See [1]. It seems I overlooked some header magic adding the compat syscalls into the syscall table at a fixed offset. So we do not have to care "manually".
[1] https://gitlab.com/Xenomai/xenomai-hacker-space/-/commits/florian/y2038
OK, but...
Quoted 21 lines
Quoted 21 lines
for time64func in $(git grep 64,
kernel/cobalt/posix/syscall32.c| \
sed 's/.*(\([^6]*\)64,.*/\1/'); dogit grep -q $time64func \ kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h && \ echo $time64func; done
sem_timedwaitclock_getresclock_gettimeclock_settimeclock_nanosleepmutex_timedlockcond_wait_prologuemq_timedsendmq_timedreceive
sigtimedwaitmonitor_waitevent_wait
recvmmsg
Quoted 6 lines
Quoted 6 lines
We now have
mq_timedreceive64, sigtimedwait64 and recvmmsg64 with thunks. There rest is missing, no?Interestingly, we also have no thunk for old recvmmsg so far. Probably a bug of it own.
...after your cleanups, we should look at this list again. If there is a compat function, don't there need to be thunk as well?
In the end, we urgently need testing, not only for the new time64 code paths.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 17 lines · Florian Bezdeka
I started testing the compat mode on a Ubuntu based system with glibc 2.34 which supports switching to 64 bit based
time_t. These are the fixes for problems observed while testing the kernel / cobalt part.More tests, especially for the libcobalt part will be necessary, especially because the way how glibc implemented the switch to 64 bit
time_taffects the function wrapping we use.Best regards,
FlorianFlorian Bezdeka (3):
y2038: posix/mqueue: Fix compat case formq_timedreceive64
y2038: cobalt: rtdm/fd: Take care of compat mode for recvmmsg64
y2038: cobalt: posix/signal: Take care of compat mode for
sigtimedwait64
Quoted 7 lines
.../x86/include/asm/xenomai/syscall32-table.h | 3 +++ kernel/cobalt/posix/mqueue.c | 26 +++++++++---------- kernel/cobalt/posix/mqueue.h | 2 +- kernel/cobalt/posix/syscall32.c | 17 ++++++++++-- kernel/cobalt/posix/syscall32.h | 3 ++- 5 files changed, 34 insertions(+), 17 deletions(-)
Applied all, but we likely need more thunks, see comment on patch 3
Thanks,
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux