Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp159779pxx; Wed, 28 Oct 2020 01:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzg/b+b3V8zmdsd7VS7SOfRo6LSoxqbQt8UXP7knJpLfnaQSQKDWjRvNqHJsVob8nw6IVg X-Received: by 2002:a17:906:f24b:: with SMTP id gy11mr6553178ejb.371.1603872400822; Wed, 28 Oct 2020 01:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603872400; cv=none; d=google.com; s=arc-20160816; b=AKdRziYnTLtvOcNsv19+b3oQCdm60Cf8KiaTFR/qRFZz0Br0XHeyE6LT1rg9TM8iWE IRsE30mEjMl3664ESTVXcWR6dsQzjyhyroKnTAJjC2dJ0vc/wqT+IdglBwllaf4Oo7th 64amfbGqwll3Ju99QSempwBSOKrOIBbrsZK1swWcqeMqwW4RE3wYkwbTK3QbnRE+XNBM LhEWvIIo4ezo8JfTph/0HBaDwoc1d6iipzUcpxScPe8/y2DsbVbeaeb8gYgnk04V4OY9 HH8fLKmnFGhOqAQFEhFIAv+2cxGMArj8hAC5w9OH1ve2xG+ulJNNdgc2qssWs1SOhBTa 3hLQ== 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=ncAW80L6EtAzuxhmDgy1Kpu5KIMyPE17czOJzKcviAw=; b=s389UN9vEF2GSF1n3HKF3dZtEf3ZXoYf9J+o6fFR8yl4bndZLcLRwYhukqHIVCz07l D5SvftbAW0M2spJnAOUB2RIwWA6rjRDgEMW8rvhKkPRP/wRGSHYO1GWI5wbKft1re3OS ywwLSz2z/woKpuI9KqY6j/lBDDCOHM8ZAZplTgxz8EsEeeopHeX557jJouyFGw0Y5xbb St/qkeTi7ucotGxDdSW/kUFEG+1sZWVgwsgz8CUOiimYSo1JNAAxtkV4hls8nWRDwA5N 9XV2jS84FQGFrSPomTsndIfIpev7kqa1qmHXiqBhWanZ1pZ4/61WIAPSwDe6eQ1LqIFy dEfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QXhfl8BD; 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 i19si2816688ejh.153.2020.10.28.01.06.17; Wed, 28 Oct 2020 01:06:40 -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=QXhfl8BD; 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 S1753014AbgJ0N6G (ORCPT + 99 others); Tue, 27 Oct 2020 09:58:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:45120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752987AbgJ0N6A (ORCPT ); Tue, 27 Oct 2020 09:58:00 -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 F1E2B21D42; Tue, 27 Oct 2020 13:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807078; bh=z5ITrvS6frDn3B3LrQuqXAo4pS6OkHGPzVrkq7m7zuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXhfl8BDVD27+5oVcDzBJ2x0U9YNNSqx4fd7L07HqbrRZ4BwPb0KFVysocVcKUhaJ nu30ZX7Jd52Q+WG1jmhNCQ2f77tsUCvuV4mWoxZoMsLpgIOv0y2LaK3y6s0yRE6vMz pM9XiCJzQExMoOgVIigdiEuhJFT7bATDX35XYadE= 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.4 035/112] VMCI: check return value of get_user_pages_fast() for errors Date: Tue, 27 Oct 2020 14:49:05 +0100 Message-Id: <20201027134902.221723386@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@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 3877f534fd3f4..e57340e980c4b 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