Skip to content

Commit

Permalink
net/sched: act_ct: fix ref leak when switching zones
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Marcelo Ricardo Leitner authored and David S. Miller committed Mar 27, 2022
1 parent 5ae6acf commit bcb74e1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions net/sched/act_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,22 +666,25 @@ static bool tcf_ct_skb_nfct_cached(struct net *net, struct sk_buff *skb,
if (!ct)
return false;
if (!net_eq(net, read_pnet(&ct->ct_net)))
return false;
goto drop_ct;
if (nf_ct_zone(ct)->id != zone_id)
return false;
goto drop_ct;

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

nf_ct_put(ct);
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);

return false;
goto drop_ct;
}

return true;

drop_ct:
nf_ct_put(ct);
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);

return false;
}

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

0 comments on commit bcb74e1

Please sign in to comment.