From patchwork Fri Aug 15 11:01:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35439 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A2231203C5 for ; Fri, 15 Aug 2014 11:09:14 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id 29sf7155487yhl.6 for ; Fri, 15 Aug 2014 04:09:14 -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=XXfIeB9bdCf/W0tbr3IVUnWPFxKe7OGXSc5L5rC8MZo=; b=W0iV2FnnN59IG42wvOj7Zqu5z0ekkluKP/sU7KJjlO0P0mJDUlDXAMSp+hbNi3aCsT j9R5toQxm+QU9osCfPvEasugBT0e/u3VnLECOqQMHIGEPNdxFpBaGu1ntkuRs5h9BEIX lZUX4m0QB6OgXu7XdUGeFPxyp/84zYy8qewHkfUOemYFlmgTDqa0wprkpBQATahJOtZ2 nv2SJulC/vo3J1KLsJvdOnG0SqEAp2i5A3efRuK+NG1yA0BbfR3CaFc6hketkxjoW0mx ysuHCwQI1QLj1vJAiYdvcj47tqqUbs8VYQkgeRSPZUSAAyxfpKuuUtKcMFIvQXl4m1lh CAJQ== X-Gm-Message-State: ALoCoQmGfH2+pgZ2IusxcjMRNRejxHaN4LArJdu/2zfJ+Dkt+Qe3RaVPBAV7bM9/v6t4X0kTJ8xJ X-Received: by 10.236.101.148 with SMTP id b20mr5605750yhg.46.1408100954459; Fri, 15 Aug 2014 04:09:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.197 with SMTP id d63ls1439937qgd.82.gmail; Fri, 15 Aug 2014 04:09:14 -0700 (PDT) X-Received: by 10.140.82.71 with SMTP id g65mr24557362qgd.75.1408100954400; Fri, 15 Aug 2014 04:09:14 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id v6si11370812qge.21.2014.08.15.04.09.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Aug 2014 04:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so2813242vcb.9 for ; Fri, 15 Aug 2014 04:09:14 -0700 (PDT) X-Received: by 10.52.135.133 with SMTP id ps5mr7986629vdb.33.1408100954182; Fri, 15 Aug 2014 04:09:14 -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.37.5 with SMTP id tc5csp104397vcb; Fri, 15 Aug 2014 04:09:13 -0700 (PDT) X-Received: by 10.140.20.226 with SMTP id 89mr24728430qgj.100.1408100953544; Fri, 15 Aug 2014 04:09:13 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b6si11373021qar.9.2014.08.15.04.09.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 Aug 2014 04:09:13 -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]:58596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFNg-0008Nw-UK for patch@linaro.org; Fri, 15 Aug 2014 07:09:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFGh-0004xR-6U for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:02:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIFGV-00073Q-62 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:01:59 -0400 Received: from afflict.kos.to ([92.243.29.197]:57591) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFGV-00071L-06 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:01:47 -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 7EBED2669C; Fri, 15 Aug 2014 13:01:45 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 15 Aug 2014 14:01:41 +0300 Message-Id: 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: 92.243.29.197 Cc: Peter Maydell , Tom Musta Subject: [Qemu-devel] [PULL 23/24] 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.178 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 c4f6454..3b1beff 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;