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: <c6ae7eda-0792-2ac0-e524-eb000366b50f@huawei.com>
Date:   Tue, 24 May 2022 11:15:44 +0800
From:   Kefeng Wang <wangkefeng.wang@...wei.com>
To:     Guenter Roeck <linux@...ck-us.net>
CC:     <linux@...linux.org.uk>, <linux-kernel@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>, <robh@...nel.org>
Subject: Re: [PATCH] amba: fix refcount underflow if amba_device_add() fails


On 2022/5/24 11:09, Guenter Roeck wrote:
> On Tue, May 24, 2022 at 10:51:39AM +0800, Kefeng Wang wrote:
>> "ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
>> to a refcount underflow if amba_device_add() fails, which called by
>> of_amba_device_create(), the of_amba_device_create() already exists
>> the error handling, so amba_put_device() only need to be added into
>> amba_deferred_retry().
>>
>> Reported-by: Guenter Roeck <linux@...ck-us.net>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@...wei.com>
> Tested-by: Guenter Roeck <linux@...ck-us.net>

Thanks.

PS: I also test with kmemleak, this could also fix previous memory leak 
issue.

>
> Thanks,
> Guenter
>
>> ---
>>   drivers/amba/bus.c | 8 ++------
>>   1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index 0e3ed5eb367b..0cb20324da16 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>>   		goto skip_probe;
>>   
>>   	ret = amba_read_periphid(dev);
>> -	if (ret) {
>> -		if (ret != -EPROBE_DEFER) {
>> -			amba_device_put(dev);
>> -			goto err_out;
>> -		}
>> +	if (ret)
>>   		goto err_release;
>> -	}
>>   
>>   skip_probe:
>>   	ret = device_add(&dev->dev);
>> @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
>>   			continue;
>>   
>>   		list_del_init(&ddev->node);
>> +		amba_device_put(ddev->dev);
>>   		kfree(ddev);
>>   	}
>>   
>> -- 
>> 2.35.3
>>
> .

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ