Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp170138pxx; Wed, 28 Oct 2020 01:28:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTqtGivK4c4gpJe/9FVYMjuiN/ye+aoWg149WyIRbafHEPAy9wtnxfnlZu2L2y4f+A3ukh X-Received: by 2002:a17:906:c0c4:: with SMTP id bn4mr6397311ejb.27.1603873716106; Wed, 28 Oct 2020 01:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603873716; cv=none; d=google.com; s=arc-20160816; b=CSRqvHrMoNdydEFofh3SAz5u9RsGssgpnhxNtMwi0z7QK/k0VhOqe8jdI/W7u15OHb 7Ye4T0ORnzdAyuloNI6EgKqzzRD+yUdmqm7Mlcsrf75oR0c+3f4RP7yNk6X/u1rwgZJ0 79G2A2Kvc8Xq7ePK5QNiO3ezxA/ZnFHr6j6Ou+mDIhE7W6y92+4aXjm4dW4ijFbBoX6k KHpX9g7bMjWwORegIqiRrvkXZMdDe9yf+vUryl7oQm6MdS8o+m5gKHAhMYFlgTvmkHQM kIp5VCAqhYOa8FbGz1vC4VrCTyEupq8bNE4KPdHDIGzwtyVP9YZ+hBYInvdBSaXHn2AG 83+A== 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=DHVppLstFn56hW2rTZbYO+xVvaFPLM2LcxGKjXZ6CIY=; b=NLG0MBENY9qU3Jz62TI3wId5YrRAkuJVet821bRgTGKJnp4ad+NksL+MzNGEtqExmr j48+6Gc929qwCVBuTW+jB/IxVwMLkD2S5kOLkbLEGCC55OBvlGNpFY0jPc39Godo8Ny1 z3c3by6H/soT5rmT06yaoOcSgpBfydDYaguER0SHE6YvrPutYRtb6OfE7mgatrmKjaeO gBr0vjUQYweDqhTrDCF5tC7MMCL81UgSwZurdbtWV4jkWOON9T3slR2gfYDAAHA+rA7a JJHYH6eVB7YkoXyH44PyvOovavFG7wkcePI16rRvy1zg/DtUUfzJnFOffG5zaaM2Sg8E PYbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nbN+1enA; 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 s16si2897729edy.300.2020.10.28.01.28.14; Wed, 28 Oct 2020 01:28:36 -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=nbN+1enA; 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 S1754145AbgJ0OEb (ORCPT + 99 others); Tue, 27 Oct 2020 10:04:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:52674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754123AbgJ0OEX (ORCPT ); Tue, 27 Oct 2020 10:04:23 -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 83DE72222C; Tue, 27 Oct 2020 14:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807463; bh=Cpp21kCkstqxQJV9sQUeqx2O8ZHuuUmNxqbSValQmvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nbN+1enArV8nTYp855QTUjhm+UNx7UFzbxIQIkxBWGPcDbZb4QWihk+jcaaURLUeW lQH1u48BwOStVBVMCOv/V8oVNtypazjbhRIFyQqpLAqsVk0igDiy7h9LVb8W2TLmCT q4uLmNUOYwkbqiHUv/3+hzc6WP1GK48kKHkvkQ3E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Dewar , Sasha Levin Subject: [PATCH 4.9 035/139] VMCI: check return value of get_user_pages_fast() for errors Date: Tue, 27 Oct 2020 14:48:49 +0100 Message-Id: <20201027134903.811607415@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@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: Alex Dewar [ Upstream commit 90ca6333fd65f318c47bff425e1ea36c0a5539f6 ] In a couple of places in qp_host_get_user_memory(), get_user_pages_fast() is called without properly checking for errors. If e.g. -EFAULT is returned, this negative value will then be passed on to qp_release_pages(), which expects a u64 as input. Fix this by only calling qp_release_pages() when we have a positive number returned. Fixes: 06164d2b72aa ("VMCI: queue pairs implementation.") Signed-off-by: Alex Dewar Link: https://lore.kernel.org/r/20200825164522.412392-1-alex.dewar90@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c index 5927db046a87c..6ac3c59c9ae78 100644 --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c @@ -758,8 +758,9 @@ static int qp_host_get_user_memory(u64 produce_uva, if (retval < (int)produce_q->kernel_if->num_pages) { pr_debug("get_user_pages_fast(produce) failed (retval=%d)", retval); - qp_release_pages(produce_q->kernel_if->u.h.header_page, - retval, false); + if (retval > 0) + qp_release_pages(produce_q->kernel_if->u.h.header_page, + retval, false); err = VMCI_ERROR_NO_MEM; goto out; } @@ -770,8 +771,9 @@ static int qp_host_get_user_memory(u64 produce_uva, if (retval < (int)consume_q->kernel_if->num_pages) { pr_debug("get_user_pages_fast(consume) failed (retval=%d)", retval); - qp_release_pages(consume_q->kernel_if->u.h.header_page, - retval, false); + if (retval > 0) + qp_release_pages(consume_q->kernel_if->u.h.header_page, + retval, false); qp_release_pages(produce_q->kernel_if->u.h.header_page, produce_q->kernel_if->num_pages, false); err = VMCI_ERROR_NO_MEM; -- 2.25.1