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: <70eb72e0-16c6-4b8e-94f6-a2bae5158502@fujitsu.com>
Date: Mon, 29 Apr 2024 08:35:43 +0000
From: "Zhijian Li (Fujitsu)" <lizhijian@...itsu.com>
To: "dave@...olabs.net" <dave@...olabs.net>, "jonathan.cameron@...wei.com"
	<jonathan.cameron@...wei.com>, "dave.jiang@...el.com" <dave.jiang@...el.com>,
	"alison.schofield@...el.com" <alison.schofield@...el.com>,
	"vishal.l.verma@...el.com" <vishal.l.verma@...el.com>, "ira.weiny@...el.com"
	<ira.weiny@...el.com>, "dan.j.williams@...el.com" <dan.j.williams@...el.com>,
	"linux-cxl@...r.kernel.org" <linux-cxl@...r.kernel.org>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] cxl/region: Fix missing put_device(region_dev)



TBH, even though this patch seems correct, there are still a few
to_cxl_region() callers where they dereference the return value directly
without checking if it's NULL.

So I'm fine to drop this one because to_cxl_region() will trigger a WARN before
returning NULL.

static struct cxl_region *to_cxl_region(struct device *dev)
{
         if (dev_WARN_ONCE(dev, dev->type != &cxl_region_type,
                           "not a cxl_region device\n"))
                 return NULL;
                                                                                 
         return container_of(dev, struct cxl_region, dev);
}


Let me know your thoughts.

Thanks
Zhijian

On 29/04/2024 09:31, Li Zhijian wrote:
>>          mutex_lock(&cxlrd->range_lock);
>>          region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa,
>>                                         match_region_by_range);
>>          if (!region_dev)
>>                  cxlr = construct_region(cxlrd, cxled);
>>          else
>>                  cxlr = to_cxl_region(region_dev);
>>          mutex_unlock(&cxlrd->range_lock);
>>
>>          rc = PTR_ERR_OR_ZERO(cxlr);
>>          if (rc)
>>                  goto out;
>>
>>          if (!region_dev)
>>                  region_dev = &cxlr->dev;
> 
> When to_cxl_region(region_dev) fails, put_device(region_dev) should be
> called to decrease the reference count added by device_find_child().
> 
> Simply put_device(region_dev) if region_dev is valid in the error path.
> 
> Fixes: a32320b71f08 ("cxl/region: Add region autodiscovery")
> Signed-off-by: Li Zhijian <lizhijian@...itsu.com>
> ---
>   drivers/cxl/core/region.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 3c80aa263a65..75390865382f 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3117,8 +3117,9 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
>   				p->res);
>   	}
>   
> -	put_device(region_dev);
>   out:
> +	if (region_dev)
> +		put_device(region_dev);
>   	put_device(cxlrd_dev);
>   	return rc;
>   }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ