From patchwork Wed Feb 19 10:35:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 24938 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5E466201EE for ; Wed, 19 Feb 2014 10:36:48 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id fa1sf488743pad.0 for ; Wed, 19 Feb 2014 02:36:47 -0800 (PST) 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=UXh9b7Y/yCLhBjDR352uy8+e2SjEbbI8DoDYRQg0XZk=; b=LjSf42AgN0hgU1s79DP+DfGWCYNM8b+ogiRla+2hmiOWv2b5m1N/fM3Jo/6izJy3Ou 8kqHmX26n2l0fw8F1aZ3p/m8td45FlHH6WxlF/Opz2BmhbnMKPz8YxU0O7/ZMTWRd3dX Oe8aXywP4UNq6CcRFULXZ3+EIuNywglhEtWAXvn50odkUC/MDZbmkjYDuSt1Q1EuSBtv 1aUTYmbOoh9G85UZ7Vo2pskFY2Ac7V4/C+kW6ow007Q3bXZzYXHOxs6RXLnBU/MNxxP4 CxpcE5cmJlle5ltqKhw9SMMeJiLIDoKj2fJEUvR7gVP2NwH4LVcU0AFpUzp9PK8F++O1 zrlw== X-Gm-Message-State: ALoCoQl/E7kXxIzGwYGC5QnXSAPEC2/nIPodZz2/wzld11FNYP5H+jwOpekwaP3CSBrAWD7vBGEL X-Received: by 10.67.1.129 with SMTP id bg1mr14784541pad.8.1392806207364; Wed, 19 Feb 2014 02:36:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.138 with SMTP id c10ls57029qga.63.gmail; Wed, 19 Feb 2014 02:36:47 -0800 (PST) X-Received: by 10.220.165.193 with SMTP id j1mr31238vcy.73.1392806207135; Wed, 19 Feb 2014 02:36:47 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id y3si6573796vdo.123.2014.02.19.02.36.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:36:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so186442vcb.0 for ; Wed, 19 Feb 2014 02:36:47 -0800 (PST) X-Received: by 10.52.106.166 with SMTP id gv6mr25184vdb.86.1392806207069; Wed, 19 Feb 2014 02:36:47 -0800 (PST) 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.220.174.196 with SMTP id u4csp286928vcz; Wed, 19 Feb 2014 02:36:46 -0800 (PST) X-Received: by 10.236.143.148 with SMTP id l20mr17793019yhj.102.1392806206541; Wed, 19 Feb 2014 02:36:46 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l58si29266933yhj.11.2014.02.19.02.36.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Feb 2014 02:36:46 -0800 (PST) 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]:58085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4WE-0008BV-2p for patch@linaro.org; Wed, 19 Feb 2014 05:36:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V7-00076n-Ub for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WG4V2-0007CL-Qf for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:37 -0500 Received: from afflict.kos.to ([92.243.29.197]:33840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG4V2-0007As-8w for qemu-devel@nongnu.org; Wed, 19 Feb 2014 05:35:32 -0500 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 97B5926562; Wed, 19 Feb 2014 11:35:30 +0100 (CET) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 19 Feb 2014 12:35:27 +0200 Message-Id: <501bb4b0cb1debf2b495f0ba3980b97ceca652f5.1392805802.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 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 Subject: [Qemu-devel] [PATCH 4/6] linux-user: Fix error handling in lock_iovec() 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=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: Peter Maydell In lock_iovec() if lock_user() failed we were doing an unlock_user but not a free(vec), which is the wrong way round. We were also assuming that free() and unlock_user() don't touch errno, which is not guaranteed. Fix both these problems. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f370087..bb3e4b1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1707,6 +1707,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, struct iovec *vec; abi_ulong total_len, max_len; int i; + int err = 0; if (count == 0) { errno = 0; @@ -1726,7 +1727,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1); if (target_vec == NULL) { - errno = EFAULT; + err = EFAULT; goto fail2; } @@ -1740,7 +1741,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, abi_long len = tswapal(target_vec[i].iov_len); if (len < 0) { - errno = EINVAL; + err = EINVAL; goto fail; } else if (len == 0) { /* Zero length pointer is ignored. */ @@ -1748,7 +1749,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, } else { vec[i].iov_base = lock_user(type, base, len, copy); if (!vec[i].iov_base) { - errno = EFAULT; + err = EFAULT; goto fail; } if (len > max_len - total_len) { @@ -1763,9 +1764,10 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr, return vec; fail: - free(vec); - fail2: unlock_user(target_vec, target_addr, 0); + fail2: + free(vec); + errno = err; return NULL; }