fix incorrect target ioctl numbers
cover fix incorrect target ioctl numbers
Some of our TARGET_* constant definitions for ioctls were wrong because the ioctl number is based on the sizeof() the type passed to the TARGET_IO* macros, and we were passing a host type rather than a target type. This was originally reported as a bug where the FS_IOC_{GET,SET}FLAGS ioctls weren't working for 32-bit arm guests on x86-64 hosts.
I did a quick audit of all the uses of the TARGET_IO* macros in syscall_defs.h, and:
* FS_IOC_GETFLAGS/SETFLAGS are indeed wrong
* 3 ioctls to do with magtapes are also wrong
* TARGET_FS_IOC_FIEMAP, TARGET_FICLONERANGE and TARGET_SOUND_MIXER_INFO take a host struct which is defined such that it's the same size for all archs
* lots and lots of ioctls use 'int', which is OK as for us 'abi_int' is always 32 bits (it might have different alignment requirements, but they don't matter for this purpose)
* TARGET_SIOCPGRP takes a pid_t, which is always 'int'
This patchset fixes the bugs in the first two bullet points, and leaves everything else alone since it doesn't actually manifest as wrong behaviour.
Patch 1 is tested by the LTP 'setxattrs3' test case. There's no LTP test case for the magtape ioctls, so that patch change is untested.
Peter Maydell (2):
linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers
linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
linux-user/syscall_defs.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers
We were defining TARGET_FS_IOC_GETFLAGS and TARGET_FS_IOC_SETFLAGS using the host 'long' type in the size field, which meant that they had the wrong values if the host and guest had different sized longs. Switch to abi_long instead.
This fixes a bug where these ioctls don't work on 32-bit guests on 64-bit hosts (and makes the LTP test 'setxattr03' pass where it did not previously.)
--- linux-user/syscall_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall_defs.h +2 -2
@@ -1101,8 +1101,8 @@ struct target_pollfd {/* Note that the ioctl numbers claim type "long" but the actual type * used by the kernel is "int". */ -#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, long) -#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, long) +#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long) +#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)#define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/2] linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers
Le 12/10/2017 à 17:30, Peter Maydell a écrit :
Quoted 21 lines
We were defining
TARGET_FS_IOC_GETFLAGSandTARGET_FS_IOC_SETFLAGSusing the host 'long' type in the size field, which meant that they had the wrong values if the host and guest had different sized longs. Switch toabi_longinstead.This fixes a bug where these ioctls don't work on 32-bit guests on 64-bit hosts (and makes the LTP test 'setxattr03' pass where it did not previously.)
Reported-by pgndev <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- linux-user/syscall_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)linux-user/syscall_defs.h +0
-0
linux-user/syscall_defs.h struct target_pollfd { · line 1108
Quoted 10 lines
linux-user/syscall_defs.h +2
-2@@ -1101,8 +1101,8 @@ struct target_pollfd {/* Note that the ioctl numbers claim type "long" but the actual type * used by the kernel is "int". */ -#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, long) -#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, long) +#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long) +#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)#define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
Riku Voipio
AppliedRe: [Qemu-devel] [PATCH 1/2] linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers
In reply to Peter MaydellQuoted 8 lines · Peter Maydell
We were defining
TARGET_FS_IOC_GETFLAGSandTARGET_FS_IOC_SETFLAGSusing the host 'long' type in the size field, which meant that they had the wrong values if the host and guest had different sized longs. Switch toabi_longinstead.This fixes a bug where these ioctls don't work on 32-bit guests on 64-bit hosts (and makes the LTP test 'setxattr03' pass where it did not previously.)
Applied to linux-user, thanks
Quoted 24 lines
Reported-by pgndev <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- linux-user/syscall_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)linux-user/syscall_defs.h +2
-2@@ -1101,8 +1101,8 @@ struct target_pollfd {/* Note that the ioctl numbers claim type "long" but the actual type * used by the kernel is "int". */ -#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, long) -#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, long) +#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long) +#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)#define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)Signature · 1 line
2.7.4
PATCH 2/2 linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
In reply to Peter MaydellThe TARGET_MTIOCTOP/TARGET_MTIOCGET/TARGET_MTIOCPOS values were being defined in terms of host struct types, but these structures are such that their size might differ on different hosts. Switch to using a target struct definition instead.
--- linux-user/syscall_defs.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
linux-user/syscall_defs.h +28 -3
@@ -2706,9 +2706,34 @@ struct target_f_owner_ex {#define TARGET_VFAT_IOCTL_READDIR_BOTH TARGET_IORU('r', 1)#define TARGET_VFAT_IOCTL_READDIR_SHORT TARGET_IORU('r', 2) -#define TARGET_MTIOCTOP TARGET_IOW('m', 1, struct mtop) -#define TARGET_MTIOCGET TARGET_IOR('m', 2, struct mtget) -#define TARGET_MTIOCPOS TARGET_IOR('m', 3, struct mtpos) +struct target_mtop { +abi_short mt_op; +abi_int mt_count; +}; + +#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif + +struct target_mtget { +abi_long mt_type; +abi_long mt_resid; +abi_long mt_dsreg; +abi_long mt_gstat; +abi_long mt_erreg; +target_kernel_daddr_t mt_fileno; +target_kernel_daddr_t mt_blkno; +}; + +struct target_mtpos { +abi_long mt_blkno; +}; + +#define TARGET_MTIOCTOP TARGET_IOW('m', 1, struct target_mtop) +#define TARGET_MTIOCGET TARGET_IOR('m', 2, struct target_mtget) +#define TARGET_MTIOCPOS TARGET_IOR('m', 3, struct target_mtpos)struct target_sysinfo {abi_long uptime;/* Seconds since boot */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Le 12/10/2017 à 17:30, Peter Maydell a écrit :
Quoted 22 lines
The TARGET_MTIOCTOP/TARGET_MTIOCGET/TARGET_MTIOCPOS values were being defined in terms of host struct types, but these structures are such that their size might differ on different hosts. Switch to using a target struct definition instead.
Signed-off-by Peter Maydell <[email protected]>--- linux-user/syscall_defs.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)linux-user/syscall_defs.h +0
-3@@ -2706,9 +2706,34 @@ struct target_f_owner_ex {#define TARGET_VFAT_IOCTL_READDIR_BOTH TARGET_IORU('r', 1)#define TARGET_VFAT_IOCTL_READDIR_SHORT TARGET_IORU('r', 2) -#define TARGET_MTIOCTOP TARGET_IOW('m', 1, struct mtop) -#define TARGET_MTIOCGET TARGET_IOR('m', 2, struct mtget) -#define TARGET_MTIOCPOS TARGET_IOR('m', 3, struct mtpos)
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2718
Quoted 10 lines
linux-user/syscall_defs.h +10
-0+struct target_mtop { +abi_short mt_op; +abi_int mt_count; +}; + +#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif
Perhaps you can add these ones into include/exec/user/abitypes.h ?
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2728
Quoted 9 lines
linux-user/syscall_defs.h +9
-0+struct target_mtget { +abi_long mt_type; +abi_long mt_resid; +abi_long mt_dsreg; +abi_long mt_gstat; +abi_long mt_erreg; +target_kernel_daddr_t mt_fileno; +target_kernel_daddr_t mt_blkno; +};
I think you need to update STRUCT(mtget, ...) in linux-user/syscall_types.h to reflect the size difference for MIPS and SPARC.
Thanks,
Laurent
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Quoted 8 lines · Laurent Vivier
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2718
Quoted 5 lines · Peter Maydell
linux-user/syscall_defs.h +5
-0+#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif Perhaps you can add these ones into
include/exec/user/abitypes.h?
I don't think they belong there -- that file is for basic CPU ABI dependent types, not things which are just part of the kernel interface.
Quoted 5 lines
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+struct target_mtget { +abi_long mt_type; +abi_long mt_resid; +abi_long mt_dsreg; +abi_long mt_gstat;
Quoted 8 lines
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2728
Quoted 4 lines
linux-user/syscall_defs.h +4
-0+abi_long mt_erreg; +target_kernel_daddr_t mt_fileno; +target_kernel_daddr_t mt_blkno; +};I think you need to update
STRUCT(mtget, ...)inlinux-user/syscall_types.hto reflect the size difference for MIPS and SPARC.
I thought about that but I wasn't feeling too enthusiastic due to not having a test case... I suppose it's better to change them both though.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Le 12/10/2017 à 18:53, Peter Maydell a écrit :
Quoted 10 lines · Laurent Vivier
Quoted 8 lines · Peter Maydell
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2718
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif Perhaps you can add these ones into
include/exec/user/abitypes.h?
Quoted 3 lines
I don't think they belong there -- that file is for basic CPU ABI dependent types, not things which are just part of the kernel interface.
I agree
Laurent
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Quoted 11 lines · Laurent Vivier
Le 12/10/2017 à 18:53, Peter Maydell a écrit :
Quoted 10 lines · Laurent Vivier
Quoted 8 lines · Peter Maydell
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2718
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif Perhaps you can add these ones into
include/exec/user/abitypes.h?
Quoted 5 lines
Quoted 3 lines
I don't think they belong there -- that file is for basic CPU ABI dependent types, not things which are just part of the kernel interface.
I agree
So we should go with the patch as-is?
Riku
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Le 16/10/2017 à 15:06, Riku Voipio a écrit :
Quoted 12 lines · Laurent Vivier
Quoted 11 lines
Le 12/10/2017 à 18:53, Peter Maydell a écrit :
Quoted 10 lines · Laurent Vivier
Quoted 8 lines · Peter Maydell
linux-user/syscall_defs.h struct target_f_owner_ex { · line 2718
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+#if defined(TARGET_SPARC ) || defined(TARGET_MIPS ) +typedef abi_long target_kernel_daddr_t ; +#else +typedef abi_int target_kernel_daddr_t ; +#endif Perhaps you can add these ones into
include/exec/user/abitypes.h?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I don't think they belong there -- that file is for basic CPU ABI dependent types, not things which are just part of the kernel interface.
I agree
So we should go with the patch as-is?
For this part, yes, but I think for the other comment, STRUCT(mtget, ...) needs to be updated.
Thanks,
Laurent
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Quoted 2 lines · Laurent Vivier
For this part, yes, but I think for the other comment,
STRUCT(mtget, ...)needs to be updated.
Looking more closely I don't think it is as simple as just adjusting the STRUCT() definition. For a basic type that can be different on host and guest, I think we'd need to handle it the way we do the TYPE_OLDDEVT, with special support in the thunk code for figuring out how large it is and so on. That seems like a lot of work for a magtape ioctl that I suspect nobody's using and which we can't test...
Applying this patch as-is would at least fix the ioctl for everything except MIPS and SPARC hosts and guests.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values
Le 16/10/2017 à 15:26, Peter Maydell a écrit :
Quoted 11 lines · Laurent Vivier
Quoted 2 lines
For this part, yes, but I think for the other comment,
STRUCT(mtget, ...)needs to be updated.Looking more closely I don't think it is as simple as just adjusting the
STRUCT()definition. For a basic type that can be different on host and guest, I think we'd need to handle it the way we do theTYPE_OLDDEVT, with special support in the thunk code for figuring out how large it is and so on. That seems like a lot of work for a magtape ioctl that I suspect nobody's using and which we can't test...
I agree.
Quoted 2 lines
Applying this patch as-is would at least fix the ioctl for everything except MIPS and SPARC hosts and guests.
Yes, so I think it can be applied as-is.
Thanks,
Laurent