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]
Date:   Tue, 26 Nov 2019 18:24:47 +0800
From:   Wen Yang <wenyang@...ux.alibaba.com>
To:     Sudeep Holla <sudeep.holla@....com>
Cc:     Arnd Bergmann <arnd@...db.de>,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] firmware: arm_scmi: avoid double free in error flow



On 2019/11/26 12:13 上午, Sudeep Holla wrote:
> On Mon, Nov 25, 2019 at 11:54:09PM +0800, Wen Yang wrote:
>> If device_register() fails, both put_device() and kfree()
>> are called, ending with a double free of the scmi_dev.
>>
> 
> Correct.
> 
>> Calling kfree() is needed only when a failure happens between the
>> allocation of the scmi_dev and its registration, so move it to
>> there and remove it from the error flow.
>>
> 
> kstrdup_const can fail and in that case device is not yet registered,
> so we need to free. Since device_register() calls put_device() on failure
> too, I would just drop it as it's unnecessary, not sure why I have added
> it in the first place. Can you re-spin the patch dropping put_device
> and renaming put_dev label to something like free_const.
> 
> --
> Regards,
> Sudeep
> 

Hi Sudeep,
Thanks for your comments.
Let's check the code like this:

int device_register(struct device *dev)
{
         device_initialize(dev);   --> Initialize kobj-> kref to 1
         return device_add(dev);
}

int device_add(struct device *dev)
{
...
         dev = get_device(dev);  --> kobj-> kref increases by 1
...
done:
         put_device(dev);  --> kobj-> kref decreases by 1 and is now 1
         return error;
...
}

So we also need to call put_device (),
and the original patch should be fine.
Please kindly help to check again, thank you.

--
Regards,
Wen








Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ