* [PATCH net] netlink: fix a memory leak on error path
@ 2019-03-22 10:58 Chengguang Xu
2019-03-22 11:03 ` Kirill Tkhai
0 siblings, 1 reply; 4+ messages in thread
From: Chengguang Xu @ 2019-03-22 10:58 UTC (permalink / raw)
To: davem; +Cc: keescook, ktkhai, netdev, linux-kernel, Chengguang Xu
In genl_register_family(), when idr_alloc() fails,
we forget to free family->attrbuf.
Note, some callers call genl_unregister_family() to clean up
on error path, it doesn't work because the family is inserted
to the global list in the nearly last step.
Fixes: 2ae0f17df1c ("genetlink: use idr to track families").
Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
net/netlink/genetlink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 25eeb6d2a75a..f0ec068e1d02 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -366,7 +366,7 @@ int genl_register_family(struct genl_family *family)
start, end + 1, GFP_KERNEL);
if (family->id < 0) {
err = family->id;
- goto errout_locked;
+ goto errout_free;
}
err = genl_validate_assign_mc_groups(family);
@@ -385,6 +385,7 @@ int genl_register_family(struct genl_family *family)
errout_remove:
idr_remove(&genl_fam_idr, family->id);
+errout_free:
kfree(family->attrbuf);
errout_locked:
genl_unlock_all();
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] netlink: fix a memory leak on error path
2019-03-22 10:58 [PATCH net] netlink: fix a memory leak on error path Chengguang Xu
@ 2019-03-22 11:03 ` Kirill Tkhai
2019-03-25 1:19 ` cgxu519
0 siblings, 1 reply; 4+ messages in thread
From: Kirill Tkhai @ 2019-03-22 11:03 UTC (permalink / raw)
To: Chengguang Xu, davem; +Cc: keescook, netdev, linux-kernel
Hi, Chengguang,
On 22.03.2019 13:58, Chengguang Xu wrote:
> In genl_register_family(), when idr_alloc() fails,
> we forget to free family->attrbuf.
>
> Note, some callers call genl_unregister_family() to clean up
> on error path, it doesn't work because the family is inserted
> to the global list in the nearly last step.
>
> Fixes: 2ae0f17df1c ("genetlink: use idr to track families").
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
have you seen https://patchwork.ozlabs.org/patch/1059834/ ?
Kirill
> ---
> net/netlink/genetlink.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
> index 25eeb6d2a75a..f0ec068e1d02 100644
> --- a/net/netlink/genetlink.c
> +++ b/net/netlink/genetlink.c
> @@ -366,7 +366,7 @@ int genl_register_family(struct genl_family *family)
> start, end + 1, GFP_KERNEL);
> if (family->id < 0) {
> err = family->id;
> - goto errout_locked;
> + goto errout_free;
> }
>
> err = genl_validate_assign_mc_groups(family);
> @@ -385,6 +385,7 @@ int genl_register_family(struct genl_family *family)
>
> errout_remove:
> idr_remove(&genl_fam_idr, family->id);
> +errout_free:
> kfree(family->attrbuf);
> errout_locked:
> genl_unlock_all();
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] netlink: fix a memory leak on error path
2019-03-22 11:03 ` Kirill Tkhai
@ 2019-03-25 1:19 ` cgxu519
2019-03-25 8:12 ` Kirill Tkhai
0 siblings, 1 reply; 4+ messages in thread
From: cgxu519 @ 2019-03-25 1:19 UTC (permalink / raw)
To: Kirill Tkhai, davem; +Cc: keescook, netdev, linux-kernel
On 3/22/19 7:03 PM, Kirill Tkhai wrote:
> Hi, Chengguang,
>
> On 22.03.2019 13:58, Chengguang Xu wrote:
>> In genl_register_family(), when idr_alloc() fails,
>> we forget to free family->attrbuf.
>>
>> Note, some callers call genl_unregister_family() to clean up
>> on error path, it doesn't work because the family is inserted
>> to the global list in the nearly last step.
>>
>> Fixes: 2ae0f17df1c ("genetlink: use idr to track families").
>> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> have you seen https://patchwork.ozlabs.org/patch/1059834/ ?
Sorry, I didn't notice that because I'm mainly working on linus-tree.
Please just ignore this patch.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] netlink: fix a memory leak on error path
2019-03-25 1:19 ` cgxu519
@ 2019-03-25 8:12 ` Kirill Tkhai
0 siblings, 0 replies; 4+ messages in thread
From: Kirill Tkhai @ 2019-03-25 8:12 UTC (permalink / raw)
To: cgxu519, davem; +Cc: keescook, netdev, linux-kernel
On 25.03.2019 04:19, cgxu519 wrote:
> On 3/22/19 7:03 PM, Kirill Tkhai wrote:
>> Hi, Chengguang,
>>
>> On 22.03.2019 13:58, Chengguang Xu wrote:
>>> In genl_register_family(), when idr_alloc() fails,
>>> we forget to free family->attrbuf.
>>>
>>> Note, some callers call genl_unregister_family() to clean up
>>> on error path, it doesn't work because the family is inserted
>>> to the global list in the nearly last step.
>>>
>>> Fixes: 2ae0f17df1c ("genetlink: use idr to track families").
>>> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
>> have you seen https://patchwork.ozlabs.org/patch/1059834/ ?
>
> Sorry, I didn't notice that because I'm mainly working on linus-tree.
> Please just ignore this patch.
Not a problem.
Some information about network development process you may find in
https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt
Kirill
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-25 8:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-22 10:58 [PATCH net] netlink: fix a memory leak on error path Chengguang Xu
2019-03-22 11:03 ` Kirill Tkhai
2019-03-25 1:19 ` cgxu519
2019-03-25 8:12 ` Kirill Tkhai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).