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] [day] [month] [year] [list]
Message-ID: <78adf4cf-e43d-fa1b-1d65-43c25e0cba6b@huawei.com>
Date:   Sat, 7 Oct 2023 17:15:06 +0800
From:   Ruan Jinjie <ruanjinjie@...wei.com>
To:     Russ Weight <russell.h.weight@...el.com>, <mdf@...nel.org>,
        <hao.wu@...el.com>, <yilun.xu@...el.com>, <trix@...hat.com>,
        <linux-fpga@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH RESEND] fpga: region: Fix possible memory leak in
 fpga_region_register_full()



On 2023/9/28 23:45, Russ Weight wrote:
> 
> 
> On 9/28/23 02:16, Jinjie Ruan wrote:
>> If device_register() fails in fpga_region_register_full(), the region
>> allocated by kzalloc() and the id allocated by ida_alloc() also need be
>> freed otherwise will cause memory leak.
>>
>> Fixes: 8886a579744f ("fpga: region: Use standard dev_release for class driver")
>> Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
>> ---
>>  drivers/fpga/fpga-region.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
>> index b364a929425c..9dc6314976ef 100644
>> --- a/drivers/fpga/fpga-region.c
>> +++ b/drivers/fpga/fpga-region.c
>> @@ -228,12 +228,13 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info *
>>  
>>  	ret = device_register(&region->dev);
> 
> The comments for device_register() say:
> 
>  * NOTE: _Never_ directly free @dev after calling this function, even
>  * if it returned an error! Always use put_device() to give up the
>  * reference initialized in this function instead.
> 
> Note that dev is embedded in the region structure, so freeing region
> means freeing dev.
> 
> The expectation is that after device_register() has been called, even
> if it returns an error, put_device() is used to lower the reference
> count. When the reference count is zero, the fpga_region_dev_release()
> function is called. fpga_region_dev_release() frees calls ida_free()
> and frees the region.

Right!

> 
> Have you observed different behavior? Do you have evidence of a memory
> leak?

I have noticed a memory leak in using fpga_region_register_full() in
fpga-region-test.c. I'll send the patch sooner.

> 
> Thanks,
> - Russ
> 
>>  	if (ret) {
>> -		put_device(&region->dev);
>> -		return ERR_PTR(ret);
>> +		goto err_put_device;
>>  	}
>>  
>>  	return region;
>>  
>> +err_put_device:
>> +	put_device(&region->dev);
>>  err_remove:
>>  	ida_free(&fpga_region_ida, id);
>>  err_free:
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ