lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ffe919f3-f4f2-b378-947f-4cf704ad8950@linux.intel.com>
Date:   Tue, 3 Jan 2023 09:26:19 +0800
From:   Baolu Lu <baolu.lu@...ux.intel.com>
To:     Miaoqian Lin <linmq006@...il.com>, Joerg Roedel <joro@...tes.org>,
        Will Deacon <will@...nel.org>,
        Robin Murphy <robin.murphy@....com>,
        Kevin Tian <kevin.tian@...el.com>,
        Eric Auger <eric.auger@...hat.com>,
        Jason Gunthorpe <jgg@...pe.ca>, iommu@...ts.linux.dev,
        linux-kernel@...r.kernel.org
Cc:     baolu.lu@...ux.intel.com
Subject: Re: [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner

On 12/30/22 4:31 PM, Miaoqian Lin wrote:
> iommu_group_get() returns the group with the reference incremented.
> Move iommu_group_get() after owner check to fix the refcount leak.

An empty @owner is a more serious problem than refcount leak. It should
not happen, so a WARN_ON() was added there.

Anyway, your change makes the code better.

> 
> Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
> Signed-off-by: Miaoqian Lin <linmq006@...il.com>
> ---
>   drivers/iommu/iommu.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index de91dd88705b..3a7dd8b61fab 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3185,14 +3185,16 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner);
>    */
>   int iommu_device_claim_dma_owner(struct device *dev, void *owner)
>   {
> -	struct iommu_group *group = iommu_group_get(dev);
> +	struct iommu_group *group = NULL;

No need to set NULL to group.

>   	int ret = 0;
>   
> -	if (!group)
> -		return -ENODEV;
>   	if (WARN_ON(!owner))
>   		return -EINVAL;
>   
> +	group = iommu_group_get(dev);
> +	if (!group)
> +		return -ENODEV;
> +
>   	mutex_lock(&group->mutex);
>   	if (group->owner_cnt) {
>   		if (group->owner != owner) {

Others look good to me.

Reviewed-by: Lu Baolu <baolu.lu@...ux.intel.com>

--
Best regards,
baolu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ