[PATCH 4.19 102/293] net: sched: Fix qdisc_rate_table refcount leak when get tcf_block failed

From: Greg Kroah-Hartman
Date: Mon Sep 20 2021 - 13:44:52 EST


From: Xiyu Yang <xiyuyang19@xxxxxxxxxxxx>

[ Upstream commit c66070125837900163b81a03063ddd657a7e9bfb ]

The reference counting issue happens in one exception handling path of
cbq_change_class(). When failing to get tcf_block, the function forgets
to decrease the refcount of "rtab" increased by qdisc_put_rtab(),
causing a refcount leak.

Fix this issue by jumping to "failure" label when get tcf_block failed.

Fixes: 6529eaba33f0 ("net: sched: introduce tcf block infractructure")
Signed-off-by: Xiyu Yang <xiyuyang19@xxxxxxxxxxxx>
Reviewed-by: Cong Wang <cong.wang@xxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/1630252681-71588-1-git-send-email-xiyuyang19@xxxxxxxxxxxx
Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
net/sched/sch_cbq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index ebc3c8c7e666..bc62e1b24653 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1616,7 +1616,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
err = tcf_block_get(&cl->block, &cl->filter_list, sch, extack);
if (err) {
kfree(cl);
- return err;
+ goto failure;
}

if (tca[TCA_RATE]) {
--
2.30.2