From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752563AbdHXMW4 (ORCPT ); Thu, 24 Aug 2017 08:22:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41636 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751272AbdHXMWz (ORCPT ); Thu, 24 Aug 2017 08:22:55 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9967E806A2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=bhe@redhat.com Date: Thu, 24 Aug 2017 20:22:51 +0800 From: Baoquan He To: Dan Carpenter Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, joro@8bytes.org Subject: Re: [PATCH] iommu/amd: Check if domain is NULL before dereference it Message-ID: <20170824122251.GG19768@x1> References: <1503575807-15746-1-git-send-email-bhe@redhat.com> <20170824121137.dgsy57bq3qsjvjqj@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170824121137.dgsy57bq3qsjvjqj@mwanda> User-Agent: Mutt/1.7.0 (2016-08-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 Aug 2017 12:22:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/24/17 at 03:11pm, Dan Carpenter wrote: > On Thu, Aug 24, 2017 at 07:56:47PM +0800, Baoquan He wrote: > > In get_domain(), 'domain' could still be NULL before it's passed to > > dma_ops_domain() to dereference. For safety, check if 'domain' is > > NULL before passing to dma_ops_domain(). > > > > Reported-by: Dan Carpenter > > Signed-off-by: Baoquan He > > --- > > drivers/iommu/amd_iommu.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c > > index 16f1e6af00b0..2e2d5e6a13b3 100644 > > --- a/drivers/iommu/amd_iommu.c > > +++ b/drivers/iommu/amd_iommu.c > > @@ -2262,7 +2262,7 @@ static struct protection_domain *get_domain(struct device *dev) > > domain = to_pdomain(io_domain); > > attach_device(dev, domain); > > } > > - if (!dma_ops_domain(domain)) > > + if (domain && !dma_ops_domain(domain)) > > return ERR_PTR(-EBUSY); > > > > return domain; > > This still doesn't look right. None of the callers can handle a NULL > domain. Here the NULL domain is on purpose. In kdump kernel if iommu is pre-enabled, just stop attach the device to domain until the device driver init. So here in driver init when call get_domain(), if found get_dev_data(dev)->defer_attach is true, we just do the attachment of device to domain. Not sure if I got what you mean about 'callers'.