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: <20220128215604.xuqdpnnn4yjqfaoy@surface>
Date:   Fri, 28 Jan 2022 13:56:04 -0800
From:   Juan Vazquez <juvazq@...ux.microsoft.com>
To:     Miaoqian Lin <linmq006@...il.com>
Cc:     "K. Y. Srinivasan" <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-hyperv@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Drivers: hv: vmbus: Fix memory leak in
 vmbus_add_channel_kobj

On Wed, Jan 26, 2022 at 05:52:46AM +0000, Miaoqian Lin wrote:
> kobject_init_and_add() takes reference even when it fails.
> According to the doc of kobject_init_and_add():
> 
>    If this function returns an error, kobject_put() must be called to
>    properly clean up the memory associated with the object.
> 
> Fix memory leak by calling kobject_put().
> 
> Fixes: c2e5df616e1a ("vmbus: add per-channel sysfs info")
> Signed-off-by: Miaoqian Lin <linmq006@...il.com>
> ---
>  drivers/hv/vmbus_drv.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 17bf55fe3169..9e055697783b 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -2028,8 +2028,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
>  	kobj->kset = dev->channels_kset;
>  	ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL,
>  				   "%u", relid);
> -	if (ret)
> +	if (ret) {
> +		kobject_put(kobj);
>  		return ret;
> +	}
>  
>  	ret = sysfs_create_group(kobj, &vmbus_chan_group);
If sysfs_create_group() fails same cleanup I think is required.

Later kobject_uevent() may fail according to doc, but there is no error
handling, maybe a good moment to consider adding it and do same cleanup.
>  
> -- 
> 2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ