Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp257491pxx; Wed, 28 Oct 2020 04:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGVReZvwLfpfZ4M0Sxzrq/Ia5g7kFKI3vCBRn7WCSXfRwgdWBsK+Stp8WkAGAnFm0iHVFa X-Received: by 2002:a17:906:3146:: with SMTP id e6mr6630111eje.363.1603883819907; Wed, 28 Oct 2020 04:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603883819; cv=none; d=google.com; s=arc-20160816; b=OCN0J0MvdDbIHnRTrx1kcTfcvT+ozW6x+eBpqyalWW5UdeyToQ6ciagUt2f8lUTWsV Ew9r3Cu8gK69OoMTKO/vMIxvOU3e4eehiCGbstuUgxg1TxWzjU4lPKW+t9MpG39Vv6Wa lkDxb8LtamQ62gI8Qe3MC+FxJwbeBJicuklH9FTy4+msCkmp+o58ccscQSsdY3VyCNQf qle+N/3AryMMqAKykrjRyRKaUHFrz3IUnewxUrlV1nwCGqiMtV6XOwwAKIZoq6W4BNHz KvbLEc5CAk9GJjuaflXytzilSUBqzoVt7vSoRxWVleJRBocF6qlTOaO1SDExAonHB0AJ K1Bg== 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=aGhSPAZ6Zx5MVA6F7W6UdQKnibe4rlnMFyIK2Xypg+w=; b=Aify/JGOEN5sPgBVDhXpx61Jg9ugC6Frd3YdXLhXWwiocSImnDnPXE01TQq3bHj0QJ kIGlO24g6TJBydPRv+XLWwCc65O2OxxU5wHB9WGmCUximJgHsb0fwcpZixP29uMJJx3k 8Hff+KxQkeH3ka8ReVfOeqlbeUJKVsOz13JJxxkew9yq+BdT+4B842fd2vsakofW65mu XztWGAgxgDv0zVUe7L6E5oVFMdUaM8aOpWfzaFAiQBmai3SuZMG37Y5cLdHMYaAIxcLL NX7Z8FXxdgvNTVH+MZhY1D4y5JijtOYZ8b0zyREfRicpJCgKPCJodxXAUt/8ts7q+Dj7 KEgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BjYbatKc; 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 bs17si3022913ejb.543.2020.10.28.04.16.38; Wed, 28 Oct 2020 04:16:59 -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=BjYbatKc; 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 S1788127AbgJ0PAW (ORCPT + 99 others); Tue, 27 Oct 2020 11:00:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1781780AbgJ0O4H (ORCPT ); Tue, 27 Oct 2020 10:56:07 -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 8D338222C8; Tue, 27 Oct 2020 14:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810567; bh=U2L4TI+ODW1DfSENXpsKzJMS8rsBSGdviXkUOtLUq+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BjYbatKcBxDHzeB9nmT2Li1KSX3Rocvz3Famackmw/RqfZ+BU7nJqDOIJ42P2F6HV IiNxBp17KNZuwypt4jIeBItQ21RWfkikUlNFyz7qV6AXDbWW6i0a32dTIu0Ih4X57L g6zdN+z7ESObOPgFBkSXcltUwcRmUs88S287fUfI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Dewar , Sasha Levin Subject: [PATCH 5.8 185/633] VMCI: check return value of get_user_pages_fast() for errors Date: Tue, 27 Oct 2020 14:48:48 +0100 Message-Id: <20201027135531.367726215@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 8531ae7811956..c49065887e8f5 100644 --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c @@ -657,8 +657,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; } @@ -670,8 +671,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