linux-user: Fix errno for sendrecvmsg with large iovec length
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 15 Jul 2016 13:57:27 +0000 (14:57 +0100)
committerRiku Voipio <riku.voipio@linaro.org>
Wed, 21 Sep 2016 11:20:31 +0000 (14:20 +0300)
The sendmsg and recvmsg syscalls use a different errno to indicate
an overlarge iovec length from readv and writev. Handle this
special case in do_sendrcvmsg_locked() to avoid getting the
default errno returned by lock_iovec().

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

index 71f40e3ab80bd200771b20e271ec31ce61cbd60d..9d1832646736c18a1cd30d401db74a563955d693 100644 (file)
@@ -3485,6 +3485,15 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
 
     count = tswapal(msgp->msg_iovlen);
     target_vec = tswapal(msgp->msg_iov);
+
+    if (count > IOV_MAX) {
+        /* sendrcvmsg returns a different errno for this condition than
+         * readv/writev, so we must catch it here before lock_iovec() does.
+         */
+        ret = -TARGET_EMSGSIZE;
+        goto out2;
+    }
+
     vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE,
                      target_vec, count, send);
     if (vec == NULL) {