Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1112388pxx; Tue, 27 Oct 2020 08:31:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjxRRSB4DZVfPGSAa72Xvod6Nv4sZY1ENwwMhrVt53gLBneVfadVGJoQGEc1N6vRNOZ62C X-Received: by 2002:a17:906:b190:: with SMTP id w16mr2918284ejy.53.1603812681307; Tue, 27 Oct 2020 08:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603812681; cv=none; d=google.com; s=arc-20160816; b=wyi9GLYuhfUN6g/7PPjc9+nMJEM6jbs7r6ZM6s3bGcLOOlG1gClG+ALibKJ3CBOC1F Ay3YqcjWeYw5gpeR5YG6iQxjwZe+YxcRG7pve1mleIWJ9YhToMUS9BBa2QRuiRa5GoxS A1avTx6EZDK2WIqRrrOXbSBm+D4d+N13au1maSofAzOP/cTuqlXfZIrGBXLGP9edj0rI iFNpuLDhSgxwWpVUVjMHdDC5Cdob5yWhSNolG+u6EVhasn+0Rwiv3zi96mETt6eBlT0w oDVfR1Tuexpx5N+9bkOmuPE7Ydhan8cFYP+5sQR1jqOfOARENDdt1CU3yf98eLwQLxEn s05w== 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=TUi6hHZyqbNWYUMkcvbYx5mtxOoUEp6LMldfsGyVPl8=; b=rLefzhr0o80NAACuh/5zMqCzt72lVDC6N/4EohQoNbXHsI/Q7FL4FcaU0+XvOU8hqo VSfnUh5uYA/LG93oyrrkR7YO4GBqYuteNyRwJfIg7q//Juuw+Bqk3mNEPUzegA8Cl4cK b7PomO+VewhAPV6npc31sJNLGVZ2SISe0lmXa5rE67ZvgLQwurQ3Rr29JJ47uGnLDMyZ NQReP2oo8wMTV2BTfL1LtWonGly+4sEczyelKbDK0RObxHyYlakl/9YYGUCj1nxXSIuP 5eVoacKj/Aqje6RMCNzCoLzBZohGt9HgTAgz51o00KT0lF5DnPmY7N+ediyhHn45CqTS RH6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xwfsZa2u; 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 t14si1079638ejy.440.2020.10.27.08.30.58; Tue, 27 Oct 2020 08:31:21 -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=xwfsZa2u; 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 S1760599AbgJ0OfX (ORCPT + 99 others); Tue, 27 Oct 2020 10:35:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:33196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760282AbgJ0OeZ (ORCPT ); Tue, 27 Oct 2020 10:34:25 -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 2F22522202; Tue, 27 Oct 2020 14:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809264; bh=107qioJLkkCn3mjMOJSHhxuAiE2054Q/f8qS2I2X+Zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xwfsZa2uhQj9QaaGMLM76aPS44XdMD4Pu7X32NrhCoqQnZ2U9R4yKIXNkG1jTpRqc A/oQIywpZSEedQiZkGJ5AUuG8XWmE1ces8S/zsb8P1PaRqYHyHIW7MqexsRSveSKND MZwkphMKi4YXK/Os/OMhj2XMfqmEMvju69+BRiN8= 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 5.4 134/408] drivers/virt/fsl_hypervisor: Fix error handling path Date: Tue, 27 Oct 2020 14:51:12 +0100 Message-Id: <20201027135501.314587905@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 93d5bebf9572a..fb292f9cf29df 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 = kcalloc(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, param.source != -1 ? FOLL_WRITE : 0, pages); 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