From patchwork Thu Sep 22 12:13:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 76749 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2563508qgf; Thu, 22 Sep 2016 05:17:44 -0700 (PDT) X-Received: by 10.200.38.147 with SMTP id 19mr1554994qto.67.1474546664504; Thu, 22 Sep 2016 05:17:44 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s62si915675qkh.281.2016.09.22.05.17.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 22 Sep 2016 05:17:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2wh-0001DE-U3 for patch@linaro.org; Thu, 22 Sep 2016 08:17:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2u1-000878-QB for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn2tz-0006L0-Km for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:56 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:36439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2tz-0006Kh-Dh for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:55 -0400 Received: by mail-lf0-f53.google.com with SMTP id g62so65192798lfe.3 for ; Thu, 22 Sep 2016 05:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WU1vRF+cxYP5ITiIlfKKH9uS6r0fqdPAQUFxg8835VQ=; b=A1i1/uWyvBTp9xbdzYEmy7AJ4PID3gvJoQ8gUPAyL0mH6bmUbJqOdVr3R8BXTu25cn JQhm6NhHu5TlY9yIEQhVetWHCdsUo4IWDNN2eKKeOuz9gPwCFZNj6g5O5t4EVQJxP0FE Y0veg66aFAmR6m2Mei1R2fUOqoIjfzZ/gv0Q8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WU1vRF+cxYP5ITiIlfKKH9uS6r0fqdPAQUFxg8835VQ=; b=bvYp3gbAkANqExsCRVRDJXyqk7xoRiB1MyQQf3oxR5p0QjVrWO+DZd0VpQCJxQYQ6f nYiduZzr6R1YHXr0HqzSSrVz1fllCjTWGHACtMv9QKO3i5TMXiB/WZr4eZtTj9117zX4 ocOkAM7eRqnTf6CQhi/y38JO3ZIlm+U8tw0fly1g6C7bFZd+eBoNBHhT8WsCq/imDdBn xEYVB+BPIqTiJcW+QcxYbRRsdychLcL53oQY4mMq/RnQtSOI6Dicn1a4oxFCE4EN97DO XU2InhtGbyGkonwuUgEfcZm+iWZezdNRk3ezvVDrsvaDX1kpzortZbjMpgt7RPFDKYFR N/Bw== X-Gm-Message-State: AE9vXwNyOF/u7kvUubzlcaMr+NtEZGBszNcCVgxXifgJev+587GV59fe/4DBNwygTN5eWnZN X-Received: by 10.25.16.210 with SMTP id 79mr753137lfq.177.1474546434413; Thu, 22 Sep 2016 05:13:54 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id u14sm294378lja.11.2016.09.22.05.13.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Sep 2016 05:13:52 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Thu, 22 Sep 2016 15:13:23 +0300 Message-Id: <26a6fc96e0ca7522b855c2164bc6098240c286f6.1474546244.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.53 Subject: [Qemu-devel] [PULL 03/26] linux-user: Allow bad msg_name for recvfrom on connected socket X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The POSIX standard mandates that for a connected socket recvfrom() must ignore the msg_name and msg_namelen fields. This is awkward for QEMU because we will attempt to copy them from guest address space. Handle this by not immediately returning a TARGET_EFAULT if the copy failed, but instead passing a known-bad address to the host kernel, which can then return EFAULT or ignore the value appropriately. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9d18326..51f558d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3472,7 +3472,14 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, ret = target_to_host_sockaddr(fd, msg.msg_name, tswapal(msgp->msg_name), msg.msg_namelen); - if (ret) { + if (ret == -TARGET_EFAULT) { + /* For connected sockets msg_name and msg_namelen must + * be ignored, so returning EFAULT immediately is wrong. + * Instead, pass a bad msg_name to the host kernel, and + * let it decide whether to return EFAULT or not. + */ + msg.msg_name = (void *)-1; + } else if (ret) { goto out2; } } else { @@ -3534,7 +3541,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, } if (!is_error(ret)) { msgp->msg_namelen = tswap32(msg.msg_namelen); - if (msg.msg_name != NULL) { + if (msg.msg_name != NULL && msg.msg_name != (void *)-1) { ret = host_to_target_sockaddr(tswapal(msgp->msg_name), msg.msg_name, msg.msg_namelen); if (ret) {