Skip to content

Commit ec5b0f6

Browse files
edumazetkuba-moo
authored andcommitted
net/sched: cls_u32: fix possible leak in u32_init_knode()
While investigating a related syzbot report, I found that whenever call to tcf_exts_init() from u32_init_knode() is failing, we end up with an elevated refcount on ht->refcnt To avoid that, only increase the refcount after all possible errors have been evaluated. Fixes: b9a24bb ("net_sched: properly handle failure case of tcf_exts_init()") Signed-off-by: Eric Dumazet <[email protected]> Cc: Cong Wang <[email protected]> Cc: Jiri Pirko <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3db09e7 commit ec5b0f6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/sched/cls_u32.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,6 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
815815
new->flags = n->flags;
816816
RCU_INIT_POINTER(new->ht_down, ht);
817817

818-
/* bump reference count as long as we hold pointer to structure */
819-
if (ht)
820-
ht->refcnt++;
821-
822818
#ifdef CONFIG_CLS_U32_PERF
823819
/* Statistics may be incremented by readers during update
824820
* so we must keep them in tact. When the node is later destroyed
@@ -840,6 +836,10 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
840836
return NULL;
841837
}
842838

839+
/* bump reference count as long as we hold pointer to structure */
840+
if (ht)
841+
ht->refcnt++;
842+
843843
return new;
844844
}
845845

0 commit comments

Comments
 (0)