diff mbox

[2/3] linux-user: fixed getsockopt() optlen

Message ID 1389432851-11420-3-git-send-email-pavel.zbitskiy@gmail.com
State New
Headers show

Commit Message

Pavel Zbitskiy Jan. 11, 2014, 9:34 a.m. UTC
From: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>

optlen parameter of getsockopt() of type socklen_t* was read into
variable of type socklen_t, that caused zeroing out of upper 4 bytes
when running s390x on top of x86_64. This patch changes optlen type
to abi_ulong.

Signed-off-by: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
---
 linux-user/syscall.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Maydell Jan. 12, 2014, 7:07 p.m. UTC | #1
On 11 January 2014 09:34,  <pavel.zbitskiy@gmail.com> wrote:
> From: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
>
> optlen parameter of getsockopt() of type socklen_t* was read into
> variable of type socklen_t, that caused zeroing out of upper 4 bytes
> when running s390x on top of x86_64. This patch changes optlen type
> to abi_ulong.

This patch and patch 3 are correct fixes, but shouldn't we be
more generally using abi_ulong for every argument we read from
the guest in do_socketcall() ?

It might be nicer to fix this by having a lookup table of SOCKOP_*
to number-of-arguments, and then hoist the get_user_ual() calls
outside the switch() statement to fill in an 'abi_ulong args[]' array.
Then the individual calls in the switch would just look like
    do_socket(args[0], args[1], args[2]);

thanks
-- PMM
Michael Tokarev Jan. 15, 2014, 7:37 p.m. UTC | #2
12.01.2014 23:07, Peter Maydell wrote:
> On 11 January 2014 09:34,  <pavel.zbitskiy@gmail.com> wrote:
>> From: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
>>
>> optlen parameter of getsockopt() of type socklen_t* was read into
>> variable of type socklen_t, that caused zeroing out of upper 4 bytes
>> when running s390x on top of x86_64. This patch changes optlen type
>> to abi_ulong.
> 
> This patch and patch 3 are correct fixes, but shouldn't we be
> more generally using abi_ulong for every argument we read from
> the guest in do_socketcall() ?

I think the current fix is worth to apply anyway, regareless of
further possible rework.

Thanks,

/mjt
diff mbox

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4a14a43..c2cd2b4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2389,7 +2389,7 @@  static abi_long do_socketcall(int num, abi_ulong vptr)
             abi_ulong level;
             abi_ulong optname;
             abi_ulong optval;
-            socklen_t optlen;
+            abi_ulong optlen;
 
             if (get_user_ual(sockfd, vptr)
                 || get_user_ual(level, vptr + n)