linux-user: Handle short lengths in host_to_target_sockaddr()
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 7 Jul 2016 14:44:43 +0000 (15:44 +0100)
committerRiku Voipio <riku.voipio@linaro.org>
Tue, 19 Jul 2016 12:23:17 +0000 (15:23 +0300)
commita1e221929f570cc84661158421f942b3328a9fd1
treeff0d7cfba933de9ee8d7dd4dd9a00b793e795105
parent31efaef1d9b80b7803e22ef28ffc51df04db60ab
linux-user: Handle short lengths in host_to_target_sockaddr()

If userspace specifies a short buffer for a target sockaddr,
the kernel will only copy in as much as it has space for
(or none at all if the length is zero) -- see the kernel
move_addr_to_user() function. Mimic this in QEMU's
host_to_target_sockaddr() routine.

In particular, this fixes a segfault running the LTP
recvfrom01 test, where the guest makes a recvfrom()
call with a bad buffer pointer and other parameters which
cause the kernel to set the addrlen to zero; because we
did not skip the attempt to swap the sa_family field we
segfaulted on the bad address.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
linux-user/syscall.c