Skip to contentSkip to conversation

netfilter: nft_ct: fix use after free when attaching zone template

PATCH Applied Florian Westphal 2 participants 2 messages Jan 23, 2022 – Jan 26, 2022

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_ct: fix use after free when attaching zone template

The conversion erronously removed the refcount increment. In case we can use the percpu template, we need to increment the refcount, else it will be released when the skb gets freed.

In case the slowpath is taken, the new template already has a refcount of 1.

Fixes 719774377622 ("netfilter: conntrack: convert to refcount_t api")
---
 net/netfilter/nft_ct.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nft_ct.c +4 -1
index 518d96c8c247..5adf8bb628a8 100644
@@ -260,9 +260,12 @@ static void nft_ct_set_zone_eval(const struct nft_expr *expr,
 	ct = this_cpu_read(nft_ct_pcpu_template);
 
 	if (likely(refcount_read(&ct->ct_general.use) == 1)) {
+		refcount_inc(&ct->ct_general.use);
 		nf_ct_zone_add(ct, &zone);
 	} else {
-		/* previous skb got queued to userspace */
+		/* previous skb got queued to userspace, allocate temporary
+		 * one until percpu template can be reused.
+		 */
 		ct = nf_ct_tmpl_alloc(nft_net(pkt), &zone, GFP_ATOMIC);
 		if (!ct) {
 			regs->verdict.code = NF_DROP;
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Florian Westphal

The conversion erronously removed the refcount increment. In case we can use the percpu template, we need to increment the refcount, else it will be released when the skb gets freed.

In case the slowpath is taken, the new template already has a refcount of 1.

Applied, thanks