Skip to contentSkip to conversation

nfct: fix counter-reset without hashtable

PATCH Applied Corubba Smith 2 participants 4 messages Mar 25, 2025 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfct: fix counter-reset without hashtable

The dump_reset_handler will try to update the hashtable regardless of whether it is used (and thus initialized), which results in a segfault if it isn't. Instead just short-circuit the handler, and skip any further result processing because it's not used in this case anyway. All flow counters in conntrack are reset regardless of the return value of the handler/callback.

---
 input/flow/ulogd_inpflow_NFCT.c | 3 +++
 1 file changed, 3 insertions(+)
input/flow/ulogd_inpflow_NFCT.c +3 -0
index 93edb76..cdda741 100644
@@ -989,6 +989,9 @@ dump_reset_handler(enum nf_conntrack_msg_type type,
 	int ret = NFCT_CB_CONTINUE, rc, id;
 	struct ct_timestamp *ts;
 
+	if (!cpi->ct_active)
+		return NFCT_CB_STOP;
+
 	switch(type) {
 	case NFCT_T_UPDATE:
 		id = hashtable_hash(cpi->ct_active, ct);

--
2.49.0

maintainer
#1 lore raw
Quoted 6 lines · Corubba Smith

The dump_reset_handler will try to update the hashtable regardless of whether it is used (and thus initialized), which results in a segfault if it isn't. Instead just short-circuit the handler, and skip any further result processing because it's not used in this case anyway. All flow counters in conntrack are reset regardless of the return value of the handler/callback.

How can this happen?
constructor_nfct (->start()) will return an error if ct_active table cannot be allocated/is disabled?

#2 lore raw
Quoted 8 lines · Florian Westphal
Quoted 6 lines · Corubba Smith

The dump_reset_handler will try to update the hashtable regardless of whether it is used (and thus initialized), which results in a segfault if it isn't. Instead just short-circuit the handler, and skip any further result processing because it's not used in this case anyway. All flow counters in conntrack are reset regardless of the return value of the handler/callback.

Quoted 4 lines

How can this happen?
constructor_nfct (->start()) will return an error if ct_active table cannot be allocated/is disabled?

In event mode the hashtable is optional, and sending SIGUSR2 to ulogd will call get_ctr_zero().

--
Corubba

maintainer Applied
#3 lore raw
Quoted 9 lines · Corubba Smith
Quoted 8 lines · Florian Westphal
Quoted 6 lines · Corubba Smith

The dump_reset_handler will try to update the hashtable regardless of whether it is used (and thus initialized), which results in a segfault if it isn't. Instead just short-circuit the handler, and skip any further result processing because it's not used in this case anyway. All flow counters in conntrack are reset regardless of the return value of the handler/callback.

Quoted 7 lines
Quoted 4 lines

How can this happen?
constructor_nfct (->start()) will return an error if ct_active table cannot be allocated/is disabled?

In event mode the hashtable is optional, and sending SIGUSR2 to ulogd will call get_ctr_zero().

Thanks, applied the patch with above sentence included in the commit message.