From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753042AbdHXNBV (ORCPT ); Thu, 24 Aug 2017 09:01:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60800 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753008AbdHXNBS (ORCPT ); Thu, 24 Aug 2017 09:01:18 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8318882FB Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=bhe@redhat.com Date: Thu, 24 Aug 2017 21:01:10 +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: <20170824130110.GI19768@x1> References: <1503575807-15746-1-git-send-email-bhe@redhat.com> <20170824121137.dgsy57bq3qsjvjqj@mwanda> <20170824122251.GG19768@x1> <20170824123226.57twp5sdh246l5kz@mwanda> <20170824124733.GH19768@x1> <20170824125311.ymx27viis6rnhozy@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170824125311.ymx27viis6rnhozy@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.28]); Thu, 24 Aug 2017 13:01:18 +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:53pm, Dan Carpenter wrote: > On Thu, Aug 24, 2017 at 08:47:33PM +0800, Baoquan He wrote: > > On 08/24/17 at 03:32pm, Dan Carpenter wrote: > > > Take a look at this code for example. But all the places which call > > > get_domain() are the same: > > > > > > drivers/iommu/amd_iommu.c > > > 2648 page = virt_to_page(virt_addr); > > > 2649 size = PAGE_ALIGN(size); > > > 2650 > > > 2651 domain = get_domain(dev); > > > ^^^^^^^^^^^^^^ > > > imagined get_domain() returns NULL. > > > > > > 2652 if (IS_ERR(domain)) > > > 2653 goto free_mem; > > > 2654 > > > 2655 dma_dom = to_dma_ops_domain(domain); > > > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > > This will Oops. > > > > I see, it's a problem. Thanks for telling! > > > > How about below change? But I am not very sure which errno should be > > picked, seems the latter one, EBUSY is better since it has passed the > > check_device() checking. > > Looks good to me. You know better than I do which errno is best, so > I'll leave that to you. OK, thanks! Then let me post v2 with it.