Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp219425pxx; Wed, 28 Oct 2020 03:11:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy44VJ6Eq79kHVmG3ncSGGX3LiYhJImC4dhPn3GBffZNcxB+QrEIJnHTsbm8U3byZTR6j/H X-Received: by 2002:a17:906:33ca:: with SMTP id w10mr7013622eja.195.1603879880277; Wed, 28 Oct 2020 03:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603879880; cv=none; d=google.com; s=arc-20160816; b=jj1CSdIIlvWxh+eI9ooTLj0dohuudUlEdC2ENtjKTTamsEnlgk4XYFz3kKuQYcgIWQ WN/Aw1B2t+6umtad2Q5NsVA11PuDBj8GVjW7jMm08fmxCNPwTlRimtscT2+eHq+Ln3p6 XDysqEREea/CGt/iouDZP/j81p3HQO3PenO22cZBR1I7oHd6mf+EsXhkgO0BpCNyudwr Mm3K+RtN4jwJm+izp8pGAD7xfooZVPTtricLPE8oEZIqhNhyuyhJNYX3Yqcspv8no4Um rz/gCo0kelnTfH0ukQZIOQzlMnSC1s45hyFwjZ5HBQVUYI8EFxxAQQFF4n8EQSk8uXKW RUqQ== 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=d8Lmr07HQMqN0kYQiTt6oq58cqlZARHMh5V+k41aSbWzgoIrxl6I7qKzbQoNU6oHMg ODiFS2uIw1xzPxIlHzWWX/4puY18auG4sBvx37b5y7i6yv3TFq4pnlk45udtSfb4wLBq i80lMfsNHn26f0ynraH2YPFb5hm6sYvNfN36aaQwnfFhWKhksg2drtNMHqdCTmSaLTiP eCsYywMDDbVMZ8UeJy2X0AzUNyabEq6L+hhLyoC119OUtDXtTGOVJs0NR8ooV8VD6ub9 3PGUZ6qHS2OffmO2BPxA0TsO5aLH6kwWqR9DPs1vONZSKbuMMgxQ/VakJgwk7ktjM5EE D0lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zuvmPazy; 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 dk22si2709939edb.258.2020.10.28.03.10.58; Wed, 28 Oct 2020 03:11:20 -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=zuvmPazy; 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 S2898618AbgJ0OfE (ORCPT + 99 others); Tue, 27 Oct 2020 10:35:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:60844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760189AbgJ0Ody (ORCPT ); Tue, 27 Oct 2020 10:33:54 -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 4226520709; Tue, 27 Oct 2020 14:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809233; bh=U2L4TI+ODW1DfSENXpsKzJMS8rsBSGdviXkUOtLUq+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zuvmPazy2eZmdkbi3pKPzGrW4QCYST9IU/GobPrp9+RAoGQ85aDMgs1nS8FZbw1SM F/zR0QkKtgMgFTXq8xSp+YUbqhzvb3Z1u2/TxzYCgTqYgLkoyJoR/reJlYSvSXO9kt M1sjgJxw38oVIKq7/MXlAdVqHuR97lSaLLwLpnow= 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.4 124/408] VMCI: check return value of get_user_pages_fast() for errors Date: Tue, 27 Oct 2020 14:51:02 +0100 Message-Id: <20201027135500.860797084@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: 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