From patchwork Fri Aug 22 13:24:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0804220540 for ; Fri, 22 Aug 2014 13:33:34 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id b6sf35202024yha.1 for ; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=G16ssBWfLY3QmHYa8CbRVnIju8lZAEBdO7bQUY+v4lE=; b=TQeo3NI65G8tP453qoRq9bA/og94PGyynSrQbDBznXkrz0TY8RSFCgYstdbpd1awn0 KX1V9AZ8AzoOZSMYzg68Ku0SrHPtLfVe/XfLeXnBK5ivhv6u3v1Phm412aZmL57yqWcD 6zXFQblh5LKVwaTWrqgarxPeVF9kx848kuwCzKQOsNgh+7uh19yan5AsF7fK6rcULn8y CLBMkPPAohRauteQ4HzWkWNnW4Z/lGbvjtLRvHAqCCp2bxMAeF/oVEnJJ7OLV52RP95j /5X3OhQRHguAJJwm/n7kJrkDBx3xSzvjMDWrmP99/fpE6BC8ecybUgk2X/rx8AviWCfJ VTaQ== X-Gm-Message-State: ALoCoQlBdMU2gQp7G6l/nRb72PDkzpl5MR2BFjL41MVR+c7XuVodwBe+Em9UhTXGoLNnfb+JqXmM X-Received: by 10.236.23.230 with SMTP id v66mr8571841yhv.53.1408714413870; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.228 with SMTP id 91ls1160635qgr.70.gmail; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) X-Received: by 10.221.68.135 with SMTP id xy7mr76027vcb.65.1408714413799; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id u7si13571397vdc.40.2014.08.22.06.33.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Aug 2014 06:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id hy10so12336810vcb.18 for ; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) X-Received: by 10.220.187.134 with SMTP id cw6mr71532vcb.71.1408714413738; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp17247vcb; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) X-Received: by 10.229.136.133 with SMTP id r5mr7862986qct.31.1408714413099; Fri, 22 Aug 2014 06:33:33 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 5si42237408qam.91.2014.08.22.06.33.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 22 Aug 2014 06:33:33 -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; Received: from localhost ([::1]:37146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKoyC-0000Xj-LI for patch@linaro.org; Fri, 22 Aug 2014 09:33:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKopr-0006b6-4V for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKoph-0002D4-97 for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:24:55 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=54466 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKoph-0002BL-2q for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:24:45 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 7499B26645; Fri, 22 Aug 2014 15:24:43 +0200 (CEST) From: riku.voipio@linaro.org To: Peter Maydell , qemu-devel@nongnu.org Date: Fri, 22 Aug 2014 16:24:39 +0300 Message-Id: <29560a6cb7a7a705de3d7dfb44e8b1c0a12ad37d.1408712881.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Tom Musta Subject: [Qemu-devel] [PULL v3 21/22] linux-user: writev Partial Writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Tom Musta Although not technically not required by POSIX, the writev system call will typically write out its buffers individually. That is, if the first buffer is written successfully, but the second buffer pointer is invalid, then the first chuck will be written and its size is returned. Signed-off-by: Tom Musta Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1da216e..ebdc70e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1803,6 +1803,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, abi_ulong total_len, max_len; int i; int err = 0; + bool bad_address = false; if (count == 0) { errno = 0; @@ -1843,9 +1844,20 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, vec[i].iov_base = 0; } else { vec[i].iov_base = lock_user(type, base, len, copy); + /* If the first buffer pointer is bad, this is a fault. But + * subsequent bad buffers will result in a partial write; this + * is realized by filling the vector with null pointers and + * zero lengths. */ if (!vec[i].iov_base) { - err = EFAULT; - goto fail; + if (i == 0) { + err = EFAULT; + goto fail; + } else { + bad_address = true; + } + } + if (bad_address) { + len = 0; } if (len > max_len - total_len) { len = max_len - total_len;