From patchwork Tue Aug 19 08:32:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35570 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AA19C2136C for ; Tue, 19 Aug 2014 08:45:46 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id cm18sf18043078qab.11 for ; Tue, 19 Aug 2014 01:45:46 -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=ChpyWmyIcBLt2ALW9Ex3fHIAQ2EUCMDWXpG9TAgf1AFw0/vN2epxZn66VI6GpU873t nkLW+l01tpwmaDQlMn9MdYKQy7Y8LHpZdgVHQa9XtxgbH+VElsslIlXQEHsOHG7qKlwi yGRuynvF9C2WOnSxBqzeVjCyg+ELe6wOLDQzNTe4snYHg8mdw1B06B1XlvoQSlEI9qcA v6ROimTn/uOvcLSYSu1miv5bNmjWQrvTr/1F+Z42CqhMkHJNKKZq1Xoq+yQJoGTKVLQb CxtfKX/ia7JCBsdif4BycxDwQWyfA/QbBtd+5GTHXx9/hTqz5vM1GE7eVbt+9PG2WUn4 4utQ== X-Gm-Message-State: ALoCoQmxxW5oJ0dLBkHEESFnjrL71rKjiKwE+3RPgm9tnIrnE0NKgn6JY5kYQu/AKFiToY1Z7esf X-Received: by 10.236.66.209 with SMTP id h57mr3780449yhd.47.1408437946524; Tue, 19 Aug 2014 01:45:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.200 with SMTP id f66ls2668132qgd.24.gmail; Tue, 19 Aug 2014 01:45:46 -0700 (PDT) X-Received: by 10.52.245.101 with SMTP id xn5mr11103823vdc.32.1408437946423; Tue, 19 Aug 2014 01:45:46 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id tc7si8355674vcb.24.2014.08.19.01.45.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:45:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so7118491vcb.12 for ; Tue, 19 Aug 2014 01:45:46 -0700 (PDT) X-Received: by 10.52.26.206 with SMTP id n14mr4452294vdg.0.1408437946326; Tue, 19 Aug 2014 01:45:46 -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 tc5csp220938vcb; Tue, 19 Aug 2014 01:45:45 -0700 (PDT) X-Received: by 10.140.103.75 with SMTP id x69mr57261722qge.17.1408437945327; Tue, 19 Aug 2014 01:45:45 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b38si28040226qge.71.2014.08.19.01.45.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:45:45 -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]:49171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJf32-0005Gk-Pd for patch@linaro.org; Tue, 19 Aug 2014 04:45:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJeqw-000178-36 for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJeql-0001ao-TY for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:14 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=50282 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJeql-0001YA-N9 for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:03 -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 85F572668F; Tue, 19 Aug 2014 10:33:02 +0200 (CEST) From: riku.voipio@linaro.org To: Peter Maydell , qemu-devel@nongnu.org Date: Tue, 19 Aug 2014 11:32:57 +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: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Tom Musta Subject: [Qemu-devel] [PULL v2 22/23] 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.181 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;