Skip to content

Commit bcb74e1

Browse files
marceloleitnerdavem330
authored andcommitted
net/sched: act_ct: fix ref leak when switching zones
When switching zones or network namespaces without doing a ct clear in between, it is now leaking a reference to the old ct entry. That's because tcf_ct_skb_nfct_cached() returns false and tcf_ct_flow_table_lookup() may simply overwrite it. The fix is to, as the ct entry is not reusable, free it already at tcf_ct_skb_nfct_cached(). Reported-by: Florian Westphal <fw@strlen.de> Fixes: 2f131de ("net/sched: act_ct: Fix flow table lookup after ct clear or switching zones") Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5ae6acf commit bcb74e1

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

net/sched/act_ct.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,22 +666,25 @@ static bool tcf_ct_skb_nfct_cached(struct net *net, struct sk_buff *skb,
666666
if (!ct)
667667
return false;
668668
if (!net_eq(net, read_pnet(&ct->ct_net)))
669-
return false;
669+
goto drop_ct;
670670
if (nf_ct_zone(ct)->id != zone_id)
671-
return false;
671+
goto drop_ct;
672672

673673
/* Force conntrack entry direction. */
674674
if (force && CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) {
675675
if (nf_ct_is_confirmed(ct))
676676
nf_ct_kill(ct);
677677

678-
nf_ct_put(ct);
679-
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
680-
681-
return false;
678+
goto drop_ct;
682679
}
683680

684681
return true;
682+
683+
drop_ct:
684+
nf_ct_put(ct);
685+
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
686+
687+
return false;
685688
}
686689

687690
/* Trim the skb to the length specified by the IP/IPv6 header,

0 commit comments

Comments
 (0)