linux-user: fix incorrect msg_l[sr]pid members of target_msqid_ds
PATCH 1/1 linux-user: fix incorrect msg_l[sr]pid members of target_msqid_ds
The members are declared as __kernel_pid_t in Linux UAPI headers. Analogous members in struct target_shmid_ds (shm_[cl]pid) are also declared as abi_int.
--- linux-user/syscall.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
linux-user/syscall.c +6 -6
@@ -4234,8 +4234,8 @@ struct target_msqid_dsabi_ulong __msg_cbytes;abi_ulong msg_qnum;abi_ulong msg_qbytes; -abi_ulong msg_lspid; -abi_ulong msg_lrpid; +abi_int msg_lspid; +abi_int msg_lrpid;abi_ulong __unused4;abi_ulong __unused5; };
@@ -4255,8 +4255,8 @@ static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, host_md->__msg_cbytes =tswapal (target_md->__msg_cbytes); host_md->msg_qnum =tswapal (target_md->msg_qnum); host_md->msg_qbytes =tswapal (target_md->msg_qbytes); - host_md->msg_lspid =tswapal (target_md->msg_lspid); - host_md->msg_lrpid =tswapal (target_md->msg_lrpid); + host_md->msg_lspid =tswap32 (target_md->msg_lspid); + host_md->msg_lrpid =tswap32 (target_md->msg_lrpid);unlock_user_struct (target_md, target_addr,0 );return 0 ; }
@@ -4276,8 +4276,8 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, target_md->__msg_cbytes =tswapal (host_md->__msg_cbytes); target_md->msg_qnum =tswapal (host_md->msg_qnum); target_md->msg_qbytes =tswapal (host_md->msg_qbytes); - target_md->msg_lspid =tswapal (host_md->msg_lspid); - target_md->msg_lrpid =tswapal (host_md->msg_lrpid); + target_md->msg_lspid =tswap32 (host_md->msg_lspid); + target_md->msg_lrpid =tswap32 (host_md->msg_lrpid);unlock_user_struct (target_md, target_addr,1 );return 0 ; }
Signature · 1 line
2.54.0
Quoted 37 lines · On 7/24/2026 9:01 AM, no92 via qemu development wrote:
The members are declared as
__kernel_pid_tin Linux UAPI headers. Analogous members in structtarget_shmid_ds(shm_[cl]pid) are also declared asabi_int.Fixes 1c54ff97bbde ("linux-user: fix and cleanup IPCOP_msg* ipc calls handling")Signed-off-by no92 <[email protected]>--- linux-user/syscall.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)linux-user/syscall.c +4
-4@@ -4234,8 +4234,8 @@ struct target_msqid_dsabi_ulong __msg_cbytes;abi_ulong msg_qnum;abi_ulong msg_qbytes; -abi_ulong msg_lspid; -abi_ulong msg_lrpid; +abi_int msg_lspid; +abi_int msg_lrpid;abi_ulong __unused4;abi_ulong __unused5; };@@ -4255,8 +4255,8 @@ static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, host_md->__msg_cbytes =tswapal (target_md->__msg_cbytes); host_md->msg_qnum =tswapal (target_md->msg_qnum); host_md->msg_qbytes =tswapal (target_md->msg_qbytes); - host_md->msg_lspid =tswapal (target_md->msg_lspid); - host_md->msg_lrpid =tswapal (target_md->msg_lrpid); + host_md->msg_lspid =tswap32 (target_md->msg_lspid); + host_md->msg_lrpid =tswap32 (target_md->msg_lrpid);unlock_user_struct (target_md, target_addr,0 );return 0 ; }
linux-user/syscall.c static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, · line 4283
Quoted 10 lines
linux-user/syscall.c +2
-2@@ -4276,8 +4276,8 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, target_md->__msg_cbytes =tswapal (host_md->__msg_cbytes); target_md->msg_qnum =tswapal (host_md->msg_qnum); target_md->msg_qbytes =tswapal (host_md->msg_qbytes); - target_md->msg_lspid =tswapal (host_md->msg_lspid); - target_md->msg_lrpid =tswapal (host_md->msg_lrpid); + target_md->msg_lspid =tswap32 (host_md->msg_lspid); + target_md->msg_lrpid =tswap32 (host_md->msg_lrpid);unlock_user_struct (target_md, target_addr,1 );return 0 ; }
The change looks correct in itself.
Did it expose a bug, or did you found this reviewing original commit?
Regards,
Pierrick
Hi,
Quoted 2 lines
The change looks correct in itself.
Did it expose a bug, or did you found this reviewing original commit?
I noticed this when the 'msg_lrpid' member was unexpectedly zero after a msgctl(IPC_STAT) call, and printing the 'struct msqid_ds' in question with gdb revealed that the expected value was not in 'msg_lrpid', but the unused member located right after. The 'Fixes' line is based purely on running git blame.
Cheers,
Leo
Pierrick Bouvier
Reviewed-byQuoted 4 lines · Leo via qemu development
Hi,
Quoted 2 lines
The change looks correct in itself.
Did it expose a bug, or did you found this reviewing original commit?
Quoted 9 lines
I noticed this when the '
msg_lrpid' member was unexpectedly zero after amsgctl(IPC_STAT)call, and printing the 'structmsqid_ds' in question with gdb revealed that the expected value was not in 'msg_lrpid', but the unused member located right after. The 'Fixes' line is based purely on running git blame.Cheers,
Leo
Regards,
Pierrick
Quoted 25 lines · Pierrick Bouvier
Quoted 22 lines · On 7/24/2026 9:01 AM, no92 via qemu development wrote:
The members are declared as
__kernel_pid_tin Linux UAPI headers. Analogous members in structtarget_shmid_ds(shm_[cl]pid) are also declared asabi_int.Fixes 1c54ff97bbde ("linux-user: fix and cleanup IPCOP_msg* ipc calls handling")Signed-off-by no92 <[email protected]>--- linux-user/syscall.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)linux-user/syscall.c +2
-2@@ -4234,8 +4234,8 @@ struct target_msqid_dsabi_ulong __msg_cbytes;abi_ulong msg_qnum;abi_ulong msg_qbytes; -abi_ulong msg_lspid; -abi_ulong msg_lrpid; +abi_int msg_lspid; +abi_int msg_lrpid;...
Quoted 1 line
The change looks correct in itself.
No.abi_ulong is wrong, but abi_int isn't much better either if you look at the kernel sources:
grep -r __kernel_ipc_pid_t arch/
arch/sparc/include/uapi/asm/posix_types.h:typedef unsigned short __kernel_ipc_pid_t;
arch/sparc/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t arch/m68k/include/uapi/asm/posix_types.h:typedef unsigned short __kernel_ipc_pid_t; arch/m68k/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/parisc/include/uapi/asm/posix_types.h:typedef unsigned short __kernel_ipc_pid_t;
arch/parisc/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/arm/include/uapi/asm/posix_types.h:typedef unsigned short __kernel_ipc_pid_t;
arch/arm/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/s390/include/uapi/asm/posix_types.h:typedef int __kernel_ipc_pid_t;
arch/s390/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/xtensa/include/uapi/asm/posix_types.h:typedef unsigned short __kernel_ipc_pid_t;
arch/xtensa/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/x86/include/uapi/asm/posix_types_32.h:typedef unsigned short __kernel_ipc_pid_t;
arch/x86/include/uapi/asm/posix_types_32.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/sh/include/uapi/asm/posix_types_32.h:typedef unsigned short __kernel_ipc_pid_t;
arch/sh/include/uapi/asm/posix_types_32.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
arch/powerpc/include/uapi/asm/posix_types.h:typedef short __kernel_ipc_pid_t;
arch/powerpc/include/uapi/asm/posix_types.h:#define __kernel_ipc_pid_t __kernel_ipc_pid_t
So, we probably need to differntiate between platforms and use either abi_int or abi_short.
Helge
Quoted 27 lines · Helge Deller
Quoted 26 lines · Pierrick Bouvier
Quoted 23 lines · On 7/24/2026 9:01 AM, no92 via qemu development wrote:
The members are declared as
__kernel_pid_tin Linux UAPI headers. Analogous members in structtarget_shmid_ds(shm_[cl]pid) are also declared asabi_int.Fixes 1c54ff97bbde ("linux-user: fix and cleanup IPCOP_msg* ipccalls handling")
Signed-off-by no92 <[email protected]>---
linux-user/syscall.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)linux-user/syscall.c +2
-2@@ -4234,8 +4234,8 @@ struct target_msqid_ds abi_ulong __msg_cbytes; abi_ulong msg_qnum; abi_ulong msg_qbytes; - abi_ulong msg_lspid; - abi_ulong msg_lrpid; + abi_int msg_lspid; + abi_int msg_lrpid;...
Quoted 6 lines
Quoted 1 line
The change looks correct in itself.
No.
abi_ulongis wrong, butabi_intisn't much better either if you look at the kernel sources:
I wrongly assumed the definition we had on bsd-user side was correct, but didn't really think about checking it in linux sources, sorry.
Quoted 43 lines
grep -r
__kernel_ipc_pid_tarch/arch/sparc/include/uapi/asm/posix_types.h:typedef unsigned short
__kernel_ipc_pid_t; arch/sparc/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/m68k/include/uapi/asm/posix_types.h:typedef unsigned short__kernel_ipc_pid_t; arch/m68k/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/parisc/include/uapi/asm/posix_types.h:typedef unsigned short__kernel_ipc_pid_t; arch/parisc/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/arm/include/uapi/asm/posix_types.h:typedef unsigned short__kernel_ipc_pid_t; arch/arm/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/s390/include/uapi/asm/posix_types.h:typedef int__kernel_ipc_pid_t; arch/s390/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/xtensa/include/uapi/asm/posix_types.h:typedef unsigned short__kernel_ipc_pid_t; arch/xtensa/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/x86/include/uapi/asm/posix_types_32.h:typedef unsigned short__kernel_ipc_pid_t; arch/x86/include/uapi/asm/posix_types_32.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/sh/include/uapi/asm/posix_types_32.h:typedef unsigned short__kernel_ipc_pid_t; arch/sh/include/uapi/asm/posix_types_32.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tarch/powerpc/include/uapi/asm/posix_types.h:typedef short__kernel_ipc_pid_t; arch/powerpc/include/uapi/asm/posix_types.h:#define__kernel_ipc_pid_t__kernel_ipc_pid_tSo, we probably need to differntiate between platforms and use either
abi_intorabi_short.Helge
Quoted 30 lines · Pierrick Bouvier
Quoted 29 lines · Helge Deller
Quoted 27 lines · Pierrick Bouvier
Quoted 16 lines · On 7/24/2026 9:01 AM, no92 via qemu development wrote:
The members are declared as
__kernel_pid_tin Linux UAPI headers. Analogous members in structtarget_shmid_ds(shm_[cl]pid) are also declared asabi_int.Fixes 1c54ff97bbde ("linux-user: fix and cleanup IPCOP_msg* ipccalls handling")
Signed-off-by no92 <[email protected]>--- linux-user/syscall.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)linux-user/syscall.c +0
-0linux-user/syscall.c struct target_msqid_ds · line 4238
Quoted 7 lines
linux-user/syscall.c +2
-2@@ -4234,8 +4234,8 @@ struct target_msqid_ds abi_ulong __msg_cbytes; abi_ulong msg_qnum; abi_ulong msg_qbytes; - abi_ulong msg_lspid; - abi_ulong msg_lrpid; + abi_int msg_lspid; + abi_int msg_lrpid;...
The change looks correct in itself.
Quoted 7 lines
Quoted 4 lines
No.
abi_ulongis wrong, butabi_intisn't much better either if you look at the kernel sources:I wrongly assumed the definition we had on bsd-user side was correct, but didn't really think about checking it in linux sources, sorry.
don't worry...
Leo (no92), will you send an updated patch?
Helge
Quoted 31 lines · Helge Deller
Quoted 30 lines · Pierrick Bouvier
Quoted 29 lines · Helge Deller
Quoted 27 lines · Pierrick Bouvier
Quoted 16 lines · On 7/24/2026 9:01 AM, no92 via qemu development wrote:
The members are declared as
__kernel_pid_tin Linux UAPI headers. Analogous members in structtarget_shmid_ds(shm_[cl]pid) are also declared asabi_int.Fixes 1c54ff97bbde ("linux-user: fix and cleanup IPCOP_msg* ipccalls handling")
Signed-off-by no92 <[email protected]>---
linux-user/syscall.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)linux-user/syscall.c +0
-0linux-user/syscall.c struct target_msqid_ds · line 4238
Quoted 7 lines
linux-user/syscall.c +2
-2@@ -4234,8 +4234,8 @@ struct target_msqid_ds abi_ulong __msg_cbytes; abi_ulong msg_qnum; abi_ulong msg_qbytes; - abi_ulong msg_lspid; - abi_ulong msg_lrpid; + abi_int msg_lspid; + abi_int msg_lrpid;...
The change looks correct in itself.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
No.
abi_ulongis wrong, butabi_intisn't much better either if you look at the kernel sources:I wrongly assumed the definition we had on bsd-user side was correct, but didn't really think about checking it in linux sources, sorry.
I need to correct myself :-(
abi_int *is* much better than anything else.
Indirectly all current builds use glibc which switches to __msqid64_ds instead of the old msqid_ds struct, and in there __pid_t is used, which seems to be defined to int for all targets.
So, leo's patch is correct and I'll pull it into my linux-user next git tree as-is.
Thanks!
Helge