linux-user: fix target_to_host_timespec64()
PATCH 1/1 linux-user: fix target_to_host_timespec64()
in 32 bit mode, drop the padding in tv_nsec. If host is 64bit and target is 32bit, the padding bytes will be copied from the target and as the kernel checks the value, the syscall exits with EINVAL.
Signed-off-by Laurent Vivier <[email protected]>
--- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+)
linux-user/syscall.c +2 -0
@@ -1253,6 +1253,8 @@ static inline abi_long target_to_host_timespec64(struct timespec *host_ts, }__get_user (host_ts->tv_sec, &target_ts->tv_sec);__get_user (host_ts->tv_nsec, &target_ts->tv_nsec); +/* in 32bit mode, this drops the padding */ + host_ts->tv_nsec = (long )(abi_long )host_ts->tv_nsec;unlock_user_struct (target_ts, target_addr,0 );return 0 ; }
Signature · 1 line
2.26.2
Quoted 14 lines · Laurent Vivier
in 32 bit mode, drop the padding in
tv_nsec. If host is 64bit and target is 32bit, the padding bytes will be copied from the target and as the kernel checks the value, the syscall exits with EINVAL.Signed-off-by Laurent Vivier <[email protected]>--- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+)linux-user/syscall.c +0
-0
linux-user/syscall.c static inline abi_long target_to_host_timespec64(struct timespec *host_ts, · line 1257
Quoted 5 lines
linux-user/syscall.c +2
-0@@ -1253,6 +1253,8 @@ static inline abi_long target_to_host_timespec64(struct timespec *host_ts, }__get_user (host_ts->tv_sec, &target_ts->tv_sec);__get_user (host_ts->tv_nsec, &target_ts->tv_nsec); +/* in 32bit mode, this drops the padding */ + host_ts->tv_nsec = (long )(abi_long )host_ts->tv_nsec;
I tested this with sh4 and the nsec conversion seems to be working fine now.
Just curious, why a double cast is needed '(long)(abi_long)', why not just '(abi_long)'?
Quoted 3 lines
linux-user/syscall.c +0
-0unlock_user_struct (target_ts, target_addr,0 );return 0 ; }