From patchwork Mon Feb 17 18:55:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 24788 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3CBD720143 for ; Mon, 17 Feb 2014 18:55:39 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id gq1sf60137609obb.8 for ; Mon, 17 Feb 2014 10:55:38 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=ucHVu82lhrMtW5DExwMRyfwzeuoDQeZd7rPqFUtpf+M=; b=mV2uxKpAKhtNcX6CadZd+E8I2m77mJlzFYPDzohjLpv9do5r78BF/eZNWYIPdDcGAk c04suxGSv+P4nOxvOgf+xcFLOnQPHgqB6hLTWdAS1+/COffkeyvdAcd7E0fXIDR37scJ /xNPlHO83iedRqCOjzB1/1N0yU1CN2X7yplEQhODfVtz5Vn/FCxWK2d23Rd9YrNvtlkx AktDa7rCtfxBAYdLxlExsa1+lTQa4INkfOJQ3mXI+fbhvzV/4UUzPaaVG26oWOmWF2nN Yg3U3vX7oank0Ow4XcI264+pLNKr6/04IZIaP+dWtRFPRYLnX3kluOfRTr/VmFI4YamN UXgQ== X-Gm-Message-State: ALoCoQmYXXgugzRtWqjUvWMufEpN01T2iRYvXwzIibYlvCTShtIXBPjt3aZGvTumEHO+XZH+HHOz X-Received: by 10.43.161.202 with SMTP id mh10mr9144126icc.23.1392663338269; Mon, 17 Feb 2014 10:55:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.129 with SMTP id g1ls992133qge.69.gmail; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Received: by 10.220.48.194 with SMTP id s2mr1269428vcf.43.1392663338155; Mon, 17 Feb 2014 10:55:38 -0800 (PST) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id uw4si4669752vdc.105.2014.02.17.10.55.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id c14so12680234vea.3 for ; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Received: by 10.220.95.139 with SMTP id d11mr13851725vcn.21.1392663338078; Mon, 17 Feb 2014 10:55:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp160326vcz; Mon, 17 Feb 2014 10:55:37 -0800 (PST) X-Received: by 10.180.149.143 with SMTP id ua15mr14139108wib.36.1392663336733; Mon, 17 Feb 2014 10:55:36 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id op5si11960720wjc.80.2014.02.17.10.55.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 17 Feb 2014 10:55:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WFTLr-0002Ed-2z; Mon, 17 Feb 2014 18:55:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH 3/4] linux-user: Fix error handling in lock_iovec() Date: Mon, 17 Feb 2014 18:55:33 +0000 Message-Id: <1392663334-8555-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1392663334-8555-1-git-send-email-peter.maydell@linaro.org> References: <1392663334-8555-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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; }