All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: flowtable: prefer refcount_inc
@ 2022-07-07 19:30 Florian Westphal
  2022-07-20 22:57 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2022-07-07 19:30 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

With refcount_inc_not_zero, we'd also need a smp_rmb or similar,
followed by a test of the CONFIRMED bit.

However, the ct pointer is taken from skb->_nfct, its refcount must
not be 0 (else, we'd already have a use-after-free bug).

Use refcount_inc() instead to clarify the ct refcount is expected to
be at least 1.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 A followp to 'netfilter: conntrack: fix crash due to confirmed bit load reordering',
 but target next as current code works fine.

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index f2def06d1070..cca2358c10a1 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -53,14 +53,14 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct)
 {
 	struct flow_offload *flow;
 
-	if (unlikely(nf_ct_is_dying(ct) ||
-	    !refcount_inc_not_zero(&ct->ct_general.use)))
+	if (unlikely(nf_ct_is_dying(ct)))
 		return NULL;
 
 	flow = kzalloc(sizeof(*flow), GFP_ATOMIC);
 	if (!flow)
-		goto err_ct_refcnt;
+		return NULL;
 
+	refcount_inc(&ct->ct_general.use);
 	flow->ct = ct;
 
 	flow_offload_fill_dir(flow, FLOW_OFFLOAD_DIR_ORIGINAL);
@@ -72,11 +72,6 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct)
 		__set_bit(NF_FLOW_DNAT, &flow->flags);
 
 	return flow;
-
-err_ct_refcnt:
-	nf_ct_put(ct);
-
-	return NULL;
 }
 EXPORT_SYMBOL_GPL(flow_offload_alloc);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nf-next] netfilter: flowtable: prefer refcount_inc
  2022-07-07 19:30 [PATCH nf-next] netfilter: flowtable: prefer refcount_inc Florian Westphal
@ 2022-07-20 22:57 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-07-20 22:57 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Thu, Jul 07, 2022 at 09:30:56PM +0200, Florian Westphal wrote:
> With refcount_inc_not_zero, we'd also need a smp_rmb or similar,
> followed by a test of the CONFIRMED bit.
> 
> However, the ct pointer is taken from skb->_nfct, its refcount must
> not be 0 (else, we'd already have a use-after-free bug).
> 
> Use refcount_inc() instead to clarify the ct refcount is expected to
> be at least 1.

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-20 22:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 19:30 [PATCH nf-next] netfilter: flowtable: prefer refcount_inc Florian Westphal
2022-07-20 22:57 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.