Skip to contentSkip to conversation

netfilter: nf_conntrack: do not skip entries in /proc/net/nf_conntrack

PATCH In review Eric Dumazet 2 participants 2 messages Sep 24, 2025

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

PATCH 1/1 netfilter: nf_conntrack: do not skip entries in /proc/net/nf_conntrack

ct_seq_show() has an opportunistic garbage collector :

if (nf_ct_should_gc(ct)) {
    nf_ct_kill(ct);
    goto release;
}

So if one nf_conn is killed there, next time ct_get_next() runs, we skip the following item in the bucket, even if it should have been displayed if gc did not take place.

We can decrement st->skip_elems to tell ct_get_next() one of the items was removed from the chain.

Fixes 58e207e4983d ("netfilter: evict stale entries when user reads /proc/net/nf_conntrack")
---
 net/netfilter/nf_conntrack_standalone.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_conntrack_standalone.c +3 -0
index 1f14ef0436c65fccc8e64956a105d5473e21b55e..708b79380f047f32aa8e6047c52c807b4019f2b9 100644
@@ -317,6 +317,9 @@ static int ct_seq_show(struct seq_file *s, void *v)
 	smp_acquire__after_ctrl_dep();
 
 	if (nf_ct_should_gc(ct)) {
+		struct ct_iter_state *st = s->private;
+
+		st->skip_elems--;
 		nf_ct_kill(ct);
 		goto release;
 	}
Signature · 1 line
2.51.0.534.gc79095c0ca-goog
maintainer
#1 lore raw

net/netfilter/nf_conntrack_standalone.c static int ct_seq_show(struct seq_file *s, void *v) · line 322

Quoted 11 lines · Eric Dumazet
net/netfilter/nf_conntrack_standalone.c +3 -0
index 1f14ef0436c65fccc8e64956a105d5473e21b55e..708b79380f047f32aa8e6047c52c807b4019f2b9 100644
@@ -317,6 +317,9 @@ static int ct_seq_show(struct seq_file *s, void *v)
 	smp_acquire__after_ctrl_dep();
 
 	if (nf_ct_should_gc(ct)) {
+		struct ct_iter_state *st = s->private;
+
+		st->skip_elems--;

I'll route this via nf-next, I don't think there is a need to add it to nf this close to release.

Thanks Eric!