Commit 7b3dbf95 authored by Cong Wang's avatar Cong Wang Committed by Greg Kroah-Hartman

net_sched: fix a resource leak in tcindex_set_parms()

[ Upstream commit 52b5ae50 ]

Jakub noticed there is a potential resource leak in
tcindex_set_parms(): when tcindex_filter_result_init() fails
and it jumps to 'errout1' which doesn't release the memory
and resources allocated by tcindex_alloc_perfect_hash().

We should just jump to 'errout_alloc' which calls
tcindex_free_perfect_hash().

Fixes: b9a24bb7 ("net_sched: properly handle failure case of tcf_exts_init()")
Reported-by: default avatarJakub Kicinski <kuba@kernel.org>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent af746042
...@@ -365,7 +365,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -365,7 +365,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
err = tcindex_filter_result_init(&new_filter_result); err = tcindex_filter_result_init(&new_filter_result);
if (err < 0) if (err < 0)
goto errout1; goto errout_alloc;
if (old_r) if (old_r)
cr = r->res; cr = r->res;
...@@ -484,7 +484,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -484,7 +484,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
tcindex_free_perfect_hash(cp); tcindex_free_perfect_hash(cp);
else if (balloc == 2) else if (balloc == 2)
kfree(cp->h); kfree(cp->h);
errout1:
tcf_exts_destroy(&new_filter_result.exts); tcf_exts_destroy(&new_filter_result.exts);
errout: errout:
kfree(cp); kfree(cp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment