Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp510960rwd; Wed, 14 Jun 2023 20:35:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZiQ3rHp7K5wctK8RQjponJC3qg69Hj/eFdkY3c4tNS5wujLcdXnGk1ihTal49y89AxyAj X-Received: by 2002:aa7:cb55:0:b0:514:a685:aa3b with SMTP id w21-20020aa7cb55000000b00514a685aa3bmr9442714edt.41.1686800121494; Wed, 14 Jun 2023 20:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686800121; cv=none; d=google.com; s=arc-20160816; b=eGc0oSDw+MrznPm566IeLe+fINbnVvLWbK5wHfDyzhiqU931Li94mFgAaUQSxeP7id BhHeHA32G3dCtj/l1ceE2wWemWVVNjjFqjHiu1sw3yFO1kh8a6K2i1qiVS5Z5EmMXhxo fu8bcPA/K5H8VrAekF3OnAQhFfZa6lfSOk7BQE7R1iGPUvD2mwGriIpJ4HRkzH0Mmq9K KBXVPxN2QzzpeP8EMA5sw3Z5ohXr1HSADTS86eMkN5oOUZMdjLnwz5JfrRtXgu+NAlWb wmEmSAjTz/2aARNa7TddCehdiq6heihnS9l3570sQcqhGZAYDWSGmkrnEpT5HmzcYAf6 xGYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=zL+b4NhSd0uNv/NBW7pqZ1KrqZynprHOEfqg361c8vw=; b=HjqjosRlcmLD9LA9QE5sD0cvmAOvUiddy5z9AP2oc1ByF3BrecGDBoUoVCtFv0PZy9 TArKDHC+ShHW/geHwxmS/cJL5vI5frChi6xGQ2zpG6pZu7j61myBTyKk+KHarBJZTyQL prEqWPX0lo3sp2rVdbi0908HtzuzULZCOEmD8vZ7sJF2ftrI+trUltx32WtlylIypSQd JjLMWVgPkbDi0j+kbKQAtsxTIlUbqGBNt3BGY/rkgGj2E3GqZ/Tt/YHMNp2bE5uA+qBZ it4ioArhxJldqjplAWHuA3UZnLZLjWmL1wj8LnWO78FAY6TddUhn2U+FLeJNr2081Apb DtUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0RqUzv5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a056402060d00b005148e4a2d74si10150200edv.71.2023.06.14.20.34.56; Wed, 14 Jun 2023 20:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0RqUzv5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237875AbjFOCcf (ORCPT + 99 others); Wed, 14 Jun 2023 22:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjFOCce (ORCPT ); Wed, 14 Jun 2023 22:32:34 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67B332110 for ; Wed, 14 Jun 2023 19:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686796353; x=1718332353; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=2XYz/4kLcutFLO2VPQ0RDJjaX/PmjaxFr9McZyU/Aio=; b=P0RqUzv5UBPMBqfny/Th+vSqRwvhj3dXBKX/baL5rguZa4+aZsNHAOWk lvExCKa0keXzzHjrZJpt71n2aO5pxe5wCPFuoeehywU/JHXA5w9k5ogg4 ERzOhpFozxxhm6A4lKuiu1IiWcBeyIfIFniIFKz3gGSuZW3Zo82CHa0Ck sS/BUeXURVkqQN0Pf5U+6+OAUEOGvtcn1a8fPmmNyumhYskJ6sKrV/8bu 9b9XA6YeHxHkPJ6cKbs+Aed07CsWomdd3j04GQglxlPoGKr/3RKuQxP30 phPfWaIt9LT2yUa06zOaoLkfEhBhjalEkvfF2dboyudY0xjyfioqK4UNw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10741"; a="348460348" X-IronPort-AV: E=Sophos;i="6.00,243,1681196400"; d="scan'208";a="348460348" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2023 19:32:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10741"; a="825060419" X-IronPort-AV: E=Sophos;i="6.00,243,1681196400"; d="scan'208";a="825060419" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by fmsmga002.fm.intel.com with ESMTP; 14 Jun 2023 19:32:31 -0700 Message-ID: Date: Thu, 15 Jun 2023 10:31:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cc: baolu.lu@linux.intel.com, will@kernel.org, robin.murphy@arm.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu: Fix missing check for return value of iommu_group_get() Content-Language: en-US To: Chenyuan Mi , joro@8bytes.org References: <20230614154308.118783-1-cymi20@fudan.edu.cn> From: Baolu Lu In-Reply-To: <20230614154308.118783-1-cymi20@fudan.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/14/23 11:43 PM, Chenyuan Mi wrote: > The iommu_group_get() function may return NULL, which may > cause null pointer deference, and most other callsites of > iommu_group_get() do Null check. Add Null check for return > value of iommu_group_get(). > > Found by our static analysis tool. > > Signed-off-by: Chenyuan Mi > --- > drivers/iommu/iommu.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index f1dcfa3f1a1b..ef3483e75511 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -3217,6 +3217,8 @@ EXPORT_SYMBOL_GPL(iommu_group_release_dma_owner); > void iommu_device_release_dma_owner(struct device *dev) > { > struct iommu_group *group = iommu_group_get(dev); > + if (!group) > + return; This interface should never be used in this way. Check the comments of this function: "Release the DMA ownership claimed by iommu_device_claim_dma_owner()." iommu group has been checked in the claim api. If any driver misuses this api, a null pointer deference warning is better than ignoring silently. > > mutex_lock(&group->mutex); > if (group->owner_cnt > 1) > @@ -3329,6 +3331,8 @@ void iommu_detach_device_pasid(struct iommu_domain *domain, struct device *dev, > ioasid_t pasid) > { > struct iommu_group *group = iommu_group_get(dev); > + if (!group) > + return; Ditto... > > mutex_lock(&group->mutex); > __iommu_remove_group_pasid(group, pasid); Best regards, baolu