Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp184335pxx; Wed, 28 Oct 2020 02:01:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD3Bl/2AWb9qk5/oDZI/e6ACBIavXlGcZ5dZS7Sb6yQQK6vgfNkU+pAF/djBvqREUsJA7y X-Received: by 2002:aa7:d790:: with SMTP id s16mr6770227edq.63.1603875670326; Wed, 28 Oct 2020 02:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603875670; cv=none; d=google.com; s=arc-20160816; b=pn/baIV3SRQBUthxk2wItiQ975F3aYO5GiRLMVy8b93ZXamO7hOz3wcD4TFpHOoFf0 Woa1nukJRvn1Mwa0NgBJySMsAVRbt2csjJOAEoVAXXPVwn8S/eEopiwoxBhGlf3exndG wkekfmPKiGEq1AanaDv+Jm+O1JX14RCgcErf7FKjMFvazRNOmZ5t8GzqrlXJdSFCm7nv zgu6jy+Y4XeaRcaDnJbJCXDfrEVFqGy2s3CUWiekR2Z3YpXQi4trKsoA6sgggK4StlqK bUOj6LwQTLluuWe+XnOyZfT4b6kSVxLNAKLChyLqaMHq4hcZ5YHNSUZ0FdpJA2+YfDsK ZoFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xrttqWguC4H6BbXVtyGsja59T8/avnXEzav5wSW95GA=; b=M9fB0mfuO2zqYOvBhNZEo8n8RnU7MA/AeHuxBDxlWBkym63I2V6UnxV4siymN+8Vyw GRHC4o0rtB52ocgoqHndBvWgsUkRDdTQqosvVLca0mwtszuDl2wO313o94tguZwvBYyU 1WnpPQXKnJpfk5ajdOiCtfrWHETT/fDVzlGGOyzI70jtn6JBRwXqzd8jkOyf/6yQHBNh 6BsvdZZABn2Gm6rGejxhhnFb1OyxCAeDKZM44fzUz4fhcUQ5vgQJ6uFpSmwno4muhkQb cne4AJR/MjB/22oEwPVIFOAp3eIpXxQei3LhUvau3aaWnX/T9U+CaEyyH055x1dA122V SCqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sJF+rtcM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si2654785ede.591.2020.10.28.02.00.48; Wed, 28 Oct 2020 02:01:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sJF+rtcM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756700AbgJ0OOr (ORCPT + 99 others); Tue, 27 Oct 2020 10:14:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:59498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755699AbgJ0OKm (ORCPT ); Tue, 27 Oct 2020 10:10:42 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB3A5218AC; Tue, 27 Oct 2020 14:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807840; bh=9dgvQk6pBI9SgNkMf31P4MykOKMkRQ8LozprGc+3ssc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sJF+rtcMyL0sooD3Zq3JOpwUjerCEg7+QHxIr4KqT1uSJOnO5WLi2Vy9aeoi+6eiy h2fdenrRDIfEVFgfZYNmVlw/HyApYR9uAWfS89GvtsDiEaqLwPjtSUBSik/U8ytQR8 C/7kf4RuI+aTg44rJ3bTz+m56S3shmKJcVHhSbKg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Souptick Joarder , Dan Carpenter , John Hubbard , Sasha Levin Subject: [PATCH 4.14 060/191] drivers/virt/fsl_hypervisor: Fix error handling path Date: Tue, 27 Oct 2020 14:48:35 +0100 Message-Id: <20201027134912.627767244@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Souptick Joarder [ Upstream commit 7f360bec37857bfd5a48cef21d86f58a09a3df63 ] First, when memory allocation for sg_list_unaligned failed, there is a bug of calling put_pages() as we haven't pinned any pages. Second, if get_user_pages_fast() failed we should unpin num_pinned pages. This will address both. As part of these changes, minor update in documentation. Fixes: 6db7199407ca ("drivers/virt: introduce Freescale hypervisor management driver") Signed-off-by: Souptick Joarder Reviewed-by: Dan Carpenter Reviewed-by: John Hubbard Link: https://lore.kernel.org/r/1598995271-6755-1-git-send-email-jrdr.linux@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/virt/fsl_hypervisor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c index 2e1678d22f6ff..1799bfb382e50 100644 --- a/drivers/virt/fsl_hypervisor.c +++ b/drivers/virt/fsl_hypervisor.c @@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) unsigned int i; long ret = 0; - int num_pinned; /* return value from get_user_pages() */ + int num_pinned = 0; /* return value from get_user_pages_fast() */ phys_addr_t remote_paddr; /* The next address in the remote buffer */ uint32_t count; /* The number of bytes left to copy */ @@ -174,7 +174,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) return -EINVAL; /* - * The array of pages returned by get_user_pages() covers only + * The array of pages returned by get_user_pages_fast() covers only * page-aligned memory. Since the user buffer is probably not * page-aligned, we need to handle the discrepancy. * @@ -224,7 +224,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) /* * 'pages' is an array of struct page pointers that's initialized by - * get_user_pages(). + * get_user_pages_fast(). */ pages = kzalloc(num_pages * sizeof(struct page *), GFP_KERNEL); if (!pages) { @@ -241,7 +241,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) if (!sg_list_unaligned) { pr_debug("fsl-hv: could not allocate S/G list\n"); ret = -ENOMEM; - goto exit; + goto free_pages; } sg_list = PTR_ALIGN(sg_list_unaligned, sizeof(struct fh_sg_list)); @@ -250,7 +250,6 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) num_pages, pages, (param.source == -1) ? 0 : FOLL_WRITE); if (num_pinned != num_pages) { - /* get_user_pages() failed */ pr_debug("fsl-hv: could not lock source buffer\n"); ret = (num_pinned < 0) ? num_pinned : -EFAULT; goto exit; @@ -292,13 +291,13 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) virt_to_phys(sg_list), num_pages); exit: - if (pages) { - for (i = 0; i < num_pages; i++) - if (pages[i]) - put_page(pages[i]); + if (pages && (num_pinned > 0)) { + for (i = 0; i < num_pinned; i++) + put_page(pages[i]); } kfree(sg_list_unaligned); +free_pages: kfree(pages); if (!ret) -- 2.25.1