Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp501771ybh; Wed, 18 Mar 2020 04:03:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtDG7/CW8CgZMZGDNAKWWJhIAvC2PaOZxzgOsa6WwkERxGoQ7gGfzuh9TTgFQ4SG140FN+u X-Received: by 2002:a05:6830:60a:: with SMTP id w10mr3450939oti.292.1584529412713; Wed, 18 Mar 2020 04:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584529412; cv=none; d=google.com; s=arc-20160816; b=cFRmscUSC/8olNjeipjN1I9VfiDV7psPtXTSueNMfx03LCVemvD01AeMjYpxnZGSg4 uchIJC+rAlso6VipKGLk/SGwgovnm4usnLgi1GfrkSHHOk+4VolXzRSwh1deSN7MbaNP 1wDhCwL09k0iKmJAoiSQrx67TPrZIAi3EjGs4+NQGtSoCRZBO8Q/pixc7fDpaC+aMJm5 qhRFTrxWRcF26qTfPpI2vp6swjLdiFtEm+X/Oa5TRvAgiUhTEIMPOtHXDbcQMtV6egR3 94E8cfCHyoZo55753RmqB+qNFl+8ui6GBh3/5EQjToMvBlStmBH+R4O/eZLBZBYRg9aX kxsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=uuzthq4QkqQg0Q/V4tBiQU2pHBpe0ASvbverVtY746M=; b=C0x9fhrFLoPFqI+uzyxO2kgz4eOHM5307pXBHGOQzFRuHvwdTmAkMd0a2urUXsDEaN NMP06ktEtbWqL0quro0iQp3IHFHD6ZcDWOWdVLFhImebT0P8sYEmFsRpW+GNOzZXoNKf AdZV8gf9elYuFMQubOyy7nyZYH2Mcs51xltki0B3rF//bXzu2TzqarNK8+aqX3ooedv3 FpHn4oiiQoR3QB+E9HH3Z5wteCXEwRoZuTv+BXeKHTRXa7qpJyZPCULXrHQqoLagQdKO 4YnCRqvSVEwsegtuzAQxO2X1U2HFmpNy/It1Edjx1zLQFqt6qmn1CHqYOFgl89XanhNV CCMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z1anWoqP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o25si3195822otk.28.2020.03.18.04.03.19; Wed, 18 Mar 2020 04:03:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z1anWoqP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727715AbgCRLCH (ORCPT + 99 others); Wed, 18 Mar 2020 07:02:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:47810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727687AbgCRLCG (ORCPT ); Wed, 18 Mar 2020 07:02:06 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BAA0E2076D; Wed, 18 Mar 2020 11:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584529326; bh=ZNJbZkH0nXoHrj4DDwLg8d1qU7rSUHWk+hrUrCsVZWI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=z1anWoqPAz0ydzDH4yHNE+g9oIyu5kuia5JrJZB6ql+zFhErDrFEJaML4T/jNdWXb CG6BzUJIFjNncmVTqoo9xd+U9Dn0jRNIeRdll160Q0bp96E8CyZSCa5o9Y9JWXGc/0 vWRLbmvfUqjoPGSF8WA48HQnwDDF9WEgbzaS5r8c= Date: Wed, 18 Mar 2020 12:02:04 +0100 From: Greg Kroah-Hartman To: Xiyu Yang Cc: Arnd Bergmann , Xin Tan , Alexios Zavras , Vishnu DASA , Thomas Gleixner , Allison Randal , Ira Weiny , Mike Marshall , linux-kernel@vger.kernel.org, yuanxzhang@fudan.edu.cn, kjlu@umn.edu Subject: Re: [PATCH] VMCI: Fix NULL pointer dereference on context ptr Message-ID: <20200318110204.GB2305113@kroah.com> References: <1584426607-89366-1-git-send-email-xiyuyang19@fudan.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1584426607-89366-1-git-send-email-xiyuyang19@fudan.edu.cn> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 17, 2020 at 02:29:57PM +0800, Xiyu Yang wrote: > The refcount wrapper function vmci_ctx_get() may return NULL > context ptr. Thus, we need to add a NULL pointer check > before its dereference. > > Signed-off-by: Xiyu Yang > Signed-off-by: Xin Tan > --- > drivers/misc/vmw_vmci/vmci_context.c | 2 ++ > drivers/misc/vmw_vmci/vmci_queue_pair.c | 17 +++++++++++------ > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c > index 16695366ec92..a20878fba374 100644 > --- a/drivers/misc/vmw_vmci/vmci_context.c > +++ b/drivers/misc/vmw_vmci/vmci_context.c > @@ -898,6 +898,8 @@ void vmci_ctx_rcv_notifications_release(u32 context_id, > bool success) > { > struct vmci_ctx *context = vmci_ctx_get(context_id); > + if (context == NULL) > + return; Same comment as on your other patch. And is this a v2? > > spin_lock(&context->lock); > if (!success) { > diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c > index 8531ae781195..2ecb22d08692 100644 > --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c > +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c > @@ -1575,11 +1575,14 @@ static int qp_broker_attach(struct qp_broker_entry *entry, > */ > > create_context = vmci_ctx_get(entry->create_id); > - supports_host_qp = vmci_ctx_supports_host_qp(create_context); > - vmci_ctx_put(create_context); > + if (!create_context) { > + supports_host_qp = > + vmci_ctx_supports_host_qp(create_context); > + vmci_ctx_put(create_context); > > - if (!supports_host_qp) > - return VMCI_ERROR_INVALID_RESOURCE; > + if (!supports_host_qp) > + return VMCI_ERROR_INVALID_RESOURCE; > + } > } > > if ((entry->qp.flags & ~VMCI_QP_ASYMM) != (flags & ~VMCI_QP_ASYMM_PEER)) > @@ -1808,7 +1811,8 @@ static int qp_alloc_host_work(struct vmci_handle *handle, > pr_devel("queue pair broker failed to alloc (result=%d)\n", > result); > } > - vmci_ctx_put(context); > + if (context) > + vmci_ctx_put(context); can't vmci_ctx_put() take a NULL pointer? If not, fix this that way please. thanks, greg k-h