Skip to contentSkip to conversation

net/sched: act_ct: fix ref leak when switching zones

PATCH New Vasiliy Kovalev 1 participant 1 message Apr 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/sched: act_ct: fix ref leak when switching zones

From: Marcelo Ricardo Leitner <[email protected]>

commit bcb74e132a76ce0502bb33d5b65533a4ed72d159 upstream.

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().

Fixes 2f131de361f6 ("net/sched: act_ct: Fix flow table lookup after ct clear or switching zones")

[ kovalev: bp to fix CVE-2022-49183; used nf_conntrack_put(&ct->ct_general)
instead of nf_ct_put(ct) due to the older kernel not yet having the conversion from the indirect call (see upstream commit 408bdcfce8df) ]

---
 net/sched/act_ct.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
net/sched/act_ct.c +9 -6
index d9748c917a50..d75f4b2b97da 100644
@@ -589,22 +589,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_conntrack_put(&ct->ct_general);
-		nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
-
-		return false;
+		goto drop_ct;
 	}
 
 	return true;
+
+drop_ct:
+	nf_conntrack_put(&ct->ct_general);
+	nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
+
+	return false;
 }
 
 /* Trim the skb to the length specified by the IP/IPv6 header,
Signature · 1 line
2.50.1