* [PATCH net 01/11] ipvs: fix problems during connection deletion
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-16 0:47 ` netdev-bot+sinfo
2026-11-17 11:50 ` patchwork-bot+netdevbpf
2026-11-16 0:43 ` [PATCH net 02/11] ipvs: avoid stack overflow from recursive connection expiration Pablo Neira Ayuso
` (9 subsequent siblings)
10 siblings, 2 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Julian Anastasov <ja@ssi.bg>
Sashiko reports for problem when deleting connections.
If connection timer expires, its callback can not be
concurrently running but if connection is deleted
the callback can be running on another CPU even
after all references are released. Before now we
continued with the connection freeing, risking the
callback to access the deleted connection after it
is freed. As ip_vs_conn_del() runs under RCU lock
there is no risk for accessing a connection freed
by concurrent timer callback. As Sashiko warns, the
risk is present if normal connection expires and
tries to delete its cp->control chain with
ip_vs_conn_del_put() without holding a RCU read lock.
It is evident that as the pending timer and the
running timer callback do not hold reference for
the connection, there are races which is difficult
to avoid.
Change the connection refcounting as follows:
* the connection hashing does not take reference anymore
* new connection handoffs its reference to the timer
if started in __ip_vs_conn_put_timer(), to hold it
while it is pending.
* if user finds connection in hash table it gets reference
and can handoff this reference to the pending timer if
this timer is started in __ip_vs_conn_put_timer(),
otherwise puts its reference if the timer was already
pending which is the common case.
* the pending timer handoffs its reference to the
running timer callback implicitly. By this way, the
timer callback in the common case has the last reference.
In rare cases, while the timer callback is running and
before it changes refcnt from 1 to 0, other users can get
reference and to handoff it again to the pending timer
they arm. In this case, the expiration is deferred
for later time.
As result, cp->refcnt accounts all current connection
users and the pending and running timer.
Two paths can try to delete the connection: the
normal expiration path and ip_vs_conn_del() if it
successfully steals the connection reference from the
pending timer. refcount_dec_if_one() will tell us if
we were the last active user with no packets accessing
the connection and no pending/running timers.
Change ip_vs_conn_unlink() to directly unhash the
connection because when we are the last user the
connection's forwarding method can not change.
Use smp_acquire__after_ctrl_dep() after refcount_dec_if_one()
and before reading the connection fields.
ip_vs_conn_expire() does not need to call timer_delete()
anymore because the pending timer is already accounted
in refcnt.
Add explicit rcu_read_lock() while deleting the cp->control
chain to protect from concurrent timer callback for ct to
expire it before us and to cause use-after-free.
During such races, try to keep 0 in cp->timeout as it is
a request for deleting our cp->control chain immediately.
Make sure we do not send timeout 0 (seconds) in the
v1 sync message because the backup server will select some
large default value which is not desired for small timeouts.
Remove the smp_mb__before_atomic() call from __ip_vs_conn_put(),
it is from the atomic_dec() era, now refcount_dec() has
RELEASE semantics.
Link: https://sashiko.dev/#/patchset/cover.1789435989.git.zihanx%40nebusec.ai
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1790266803.git.zihanx%40nebusec.ai
Fixes: f9200a52eedf ("ipvs: avoid expiring many connections from timer")
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/ip_vs.h | 1 -
net/netfilter/ipvs/ip_vs_conn.c | 99 ++++++++++++++++++---------------
net/netfilter/ipvs/ip_vs_sync.c | 2 +-
3 files changed, 55 insertions(+), 47 deletions(-)
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 9a83bff32569..97097d60d1c4 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -1685,7 +1685,6 @@ static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
/* put back the conn without restarting its timer */
static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
{
- smp_mb__before_atomic();
refcount_dec(&cp->refcnt);
}
void ip_vs_conn_put(struct ip_vs_conn *cp);
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 94f25fb7d87e..86c5e6c7b5af 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -293,7 +293,6 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
cp->flags |= IP_VS_CONN_F_HASHED;
WRITE_ONCE(cp->hn0.hash_key, hash_key);
WRITE_ONCE(cp->hn1.hash_key, hash_key2);
- refcount_inc(&cp->refcnt);
hlist_bl_add_head_rcu(&cp->hn0.node, head);
if (use2)
hlist_bl_add_head_rcu(&cp->hn1.node, head2);
@@ -319,11 +318,27 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
struct hlist_bl_head *head, *head2;
u32 hash_key, hash_key2;
struct ip_vs_rht *t;
- bool ret = false;
bool use2;
+ /* No more users and no running/pending timer except us? */
+ if (!refcount_dec_if_one(&cp->refcnt))
+ return false;
+
+ /* The ONE_PACKET connection is special:
+ * - the flag is present only for normal connections, not for templates
+ * - its timer is never started
+ * - it is never hashed, so you can not find it and delete it
+ * - it is not synced
+ * - it has only one user
+ * - it is freed after use immediately
+ */
if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
- return refcount_dec_if_one(&cp->refcnt);
+ return true;
+
+ /* Add the needed ACQUIRE barrier between the above
+ * refcount_dec_if_one() call and the read of cp fields
+ */
+ smp_acquire__after_ctrl_dep();
rcu_read_lock();
local_bh_disable();
@@ -337,15 +352,11 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
false /* new_hash2 */, &head, &head2);
if (cp->flags & IP_VS_CONN_F_HASHED) {
- /* Decrease refcnt and unlink conn only if we are last user */
- if (use2 == ip_vs_conn_use_hash2(cp) &&
- refcount_dec_if_one(&cp->refcnt)) {
- hlist_bl_del_rcu(&cp->hn0.node);
- if (use2)
- hlist_bl_del_rcu(&cp->hn1.node);
- cp->flags &= ~IP_VS_CONN_F_HASHED;
- ret = true;
- }
+ /* Unlink conn as we are the last user */
+ hlist_bl_del_rcu(&cp->hn0.node);
+ if (use2)
+ hlist_bl_del_rcu(&cp->hn1.node);
+ cp->flags &= ~IP_VS_CONN_F_HASHED;
}
conn_tab_unlock(head, head2);
@@ -353,7 +364,7 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
local_bh_enable();
rcu_read_unlock();
- return ret;
+ return true;
}
@@ -621,9 +632,12 @@ static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp)
{
unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ?
0 : cp->timeout;
- mod_timer(&cp->timer, jiffies+t);
- __ip_vs_conn_put(cp);
+ /* Handoff our reference to the timer if it was just armed,
+ * put the reference if timer was already pending.
+ */
+ if (mod_timer(&cp->timer, jiffies + t))
+ __ip_vs_conn_put(cp);
}
void ip_vs_conn_put(struct ip_vs_conn *cp)
@@ -1322,9 +1336,18 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
kmem_cache_free(ip_vs_conn_cachep, cp);
}
-/* Try to delete connection while not holding reference */
+/* Try to delete connection while not holding reference.
+ * It can be called concurrently and always under RCU lock
+ * to protect from connection deletion from others.
+ * Used when we need to remove the connection immediately
+ * and without overloading the timer processing.
+ * OTOH, we use ip_vs_conn_expire_now() when we prefer to
+ * leave the current context (packet processing) and to
+ * remove the connection from timer.
+ */
static void ip_vs_conn_del(struct ip_vs_conn *cp)
{
+ /* Steal reference from the pending timer */
if (timer_delete(&cp->timer)) {
/* Drop cp->control chain too */
if (cp->control)
@@ -1333,20 +1356,11 @@ static void ip_vs_conn_del(struct ip_vs_conn *cp)
}
}
-/* Try to delete connection while holding reference */
-static void ip_vs_conn_del_put(struct ip_vs_conn *cp)
-{
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
- __ip_vs_conn_put(cp);
- ip_vs_conn_expire(&cp->timer);
- } else {
- __ip_vs_conn_put(cp);
- }
-}
-
+/* Connection is removed in the following steps:
+ * - timer expires (with ref) or connection is deleted (with stolen ref)
+ * - there should be no more users except us (pending/running timer,
+ * n_control>0 or refcnt>1)
+ */
static void ip_vs_conn_expire(struct timer_list *t)
{
struct ip_vs_conn *cp = timer_container_of(cp, t, timer);
@@ -1362,23 +1376,18 @@ static void ip_vs_conn_expire(struct timer_list *t)
if (likely(ip_vs_conn_unlink(cp))) {
struct ip_vs_conn *ct = cp->control;
- /* delete the timer if it is activated by other users */
- timer_delete(&cp->timer);
-
/* does anybody control me? */
if (ct) {
- bool has_ref = !cp->timeout && __ip_vs_conn_get(ct);
-
+ rcu_read_lock();
ip_vs_control_del(cp);
/* Drop CTL or non-assured TPL if not used anymore */
- if (has_ref && !atomic_read(&ct->n_control) &&
+ if (!cp->timeout && !atomic_read(&ct->n_control) &&
(!(ct->flags & IP_VS_CONN_F_TEMPLATE) ||
!(ct->state & IP_VS_CTPL_S_ASSURED))) {
IP_VS_DBG(4, "drop controlling connection\n");
- ip_vs_conn_del_put(ct);
- } else if (has_ref) {
- __ip_vs_conn_put(ct);
+ ip_vs_conn_del(ct);
}
+ rcu_read_unlock();
}
if ((cp->flags & IP_VS_CONN_F_NFCT) &&
@@ -1413,8 +1422,8 @@ static void ip_vs_conn_expire(struct timer_list *t)
refcount_read(&cp->refcnt),
atomic_read(&cp->n_control));
- refcount_inc(&cp->refcnt);
- cp->timeout = 60*HZ;
+ if (cp->timeout || atomic_read(&cp->n_control))
+ cp->timeout = 60 * HZ;
if (ipvs->sync_state & IP_VS_STATE_MASTER)
ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
@@ -1432,7 +1441,7 @@ static void ip_vs_conn_expire(struct timer_list *t)
void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
{
/* Using mod_timer_pending will ensure the timer is not
- * modified after the final timer_delete in ip_vs_conn_expire.
+ * started without giving it new reference.
*/
if (timer_pending(&cp->timer) &&
time_after(cp->timer.expires, jiffies))
@@ -1500,9 +1509,9 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
spin_lock_init(&cp->lock);
/*
- * Set the entry is referenced by the current thread before hashing
- * it in the table, so that other thread run ip_vs_random_dropentry
- * but cannot drop this entry.
+ * Set the entry as referenced by the current thread before starting
+ * the timer and giving it our reference to allow other threads to
+ * run ip_vs_random_dropentry() or any deletion method safely.
*/
refcount_set(&cp->refcnt, 1);
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index 157f5c8361ab..1caacf419af9 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -732,7 +732,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
s->v4.vport = cp->vport;
s->v4.dport = cp->dport;
s->v4.fwmark = htonl(cp->fwmark);
- s->v4.timeout = htonl(cp->timeout / HZ);
+ s->v4.timeout = htonl(max(1UL, cp->timeout / HZ));
m->nr_conns++;
#ifdef CONFIG_IP_VS_IPV6
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 01/11] ipvs: fix problems during connection deletion
2026-11-16 0:43 ` [PATCH net 01/11] ipvs: fix problems during connection deletion Pablo Neira Ayuso
@ 2026-11-16 0:47 ` netdev-bot+sinfo
2026-11-16 0:48 ` Pablo Neira Ayuso
2026-11-17 11:50 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 23+ messages in thread
From: netdev-bot+sinfo @ 2026-11-16 0:47 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH net 01/11] ipvs: fix problems during connection deletion
2026-11-16 0:47 ` netdev-bot+sinfo
@ 2026-11-16 0:48 ` Pablo Neira Ayuso
0 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:48 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
On Mon, Nov 16, 2026 at 12:47:24AM +0000, netdev-bot+sinfo@kernel.org wrote:
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - How the issue was discovered, e.g. hit in production, hit during
> development, syzbot report, manual code inspection, LLM or static
> analysis tool scan.
>
> - Whether the issue was actually triggered, or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
This is v2 of this PR for IPVS.
Keeping back the patches 1, 2, 7 and 15 coming in the previous batch
as discussed with Julian Anastasov.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH net 01/11] ipvs: fix problems during connection deletion
2026-11-16 0:43 ` [PATCH net 01/11] ipvs: fix problems during connection deletion Pablo Neira Ayuso
2026-11-16 0:47 ` netdev-bot+sinfo
@ 2026-11-17 11:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 23+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-17 11:50 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <pablo@netfilter.org>:
On Mon, 16 Nov 2026 01:43:54 +0100 you wrote:
> From: Julian Anastasov <ja@ssi.bg>
>
> Sashiko reports for problem when deleting connections.
>
> If connection timer expires, its callback can not be
> concurrently running but if connection is deleted
> the callback can be running on another CPU even
> after all references are released. Before now we
> continued with the connection freeing, risking the
> callback to access the deleted connection after it
> is freed. As ip_vs_conn_del() runs under RCU lock
> there is no risk for accessing a connection freed
> by concurrent timer callback. As Sashiko warns, the
> risk is present if normal connection expires and
> tries to delete its cp->control chain with
> ip_vs_conn_del_put() without holding a RCU read lock.
>
> [...]
Here is the summary with links:
- [net,01/11] ipvs: fix problems during connection deletion
https://git.kernel.org/netdev/net/c/5ae07c10854f
- [net,02/11] ipvs: avoid stack overflow from recursive connection expiration
https://git.kernel.org/netdev/net/c/d4e4cd04de2c
- [net,03/11] ipvs: reject FTP control ports as data ports
https://git.kernel.org/netdev/net/c/a107e150e105
- [net,04/11] ipvs: ftp: skip conntrack templates in ip_vs_ftp_out
https://git.kernel.org/netdev/net/c/4656934d460d
- [net,05/11] ipvs: update flags and seqs in backup server under lock
https://git.kernel.org/netdev/net/c/f3aff3d80b57
- [net,06/11] ipvs: read flags and seqs in master atomically
https://git.kernel.org/netdev/net/c/aa9afc79f57b
- [net,07/11] ipvs: honor the overload state and do not enter it forever
https://git.kernel.org/netdev/net/c/567ca80d77ba
- [net,08/11] ipvs: validate cport in received sync records
https://git.kernel.org/netdev/net/c/1d1e8bc81f79
- [net,09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get()
https://git.kernel.org/netdev/net/c/5c8d6e2596e0
- [net,10/11] ipvs: do not create conns from packets with port 0
https://git.kernel.org/netdev/net/c/7439e0fed91f
- [net,11/11] ipvs: wait grace period before reusing destinations
https://git.kernel.org/netdev/net/c/5367e14e92bb
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net 02/11] ipvs: avoid stack overflow from recursive connection expiration
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
2026-11-16 0:43 ` [PATCH net 01/11] ipvs: fix problems during connection deletion Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-16 0:43 ` [PATCH net 03/11] ipvs: reject FTP control ports as data ports Pablo Neira Ayuso
` (8 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Zihan Xi <zihanx@nebusec.ai>
When a controlled IPVS connection expires, its controller may be expired
synchronously if it has no remaining controlled connections. A chain of
controlled connections can then recurse through ip_vs_conn_expire() and
exhaust the kernel stack during namespace cleanup.
Continue expiration with the controller after the current connection has
been fully cleaned up instead of calling ip_vs_conn_del() recursively. Keep
the expiration walk under RCU, preserve the immediate-drop timeout for a
controller with its own controller, and switch to deletion mode before the
next iteration.
This keeps controlled-connection cleanup synchronous while using one stack
frame for the whole chain. The timer callback race during connection
deletion is handled by the preceding connection-deletion fix.
This patch depends on "ipvs: fix problems during connection deletion" to
protect the iterative controller cleanup from the timer callback race.
Fixes: f9200a52eedf ("ipvs: avoid expiring many connections from timer")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Co-developed-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_conn.c | 40 ++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 86c5e6c7b5af..27db8d558a03 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1336,9 +1336,23 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
kmem_cache_free(ip_vs_conn_cachep, cp);
}
-/* Try to delete connection while not holding reference.
+/* Try to steal the reference from the pending timer.
* It can be called concurrently and always under RCU lock
* to protect from connection deletion from others.
+ */
+static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp)
+{
+ /* Steal reference from the pending timer */
+ if (!timer_delete(&cp->timer))
+ return false;
+
+ /* Drop cp->control chain too */
+ if (cp->control)
+ cp->timeout = 0;
+ return true;
+}
+
+/* Try to delete connection while not holding reference.
* Used when we need to remove the connection immediately
* and without overloading the timer processing.
* OTOH, we use ip_vs_conn_expire_now() when we prefer to
@@ -1347,13 +1361,8 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
*/
static void ip_vs_conn_del(struct ip_vs_conn *cp)
{
- /* Steal reference from the pending timer */
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
+ if (ip_vs_conn_del_reference(cp))
ip_vs_conn_expire(&cp->timer);
- }
}
/* Connection is removed in the following steps:
@@ -1366,6 +1375,9 @@ static void ip_vs_conn_expire(struct timer_list *t)
struct ip_vs_conn *cp = timer_container_of(cp, t, timer);
struct netns_ipvs *ipvs = cp->ipvs;
+ rcu_read_lock();
+
+repeat:
/*
* do I control anybody?
*/
@@ -1375,19 +1387,18 @@ static void ip_vs_conn_expire(struct timer_list *t)
/* Unlink conn if not referenced anymore */
if (likely(ip_vs_conn_unlink(cp))) {
struct ip_vs_conn *ct = cp->control;
+ bool next = false;
/* does anybody control me? */
if (ct) {
- rcu_read_lock();
ip_vs_control_del(cp);
/* Drop CTL or non-assured TPL if not used anymore */
if (!cp->timeout && !atomic_read(&ct->n_control) &&
(!(ct->flags & IP_VS_CONN_F_TEMPLATE) ||
!(ct->state & IP_VS_CTPL_S_ASSURED))) {
IP_VS_DBG(4, "drop controlling connection\n");
- ip_vs_conn_del(ct);
+ next = ip_vs_conn_del_reference(ct);
}
- rcu_read_unlock();
}
if ((cp->flags & IP_VS_CONN_F_NFCT) &&
@@ -1414,7 +1425,11 @@ static void ip_vs_conn_expire(struct timer_list *t)
else
call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free);
atomic_dec(&ipvs->conn_count);
- return;
+ if (next) {
+ cp = ct;
+ goto repeat;
+ }
+ goto out;
}
expire_later:
@@ -1429,6 +1444,9 @@ static void ip_vs_conn_expire(struct timer_list *t)
ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
__ip_vs_conn_put_timer(cp);
+
+out:
+ rcu_read_unlock();
}
/* Modify timer, so that it expires as soon as possible.
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH net 03/11] ipvs: reject FTP control ports as data ports
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
2026-11-16 0:43 ` [PATCH net 01/11] ipvs: fix problems during connection deletion Pablo Neira Ayuso
2026-11-16 0:43 ` [PATCH net 02/11] ipvs: avoid stack overflow from recursive connection expiration Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-16 0:43 ` [PATCH net 04/11] ipvs: ftp: skip conntrack templates in ip_vs_ftp_out Pablo Neira Ayuso
` (7 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Zihan Xi <zihanx@nebusec.ai>
The FTP helper must not treat a configured control port as a data port.
Accepting such a port can leave IPVS connections in a state that leads
to recursive expiration and kernel stack exhaustion.
Reject zero and configured control ports before creating passive data
connections. For active mode, reject a zero client port and a derived
data port that is itself a configured control port.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Co-developed-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_ftp.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 9e3e005a8263..4822a1a75212 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -62,6 +62,17 @@ static unsigned short ports[IP_VS_APP_MAX_PORTS] = {21, 0};
module_param_array(ports, ushort, &ports_count, 0444);
MODULE_PARM_DESC(ports, "Ports to monitor for FTP control commands");
+static bool is_control_port(u16 port)
+{
+ unsigned int i;
+
+ for (i = 0; i < ports_count; i++) {
+ if (ports[i] == port)
+ return true;
+ }
+ return false;
+}
+
static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh)
{
@@ -319,6 +330,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ /* Do not redirect data to control ports */
+ if (!port || is_control_port(ntohs(port)))
+ return 0;
+
/* Now update or create a connection entry for it */
{
struct ip_vs_conn_param p;
@@ -529,6 +544,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ if (!port || is_control_port(ntohs(cp->vport) - 1))
+ return 0;
+
/* Passive mode off */
cp->app_data = (void *) IP_VS_FTP_ACTIVE;
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 03/11] ipvs: reject FTP control ports as data ports
2026-11-16 0:43 ` [PATCH net 03/11] ipvs: reject FTP control ports as data ports Pablo Neira Ayuso
@ 2026-11-17 1:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 1:40 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new rejection checks in ip_vs_ftp_out() and ip_vs_ftp_in()
(net/netfilter/ipvs/ip_vs_ftp.c) return 0.
- [Low] The commit message says that accepting a control port as a data
port 'leads to recursive expiration and kernel stack exhaustion'.
--
ipvs: reject FTP control ports as data ports
This patch adds is_control_port() to the IPVS FTP helper. Before a data
connection is created, the helper now rejects zero ports and configured
FTP control ports. In passive mode it checks the port from the server's
PASV/EPSV reply; in active mode it checks the client port and the derived
data port (vport - 1).
> The FTP helper must not treat a configured control port as a data port.
> Accepting such a port can leave IPVS connections in a state that leads
> to recursive expiration and kernel stack exhaustion.
[Severity: Low]
Is this rationale still accurate once the previous patch in this series
is applied?
"ipvs: avoid stack overflow from recursive connection expiration" already
rewrote ip_vs_conn_expire() so that it walks the ->control chain
iteratively, in a single stack frame:
net/netfilter/ipvs/ip_vs_conn.c:ip_vs_conn_expire() {
...
next = ip_vs_conn_del_reference(ct);
...
if (next) {
cp = ct;
goto repeat;
}
...
}
With that change, the recursive expiration described here should no
longer happen in this tree.
Could the commit message point to the companion commit and say what this
guard still prevents now that expiration is iterative? Two candidates are
long chains of FTP-bound data connections, and NO_CPORT entries on
VIP:control-port capturing the client's new control connections.
Both commits carry Cc: stable, but with different Fixes: tags
(f9200a52eedf and 1da177e4c3f4). A stable backporter can't tell from the
messages whether the two are alternatives or must both be applied.
> diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
> index 9e3e005a82635..4822a1a75212d 100644
> --- a/net/netfilter/ipvs/ip_vs_ftp.c
> +++ b/net/netfilter/ipvs/ip_vs_ftp.c
[ ... ]
> @@ -319,6 +330,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
> return 1;
> }
>
> + /* Do not redirect data to control ports */
> + if (!port || is_control_port(ntohs(port)))
> + return 0;
> +
> /* Now update or create a connection entry for it */
> {
> struct ip_vs_conn_param p;
> @@ -529,6 +544,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
> return 1;
> }
>
> + if (!port || is_control_port(ntohs(cp->vport) - 1))
> + return 0;
> +
> /* Passive mode off */
> cp->app_data = (void *) IP_VS_FTP_ACTIVE;
>
[Severity: Medium]
Should these new checks return 0? In include/net/ip_vs.h, struct
ip_vs_app documents pkt_out/pkt_in as:
Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
The callers drop the packet when they get 0:
ip_vs_ftp_in() returns 0
tcp_dnat_handler() returns 0
ip_vs_nat_xmit()
if (pp->dnat_handler && !pp->dnat_handler(skb, pp, cp, ipvsh))
goto tx_error;
ip_vs_ftp_out() returns 0
tcp_snat_handler() returns 0
handle_response()
if (pp->snat_handler &&
!SNAT_CALL(pp->snat_handler, skb, pp, cp, iph))
goto drop;
So instead of just skipping the data connection, the FTP control segment
itself seems to be dropped silently.
In ip_vs_ftp_in(), the is_control_port(ntohs(cp->vport) - 1) test depends
only on configuration, not on packet contents. Take an FTP virtual service
on port V where V-1 is also in the ports= module parameter (for example
ports=20,21 or ports=2120,2121). Wouldn't every PORT/EPRT command on V be
dropped, retransmissions included? The control session would then stall
until TCP gives up, and nothing would be logged.
Before this patch, active-mode FTP worked in that configuration. The data
connection was created with vport V-1, and tcp_app_conn_bind() also bound
it to the FTP app, because binding depends only on the vport.
In ip_vs_ftp_out(), the return 0 comes before cp->app_data is reset to
IP_VS_FTP_ACTIVE. Wouldn't each retransmitted 227/229 reply then be parsed
and dropped again? A comment later in that function justifies a 0 return
only because mangling failures are transient:
* Mangling can only fail under memory pressure,
* hopefully it will succeed on the retransmitted
* packet.
This rejection isn't transient.
Would returning 1 work better here? The payload would pass through
unmangled and no data connection would be created. The control session
would survive (the server reports a data connection failure), and the
self-binding would still be prevented. A rate-limited log message might
also help.
Since this is tagged for stable, could the commit message also say that
active FTP stops working when V-1 is also a configured control port?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net 04/11] ipvs: ftp: skip conntrack templates in ip_vs_ftp_out
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (2 preceding siblings ...)
2026-11-16 0:43 ` [PATCH net 03/11] ipvs: reject FTP control ports as data ports Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-16 0:43 ` [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock Pablo Neira Ayuso
` (6 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>
A CT target hooked after conntrack attaches its template to a packet
that conntrack left without an entry. On an IPVS FTP PASV/EPSV reply,
ip_vs_ftp_out() then mangles with the template and creates an
expectation with the template as master. Deleting the CT rule frees
the template and leaves the expectation, so a later expectation flush
reads freed memory:
BUG: KASAN: slab-use-after-free in nf_ct_unlink_expect_report
Reachable with CAP_NET_ADMIN in a user namespace.
Skip templates, as nft_ct and nfnetlink_queue do.
Fixes: f4bc17cdd205 ("ipvs: netfilter connection tracking changes")
Cc: stable@vger.kernel.org
Signed-off-by: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_ftp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 4822a1a75212..44de99f4d187 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -383,7 +383,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
buf_len = strlen(buf);
ct = nf_ct_get(skb, &ctinfo);
- if (ct) {
+ if (ct && !nf_ct_is_template(ct)) {
bool mangled;
/* If mangling fails this function will return 0
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (3 preceding siblings ...)
2026-11-16 0:43 ` [PATCH net 04/11] ipvs: ftp: skip conntrack templates in ip_vs_ftp_out Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-16 0:43 ` [PATCH net 06/11] ipvs: read flags and seqs in master atomically Pablo Neira Ayuso
` (5 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Julian Anastasov <ja@ssi.bg>
Sashiko reports that we modify the conn flags and seq values in
the backup server without holding cp->lock. The same is true for
other fields such as state, old_state and timeout which are
modified by protocols under lock.
Extend the locked region in ip_vs_proc_conn() to update the
fields atomically.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_sync.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index 1caacf419af9..ba2fa1f9d08e 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -850,6 +850,7 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
unsigned long timeout, __u32 fwmark,
struct ip_vs_sync_conn_options *opt)
{
+ struct ip_vs_conn *cp_new = NULL;
struct ip_vs_dest *dest;
struct ip_vs_conn *cp;
@@ -891,9 +892,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
flags &= IP_VS_CONN_F_BACKUP_UPD_MASK;
flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK;
cp->flags = flags;
- spin_unlock_bh(&cp->lock);
- if (!dest)
- ip_vs_try_bind_dest(cp);
} else {
/*
* Find the appropriate destination for the connection.
@@ -920,6 +918,8 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
}
if (!(flags & IP_VS_CONN_F_TEMPLATE))
kfree(param->pe_data);
+ cp_new = cp;
+ spin_lock_bh(&cp->lock);
}
if (opt) {
@@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
else
cp->timeout = (3*60*HZ);
}
+ spin_unlock_bh(&cp->lock);
+ if (!dest && !cp_new)
+ ip_vs_try_bind_dest(cp);
ip_vs_conn_put(cp);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock
2026-11-16 0:43 ` [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock Pablo Neira Ayuso
@ 2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-17 4:58 ` Julian Anastasov
0 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 1:40 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The fix is incomplete.
--
ipvs: update flags and seqs in backup server under lock
This commit extends the cp->lock region in ip_vs_proc_conn() so that the
backup server updates the conn flags, seqs, state, old_state and timeout
under the lock. Newly created conns now also take cp->lock before these
updates. ip_vs_try_bind_dest() is now called after the unlock.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org
> diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
> index 1caacf419af99..ba2fa1f9d08ed 100644
> --- a/net/netfilter/ipvs/ip_vs_sync.c
> +++ b/net/netfilter/ipvs/ip_vs_sync.c
[ ... ]
> @@ -891,9 +892,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
> flags &= IP_VS_CONN_F_BACKUP_UPD_MASK;
> flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK;
> cp->flags = flags;
> - spin_unlock_bh(&cp->lock);
> - if (!dest)
> - ip_vs_try_bind_dest(cp);
> } else {
> /*
> * Find the appropriate destination for the connection.
[ ... ]
> @@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
> else
> cp->timeout = (3*60*HZ);
> }
> + spin_unlock_bh(&cp->lock);
> + if (!dest && !cp_new)
> + ip_vs_try_bind_dest(cp);
[Severity: High]
Can the backup server still write cp->flags without cp->lock through this
ip_vs_try_bind_dest() call?
ip_vs_try_bind_dest() holds cp->lock only around ip_vs_unbind_app() and
ip_vs_bind_dest(). It drops the lock before it rebinds the transmitter and
the app:
net/netfilter/ipvs/ip_vs_conn.c:ip_vs_try_bind_dest() {
...
ip_vs_bind_dest(cp, dest);
spin_unlock_bh(&cp->lock);
/* Update its packet transmitter */
cp->packet_xmit = NULL;
...
pd = ip_vs_proto_data_get(cp->ipvs, cp->protocol);
if (pd && atomic_read(&pd->appcnt))
ip_vs_bind_app(cp, pd->pp);
...
}
For a MASQ conn, ip_vs_bind_app() reaches tcp_app_conn_bind(), which sets
cp->app and calls inc->init_conn(). For the FTP helper, that is:
net/netfilter/ipvs/ip_vs_ftp.c:ip_vs_ftp_init_conn() {
/* We use connection tracking for the command connection */
cp->flags |= IP_VS_CONN_F_NFCT;
return 0;
}
This is a non-atomic read-modify-write of cp->flags on a conn that is
already hashed. The other runtime writers of cp->flags hold cp->lock:
- set_tcp_state() and set_sctp_state() toggle IP_VS_CONN_F_INACTIVE and
adjust the dest counters.
- vs_seq_update() sets IN_SEQ/OUT_SEQ.
- ip_vs_in_hook() clears NFCT.
The path is:
ip_vs_process_message()
ip_vs_proc_conn() /* existing conn, cp->dest == NULL */
spin_unlock_bh(&cp->lock)
ip_vs_try_bind_dest()
spin_unlock_bh(&cp->lock)
ip_vs_bind_app()
tcp_app_conn_bind()
ip_vs_ftp_init_conn() /* unlocked cp->flags |= ... */
This can happen when all of the following are true:
- A synced MASQ conn for an FTP virtual service was created unbound,
because the real server was not yet configured on the backup.
- The dest is added later.
- The next sync message for that conn arrives while the backup is also
forwarding its traffic.
Suppose tcp_state_transition() on another CPU sets IP_VS_CONN_F_INACTIVE
under cp->lock and moves activeconns/inactconns at the same time. Would
the unlocked write here put back the stale flags?
The flags and the dest counters would then disagree, and the wrong counter
would be decremented when the conn is unbound. IN_SEQ/OUT_SEQ bits could
be lost the same way. This code path also looks unchanged by the rest of
the series.
The commit message says:
"Sashiko reports that we modify the conn flags and seq values in
the backup server without holding cp->lock."
Should this path be covered as well?
> ip_vs_conn_put(cp);
> }
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock
2026-11-17 1:40 ` netdev-bot+sashiko
@ 2026-11-17 4:58 ` Julian Anastasov
0 siblings, 0 replies; 23+ messages in thread
From: Julian Anastasov @ 2026-11-17 4:58 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: pablo, netfilter-devel, davem, netdev, kuba, pabeni, edumazet,
horms, fw
[-- Attachment #1: Type: text/plain, Size: 4941 bytes --]
Hello,
On Tue, 17 Nov 2026, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] The fix is incomplete.
>
> --
>
> ipvs: update flags and seqs in backup server under lock
>
> This commit extends the cp->lock region in ip_vs_proc_conn() so that the
> backup server updates the conn flags, seqs, state, old_state and timeout
> under the lock. Newly created conns now also take cp->lock before these
> updates. ip_vs_try_bind_dest() is now called after the unlock.
>
> Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org
>
> > diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
> > index 1caacf419af99..ba2fa1f9d08ed 100644
> > --- a/net/netfilter/ipvs/ip_vs_sync.c
> > +++ b/net/netfilter/ipvs/ip_vs_sync.c
>
> [ ... ]
>
> > @@ -891,9 +892,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
> > flags &= IP_VS_CONN_F_BACKUP_UPD_MASK;
> > flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK;
> > cp->flags = flags;
> > - spin_unlock_bh(&cp->lock);
> > - if (!dest)
> > - ip_vs_try_bind_dest(cp);
> > } else {
> > /*
> > * Find the appropriate destination for the connection.
>
> [ ... ]
>
> > @@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
> > else
> > cp->timeout = (3*60*HZ);
> > }
> > + spin_unlock_bh(&cp->lock);
> > + if (!dest && !cp_new)
> > + ip_vs_try_bind_dest(cp);
>
> [Severity: High]
> Can the backup server still write cp->flags without cp->lock through this
> ip_vs_try_bind_dest() call?
>
> ip_vs_try_bind_dest() holds cp->lock only around ip_vs_unbind_app() and
> ip_vs_bind_dest(). It drops the lock before it rebinds the transmitter and
> the app:
>
> net/netfilter/ipvs/ip_vs_conn.c:ip_vs_try_bind_dest() {
> ...
> ip_vs_bind_dest(cp, dest);
> spin_unlock_bh(&cp->lock);
>
> /* Update its packet transmitter */
> cp->packet_xmit = NULL;
> ...
> pd = ip_vs_proto_data_get(cp->ipvs, cp->protocol);
> if (pd && atomic_read(&pd->appcnt))
> ip_vs_bind_app(cp, pd->pp);
> ...
> }
>
> For a MASQ conn, ip_vs_bind_app() reaches tcp_app_conn_bind(), which sets
> cp->app and calls inc->init_conn(). For the FTP helper, that is:
>
> net/netfilter/ipvs/ip_vs_ftp.c:ip_vs_ftp_init_conn() {
> /* We use connection tracking for the command connection */
> cp->flags |= IP_VS_CONN_F_NFCT;
This problem is deep in my TODO list. It is not locked only
for the backup context, not for the normal packet context, so it
needs a proper separate fix.
> return 0;
> }
>
> This is a non-atomic read-modify-write of cp->flags on a conn that is
> already hashed. The other runtime writers of cp->flags hold cp->lock:
>
> - set_tcp_state() and set_sctp_state() toggle IP_VS_CONN_F_INACTIVE and
> adjust the dest counters.
> - vs_seq_update() sets IN_SEQ/OUT_SEQ.
> - ip_vs_in_hook() clears NFCT.
>
> The path is:
>
> ip_vs_process_message()
> ip_vs_proc_conn() /* existing conn, cp->dest == NULL */
> spin_unlock_bh(&cp->lock)
> ip_vs_try_bind_dest()
> spin_unlock_bh(&cp->lock)
> ip_vs_bind_app()
> tcp_app_conn_bind()
> ip_vs_ftp_init_conn() /* unlocked cp->flags |= ... */
>
> This can happen when all of the following are true:
>
> - A synced MASQ conn for an FTP virtual service was created unbound,
> because the real server was not yet configured on the backup.
> - The dest is added later.
> - The next sync message for that conn arrives while the backup is also
> forwarding its traffic.
>
> Suppose tcp_state_transition() on another CPU sets IP_VS_CONN_F_INACTIVE
> under cp->lock and moves activeconns/inactconns at the same time. Would
> the unlocked write here put back the stale flags?
>
> The flags and the dest counters would then disagree, and the wrong counter
> would be decremented when the conn is unbound. IN_SEQ/OUT_SEQ bits could
> be lost the same way. This code path also looks unchanged by the rest of
> the series.
>
> The commit message says:
>
> "Sashiko reports that we modify the conn flags and seq values in
> the backup server without holding cp->lock."
>
> Should this path be covered as well?
>
> > ip_vs_conn_put(cp);
> > }
> >
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Regards
--
Julian Anastasov <ja@ssi.bg>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net 06/11] ipvs: read flags and seqs in master atomically
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (4 preceding siblings ...)
2026-11-16 0:43 ` [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock Pablo Neira Ayuso
@ 2026-11-16 0:43 ` Pablo Neira Ayuso
2026-11-16 0:44 ` [PATCH net 07/11] ipvs: honor the overload state and do not enter it forever Pablo Neira Ayuso
` (4 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:43 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Julian Anastasov <ja@ssi.bg>
After we fixed the double read of cp->flags in the master with
commit 3e3fe49e8678 ("ipvs: fix buffer overflow when sending sync messages")
Sashiko reports that we should also read the cp->flags and the seqs
atomically. So if the SEQ_MASK is set, re-read the flags and the
seqs under cp->lock to provide a snapshot when sending the sync
message.
Fixes: 3e3fe49e8678 ("ipvs: fix buffer overflow when sending sync messages")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_sync.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index ba2fa1f9d08e..f11c59eca553 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -539,6 +539,7 @@ static int ip_vs_sync_conn_needed(struct netns_ipvs *ipvs,
static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg_v0 *m;
struct ip_vs_sync_conn_v0 *s;
struct ip_vs_sync_buff *buff;
@@ -557,6 +558,14 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
return;
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
+
spin_lock_bh(&ipvs->sync_buff_lock);
if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) {
spin_unlock_bh(&ipvs->sync_buff_lock);
@@ -604,7 +613,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (seq_mask) {
struct ip_vs_sync_conn_options *opt =
(struct ip_vs_sync_conn_options *)&s[1];
- memcpy(opt, &cp->sync_conn_opt, sizeof(*opt));
+ memcpy(opt, &opts, sizeof(*opt));
}
m->nr_conns++;
@@ -630,6 +639,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
*/
void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg *m;
union ip_vs_sync_conn *s;
struct ip_vs_sync_buff *buff;
@@ -651,6 +661,13 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
goto control;
flags = READ_ONCE(cp->flags);
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
/* Sanity checks */
pe_name_len = 0;
@@ -752,9 +769,9 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (seq_mask) {
*(p++) = IPVS_OPT_SEQ_DATA;
*(p++) = sizeof(struct ip_vs_sync_conn_options);
- hton_seq(&cp->in_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.in_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
- hton_seq(&cp->out_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.out_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
}
/* Handle pe data */
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH net 07/11] ipvs: honor the overload state and do not enter it forever
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (5 preceding siblings ...)
2026-11-16 0:43 ` [PATCH net 06/11] ipvs: read flags and seqs in master atomically Pablo Neira Ayuso
@ 2026-11-16 0:44 ` Pablo Neira Ayuso
2026-11-16 0:44 ` [PATCH net 08/11] ipvs: validate cport in received sync records Pablo Neira Ayuso
` (3 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Julian Anastasov <ja@ssi.bg>
Sashiko warns that we may enter the dest overload state forever
if setting the u_threshold to 1 races with the ip_vs_unbind_dest()
call for the last connection for dest. The problem is that we
prefer ip_vs_unbind_dest() to avoid using locks while reading the
threshold.
To avoid the race, add a smp_mb() in __ip_vs_dest_update_overload()
that is paired with the atomic_fetch_dec() in ip_vs_unbind_dest()
which allows to re-read the totalconns and to leave the overload
state if we are below l_threshold_val.
Also, remove the overload parameter from ip_vs_dest_update_overload()
because we just need to know the current state while deciding
which threshold ranges to use. This ip_vs_dest_is_overloaded() check
can be in __ip_vs_dest_update_overload() instead.
To avoid ip_vs_bind_dest() to enter lock just to initialize
u_threshold_val to INT_MAX, do it in ip_vs_new_dest().
The LBLC and LBLCR schedulers do not honor the global overload state
for cached dests, so add a ip_vs_dest_is_overloaded() check for
the situations where we may fallback from overloaded dest (LBLC and
LBLCR) or when we hit a cached dest (LBLC).
Also, move the ip_vs_dest_set_min() call in LBLCR after the
ip_vs_dest_set_erase() call that removes the most-loaded
server because due to races we may work with dest that is
in process of removing, i.e. ip_vs_dest_set_min() and
ip_vs_dest_set_max() may return same dest.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019150249.1879516-2-pablo%40netfilter.org
Fixes: 3ba20137287f ("ipvs: fix more races around the overload flag")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/ip_vs.h | 2 +-
net/netfilter/ipvs/ip_vs_conn.c | 4 ++--
net/netfilter/ipvs/ip_vs_ctl.c | 30 ++++++++++++++++++------------
net/netfilter/ipvs/ip_vs_lblc.c | 8 +++++---
net/netfilter/ipvs/ip_vs_lblcr.c | 13 +++++++------
5 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 97097d60d1c4..c1f7a3f144f1 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -1922,7 +1922,7 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
kfree(dest);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload);
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest);
/* Check if dest is in overloaded state */
static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 27db8d558a03..66fcdc00ef37 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1168,7 +1168,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
atomic_inc(&dest->activeconns);
tc = atomic_inc_return(&dest->totalconns);
if (tc >= READ_ONCE(dest->u_threshold_val))
- ip_vs_dest_update_overload(dest, true);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so increase
the persistent connection counter */
@@ -1261,7 +1261,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
atomic_dec(&dest->activeconns);
tc = atomic_fetch_dec(&dest->totalconns);
if (tc <= READ_ONCE(dest->l_threshold_val))
- ip_vs_dest_update_overload(dest, false);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so decrease
the persistent connection counter */
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index ce9fe20d6106..5868adda6ed6 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1304,12 +1304,12 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)
}
}
-/* Update overload flag based on number of dest conns and lower/upper
+/* Update overload state based on number of dest conns and lower/upper
* connection thresholds:
- * - conns reach u_threshold and exceed it: set the flag
- * - conns go below l_threshold (or 75% of u_threshold): clear the flag
+ * - conns reach u_threshold and exceed it: set the overload state
+ * - conns go below l_threshold (or 75% of u_threshold): clear the state
*/
-static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
int conns;
u32 l, u;
@@ -1320,10 +1320,18 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
/* Low threshold defaults to 75% of upper threshold */
l = READ_ONCE(dest->l_threshold) ? : (u - (u >> 2));
conns = atomic_read(&dest->totalconns);
- if (conns >= (overload ? l : u)) {
+ if (conns >= (ip_vs_dest_is_overloaded(dest) ? l : u)) {
WRITE_ONCE(dest->u_threshold_val, INT_MAX);
WRITE_ONCE(dest->l_threshold_val, l);
- return;
+ /* Commit thresholds before repeating the check,
+ * it is paired with atomic_fetch_dec() in
+ * ip_vs_unbind_dest() to avoid entering the
+ * overload state forever.
+ */
+ smp_mb();
+ conns = atomic_read(&dest->totalconns);
+ if (conns >= l)
+ return;
}
}
@@ -1331,10 +1339,10 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
WRITE_ONCE(dest->l_threshold_val, 0);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
spin_lock_bh(&dest->dst_lock);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1406,13 +1414,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if (READ_ONCE(dest->u_threshold) != udest->u_threshold ||
READ_ONCE(dest->l_threshold) != udest->l_threshold) {
- bool overload;
-
spin_lock_bh(&dest->dst_lock);
WRITE_ONCE(dest->u_threshold, udest->u_threshold);
WRITE_ONCE(dest->l_threshold, udest->l_threshold);
- overload = ip_vs_dest_is_overloaded(dest);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1477,6 +1482,7 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
if (ret < 0)
goto err_stats;
+ dest->u_threshold_val = INT_MAX;
dest->af = udest->af;
dest->protocol = svc->protocol;
dest->vaddr = svc->addr;
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index e1111c3b2721..f5ce1f2afb86 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -467,10 +467,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -507,6 +508,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
dest = en->dest;
if ((dest->cflags & IP_VS_DEST_CF_AVAILABLE) &&
+ !ip_vs_dest_is_overloaded(dest) &&
atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc))
goto out;
}
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index dfb5bf83750d..4046608922e7 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -630,10 +630,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -658,9 +659,6 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
if (en) {
en->lastuse = jiffies;
- /* Get the least loaded destination */
- dest = ip_vs_dest_set_min(&en->set);
-
/* More than one destination + enough time passed by, cleanup */
if (atomic_read(&en->set.size) > 1 &&
time_after(jiffies, en->set.lastmod +
@@ -676,6 +674,9 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
spin_unlock_bh(&svc->sched_lock);
}
+ /* Get the least loaded destination */
+ dest = ip_vs_dest_set_min(&en->set);
+
/* If the destination is not overloaded, use it */
if (dest && !is_overloaded(dest, svc))
goto out;
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH net 08/11] ipvs: validate cport in received sync records
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (6 preceding siblings ...)
2026-11-16 0:44 ` [PATCH net 07/11] ipvs: honor the overload state and do not enter it forever Pablo Neira Ayuso
@ 2026-11-16 0:44 ` Pablo Neira Ayuso
2026-11-16 0:44 ` [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get() Pablo Neira Ayuso
` (2 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Axel Mierczuk <axel.mierczuk@1password.com>
Local templates have cport 0 and IP_VS_CONN_F_NO_CPORT clear, so
ip_vs_conn_in_get() cannot match them. A template received over the
unauthenticated sync protocol with a nonzero cport can reach the
protocol state machine. Before template state validation, this
could cause out-of-bounds reads, crashes and kernel data leaks.
Ordinary records with cport 0 and IP_VS_CONN_F_NO_CPORT clear, or
with a nonzero cport and IP_VS_CONN_F_NO_CPORT set, create connections
that incoming lookups cannot match. The latter also keeps the
cport-zero fallback in ip_vs_conn_in_get() enabled.
Reject all three cases. Continue accepting ordinary connections with
cport 0 and IP_VS_CONN_F_NO_CPORT. The companion commit f96e91748f63
("ipvs: filter some flags received in the backup server") rejects
template records carrying IP_VS_CONN_F_NO_CPORT.
Fixes: 87375ab47cd0 ("[IPVS]: ip_vs_ftp breaks connections using persistence")
Cc: stable@vger.kernel.org
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Axel Mierczuk <axel.mierczuk@1password.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_sync.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index f11c59eca553..7e562e745ab5 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -871,6 +871,25 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
struct ip_vs_dest *dest;
struct ip_vs_conn *cp;
+ /* Templates require cport 0. Ordinary connections require
+ * NO_CPORT exactly when cport is 0.
+ */
+ if (flags & IP_VS_CONN_F_TEMPLATE) {
+ if (param->cport) {
+ IP_VS_DBG(2, "BACKUP, template with cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+ } else if (!param->cport && !(flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn without cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ } else if (param->cport && (flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn with cport and NO_CPORT dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+
if (!(flags & IP_VS_CONN_F_TEMPLATE)) {
cp = ip_vs_conn_in_get(param);
if (cp && ((cp->dport != dport) ||
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get()
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (7 preceding siblings ...)
2026-11-16 0:44 ` [PATCH net 08/11] ipvs: validate cport in received sync records Pablo Neira Ayuso
@ 2026-11-16 0:44 ` Pablo Neira Ayuso
2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-16 0:44 ` [PATCH net 10/11] ipvs: do not create conns from packets with port 0 Pablo Neira Ayuso
2026-11-16 0:44 ` [PATCH net 11/11] ipvs: wait grace period before reusing destinations Pablo Neira Ayuso
10 siblings, 1 reply; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Axel Mierczuk <axel.mierczuk@1password.com>
ip_vs_conn_out_get() does not filter templates. A template with
cport 0 is matched by a packet sent to client port 0 that traverses
the out hook, and handle_response() then runs ip_vs_set_state() and
the timeout update on a connection that must never see packets. A
backup server receives such templates over the unauthenticated sync
protocol. An ordinary connection scheduled for a client that uses
source port 0 has cport 0 as well and is matched the same way.
Apply the rule used by __ip_vs_conn_in_get(): a lookup for client
port 0 matches only connections flagged IP_VS_CONN_F_NO_CPORT, which
still wait for their cport, and a lookup for a nonzero client port
matches only connections without this flag. Test p->vport, which was
already compared with cp->cport, instead of reading cp->cport again.
ip_vs_ftp_out() relies on the first case: it looks up the data
connection with client port 0 to find the IP_VS_CONN_F_NO_CPORT entry
created for an earlier PASV or EPSV reply. That lookup keeps working.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Axel Mierczuk <axel.mierczuk@1password.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_conn.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 66fcdc00ef37..83d8a9153a34 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -590,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
ip_vs_addr_equal(p->af, p->vaddr,
&cp->caddr) &&
ip_vs_addr_equal(p->af, p->caddr, saddr) &&
+ (!p->vport ^
+ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
p->protocol == cp->protocol) {
if (__ip_vs_conn_get(cp))
goto out;
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get()
2026-11-16 0:44 ` [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get() Pablo Neira Ayuso
@ 2026-11-17 1:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 1:40 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new term `(!p->vport ^ !(cp->flags &
IP_VS_CONN_F_NO_CPORT))` in ip_vs_conn_out_get()…
--
ipvs: skip cport 0 connections in ip_vs_conn_out_get()
This commit adds a check to ip_vs_conn_out_get(). A lookup for client
port 0 now matches only connections flagged IP_VS_CONN_F_NO_CPORT, and a
lookup for a nonzero client port matches only connections without that
flag. The aim is to stop packets sent to client port 0 from matching
templates and ordinary cport 0 connections.
> diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
> index 66fcdc00ef375..83d8a9153a342 100644
> --- a/net/netfilter/ipvs/ip_vs_conn.c
> +++ b/net/netfilter/ipvs/ip_vs_conn.c
> @@ -590,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
> ip_vs_addr_equal(p->af, p->vaddr,
> &cp->caddr) &&
> ip_vs_addr_equal(p->af, p->caddr, saddr) &&
> + (!p->vport ^
> + (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
> p->protocol == cp->protocol) {
> if (__ip_vs_conn_get(cp))
> goto out;
[Severity: Medium]
Can the nonzero port half of this check make reply lookups miss while
ip_vs_conn_fill_cport() is still running?
Some NO_CPORT connections are MASQ and double-hashed. One example is the
FTP passive data connection that ip_vs_ftp_out() creates with
IP_VS_CONN_F_NO_CPORT | IP_VS_CONN_F_NFCT. For these,
ip_vs_conn_fill_cport() works in two locked passes. The dir=1 pass sets
cport and rehashes hn1, but only the dir=0 pass clears the flag:
net/netfilter/ipvs/ip_vs_conn.c:ip_vs_conn_fill_cport() {
...
if (cp->flags & IP_VS_CONN_F_NO_CPORT && (!cp->cport || by_me)) {
if (!cp->cport) {
cp->cport = cport;
by_me = true;
}
if (!dir) {
atomic_dec(&ipvs->no_cport_conns[af_id]);
cp->flags &= ~IP_VS_CONN_F_NO_CPORT;
}
...
WRITE_ONCE(hn->hash_key, hash_key_r);
...
}
...
spin_unlock_bh(&cp->lock);
if (dir-- && by_me)
goto next_dir;
}
All locks, including cp->lock, are dropped between the two passes.
Take an RCU reader in ip_vs_conn_out_get() that looks up a real server
reply to client:X inside that window. It finds hn1 with a matching
hash_key and passes the p->vport != cp->cport check, because cp->cport is
already X. NO_CPORT is still set, so the new term evaluates to 0 ^ 0 and
the lookup misses. Before this patch the same lookup matched.
One way to reach the window:
CPU A: ip_vs_nat_xmit()->ip_vs_conn_fill_cport() completes the dir=1
pass (cport = X, hn1 rehashed) and stalls before the dir=0 pass.
CPU B: already holds cp from the cport 0 fallback lookup and sees
NO_CPORT in ip_vs_nat_xmit(). Its ip_vs_conn_fill_cport() call
does nothing because cp->cport != 0 and by_me is false. It then
forwards the packet to the real server.
Reply: reaches ip_vs_out_hook(). ip_vs_conn_out_get() misses because
NO_CPORT is still set.
On a miss, ip_vs_out_hook() takes the no-connection path. The reply then
goes out without SNAT, which exposes the real server address. If
nat_icmp_send is enabled, the reply is instead answered with ICMP port
unreachable and dropped. TCP retransmissions recover once the dir=0 pass
clears the flag.
The cases in the commit message (templates and ordinary cport 0
connections) seem to need only the zero port half of the rule. For a
nonzero p->vport, the existing p->vport == cp->cport test already
excludes those entries.
The earlier patch "ipvs: validate cport in received sync records" also
already rejects sync records that have a nonzero cport with NO_CPORT
set. No later patch in the series changes ip_vs_conn_out_get() or
ip_vs_conn_fill_cport().
Would a narrower check like this close the template and cport 0 case
without opening this window?
(p->vport || (cp->flags & IP_VS_CONN_F_NO_CPORT))
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net 10/11] ipvs: do not create conns from packets with port 0
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (8 preceding siblings ...)
2026-11-16 0:44 ` [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get() Pablo Neira Ayuso
@ 2026-11-16 0:44 ` Pablo Neira Ayuso
2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-16 0:44 ` [PATCH net 11/11] ipvs: wait grace period before reusing destinations Pablo Neira Ayuso
10 siblings, 1 reply; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Julian Anastasov <ja@ssi.bg>
We should disallow normal connections with cport 0 to be
created from packets by the scheduler (from clients) or
by ip_vs_new_conn_out (from real servers) because later
such traffic can not hit the connection due to the
NO_CPORT requirement. As result, it can lead to duplicate
connection for every packet. Do the same for vport 0.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://sashiko.dev/#/patchset/20261104201530.147292-1-ja%40ssi.bg
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260925141115.16126-1-axel.mierczuk%401password.com
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_core.c | 3 ++-
net/netfilter/ipvs/ip_vs_proto_sctp.c | 7 +++++++
net/netfilter/ipvs/ip_vs_proto_tcp.c | 7 +++++++
net/netfilter/ipvs/ip_vs_proto_udp.c | 6 ++++++
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 8a3c880fdb26..f3eb72e95024 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -1305,6 +1305,7 @@ static inline bool is_new_conn_expected(const struct ip_vs_conn *cp,
* In fwmark-VS actual vaddr and vport are unknown to IPVS
* 2) Real Server and Virtual Service were NOT configured without port:
* This is to allow match of different VS to the same RS ip-addr
+ * 3) Client port is not 0
*/
struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
struct ip_vs_dest *dest,
@@ -1328,7 +1329,7 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
/* check pre-requisites are satisfied */
if (svc->fwmark)
return NULL;
- if (!vport || !dport)
+ if (!vport || !dport || !cport)
return NULL;
/* for persistent service first create connection template */
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index fb8af6b15a39..cb34bcceb4f6 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -30,6 +30,7 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
sch = skb_header_pointer(skb, iph->len + sizeof(_sctph),
sizeof(_schunkh), &_schunkh);
if (sch) {
+ /* Accept packet without scheduling? */
if (sch->type == SCTP_CID_ABORT ||
!(sysctl_sloppy_sctp(ipvs) ||
sch->type == SCTP_CID_INIT))
@@ -56,6 +57,12 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
index fec0e8b47b71..25d4576d0e12 100644
--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
@@ -48,6 +48,7 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (likely(!ip_vs_iph_icmp(iph))) {
th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
if (th) {
+ /* Accept packet without scheduling? */
if (th->rst || !(sysctl_sloppy_tcp(ipvs) || th->syn))
return 1;
ports = &th->source;
@@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
index f32785682402..ab3ab9524168 100644
--- a/net/netfilter/ipvs/ip_vs_proto_udp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
@@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
2026-11-16 0:44 ` [PATCH net 10/11] ipvs: do not create conns from packets with port 0 Pablo Neira Ayuso
@ 2026-11-17 1:40 ` netdev-bot+sashiko
2026-11-17 10:00 ` Paolo Abeni
0 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 1:40 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] udp_conn_schedule() (net/netfilter/ipvs/ip_vs_proto_udp.c) now
drops every UDP packet with source or destination port 0 that matches…
- [Low] The commit message explains rejecting cport 0 (the NO_CPORT
lookup requirement makes such connections impossible to find again),…
--
ipvs: do not create conns from packets with port 0
This commit makes tcp_conn_schedule(), udp_conn_schedule() and
sctp_conn_schedule() drop new packets that match a virtual service when
either the source or the destination port is 0. It also makes
ip_vs_new_conn_out() refuse to create connections for client port 0. The
stated reason is that cport 0 connections cannot be found again because
of the NO_CPORT lookup requirement, so a new connection gets created for
every packet.
Link: https://sashiko.dev/#/patchset/20261104201530.147292-1-ja%40ssi.bg
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260925141115.16126-1-axel.mierczuk%401password.com
> diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
> index fec0e8b47b716..25d4576d0e129 100644
> --- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
> +++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
[ ... ]
> @@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
> if (svc) {
> int ignored;
>
> + /* Do not create connection for port 0 */
> + if (!ports[0] || !ports[1]) {
> + *verdict = NF_DROP;
> + return 0;
> + }
[Severity: Low]
The commit message gives a reason for rejecting cport 0, then says "Do
the same for vport 0." without giving one. Does the duplicate connection
problem apply to the virtual port at all?
__ip_vs_conn_in_get() compares vport with plain equality. Only p->cport
takes part in the XOR:
if (p->cport == cp->cport &&
p->vport == cp->vport && cp->af == p->af &&
...
(!p->cport ^
(!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
ip_vs_conn_out_get() also matches the server side port with plain
equality. Its XOR uses p->vport, which in the out direction is the client
port:
if (p->cport == sport && cp->af == p->af &&
...
(!p->vport ^
(!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
So a hashed connection with vport 0 and a non-zero cport looks like it
can still be found, and would not be duplicated on every packet.
Before this patch, packets to destination port 0 that hit fwmark services
or persistent port-zero services were scheduled and forwarded. The
!ports[1] check (or !ports[0] in the inverse case) now drops them. The
same check is in udp_conn_schedule() and sctp_conn_schedule().
If this is meant as a policy change, for example because port 0 is not
valid on the wire, could the commit message say so? That would help
reviewers and stable backporters judge it.
[ ... ]
> diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
> index f32785682402d..ab3ab95241687 100644
> --- a/net/netfilter/ipvs/ip_vs_proto_udp.c
> +++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
> @@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
> if (svc) {
> int ignored;
>
> + /* Do not create connection for port 0 */
> + if (!ports[0] || !ports[1]) {
> + *verdict = NF_DROP;
> + return 0;
> + }
[Severity: Medium]
Should one-packet scheduling (OPS) UDP services be excluded from this
check?
The check runs before ip_vs_schedule() sets IP_VS_CONN_F_ONE_PACKET, so
it also drops port 0 traffic for services with IP_VS_SVC_F_ONEPACKET.
OPS connections are never inserted into the connection table:
net/netfilter/ipvs/ip_vs_conn.c:ip_vs_conn_hash() {
...
if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
return 0;
...
}
They are also freed right after use. So the NO_CPORT mismatch in
__ip_vs_conn_in_get() cannot cause duplicate connections for them:
(!p->cport ^
(!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
Before this patch, OPS UDP traffic from client port 0 was scheduled and
forwarded. RFC 768 allows source port 0 for one-way UDP, and that is the
traffic OPS is meant for. With this patch those packets are dropped.
The new !cport check in ip_vs_new_conn_out() has the same scope:
if (!vport || !dport || !cport)
return NULL;
It returns before the IP_VS_CONN_F_ONE_PACKET flags are computed. As a
result, OPS UDP initiated by a real server toward client port 0 gets no
connection, and leaves the director without SNAT.
The commit message says it will "disallow normal connections ... to be
created". It doesn't mention that matching packets are now dropped, or
that OPS services are affected too.
Could OPS services be exempted here and in ip_vs_new_conn_out()? If not,
could the commit message describe the dropping?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
2026-11-17 1:40 ` netdev-bot+sashiko
@ 2026-11-17 10:00 ` Paolo Abeni
2026-11-17 10:50 ` Julian Anastasov
0 siblings, 1 reply; 23+ messages in thread
From: Paolo Abeni @ 2026-11-17 10:00 UTC (permalink / raw)
To: pablo, Julian Anastasov
Cc: netfilter-devel, davem, netdev, kuba, edumazet, horms, fw, ja,
netdev-bot+sashiko
On 11/17/26 02:40, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] udp_conn_schedule() (net/netfilter/ipvs/ip_vs_proto_udp.c) now
> drops every UDP packet with source or destination port 0 that matches…
AFAICS this is the only new/unaddressed comment in this revision.
@Julian: could you please have a look?
Likely no additional revision needed, a confirmation this under control
would suffice.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
2026-11-17 10:00 ` Paolo Abeni
@ 2026-11-17 10:50 ` Julian Anastasov
0 siblings, 0 replies; 23+ messages in thread
From: Julian Anastasov @ 2026-11-17 10:50 UTC (permalink / raw)
To: Paolo Abeni
Cc: pablo, netfilter-devel, davem, netdev, kuba, edumazet, horms, fw,
netdev-bot+sashiko
[-- Attachment #1: Type: text/plain, Size: 1280 bytes --]
Hello,
On Tue, 17 Nov 2026, Paolo Abeni wrote:
> On 11/17/26 02:40, netdev-bot+sashiko@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 2 potential
> > issue(s) to consider.
> >
> > Critical: 0 · High: 0 · Medium: 1 · Low: 1
> >
> > If you believe none of the issues are legitimate, please reply to each
> > issue of Medium severity or higher and explain why the AI is wrong.
> > If any of them are legitimate and you plan to respin, please let patchwork
> > know by including "pw-bot: cr" as a separate line at the end of your reply
> > (one such reply per series is enough).
> >
> > - [Medium] udp_conn_schedule() (net/netfilter/ipvs/ip_vs_proto_udp.c) now
> > drops every UDP packet with source or destination port 0 that matches…
> AFAICS this is the only new/unaddressed comment in this revision.
>
> @Julian: could you please have a look?
RFC 768 allows source port 0 for one-way UDP but
due to the NO_CPORT usage we do not allow it. I assume
server port 0 is not allowed because we can not bind on
port 0. That is why vport 0 is disallowed too, only for IPVS
traffic.
> Likely no additional revision needed, a confirmation this under control
> would suffice.
>
> Thanks,
>
> Paolo
Regards
--
Julian Anastasov <ja@ssi.bg>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH net 11/11] ipvs: wait grace period before reusing destinations
2026-11-16 0:43 [PATCH net,v2 00/11] IPVS fixes for net Pablo Neira Ayuso
` (9 preceding siblings ...)
2026-11-16 0:44 ` [PATCH net 10/11] ipvs: do not create conns from packets with port 0 Pablo Neira Ayuso
@ 2026-11-16 0:44 ` Pablo Neira Ayuso
2026-11-17 1:40 ` netdev-bot+sashiko
10 siblings, 1 reply; 23+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-16 0:44 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Darong Lu <zzyy19904204639@163.com>
An IPVS destination can be removed from a service and immediately reused
from dest_trash before an RCU grace period has elapsed. Reusing its n_list
or d_list can make existing readers follow links into another service or
real-server hash chain.
The grace-period cookie is also saved when a live destination is unhashed
for an edit and consumed when it is rehashed. Describe rcu_state as the
cookie for an unlink, covering both trash and rehash cases.
When a destination is retrieved from dest_trash, ip_vs_add_dest() currently
restarts its estimator before waiting for the grace period.
If the estimator was on a tick chain, ip_vs_stop_estimator() removed
est->list with hlist_del_rcu(), so an estimator kthread can still be
traversing that node.
ip_vs_start_estimator() rewrites the node on its temporary list on success,
or initializes it on failure, before the current wait. A reader can then
follow the changed link or stop traversing the chain early.
Wait immediately after retrieving the destination, before starting its
estimator. The conditional grace-period wait then covers the destination
list, real-server hash and estimator list on both estimator success and
failure paths.
Fixes: bcbde4c0a755 ("ipvs: make the service replacement more robust")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Reported-by: Darong Lu <zzyy19904204639@163.com>
Co-developed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Signed-off-by: Darong Lu <zzyy19904204639@163.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/ip_vs.h | 4 +-
net/netfilter/ipvs/ip_vs_ctl.c | 110 ++++++++++++++++++++++++++-------
2 files changed, 91 insertions(+), 23 deletions(-)
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index c1f7a3f144f1..8dc80d5d42dc 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -1021,7 +1021,9 @@ struct ip_vs_dest {
struct rcu_head rcu_head;
struct list_head t_list; /* in dest_trash */
- unsigned int in_rs_table:1; /* we are in rs_table */
+ unsigned long rcu_state; /* GP cookie on unlink (trash or rehash) */
+ unsigned int in_rs_table:1, /* we are in rs_table */
+ need_gp:1; /* Need GP on rehash */
};
/* The scheduler object */
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 5868adda6ed6..be818bf7d380 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -64,7 +64,8 @@ int ip_vs_get_debug_level(void)
/* Protos */
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup);
#ifdef CONFIG_IP_VS_IPV6
@@ -918,6 +919,11 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)
*/
hash = ip_vs_rs_hashkey(dest->af, &dest->addr, port);
+ /* Need RCU grace period when rehashing */
+ if (dest->need_gp) {
+ cond_synchronize_rcu(dest->rcu_state);
+ dest->need_gp = 0;
+ }
hlist_add_head_rcu(&dest->d_list, &ipvs->rs_table[hash]);
dest->in_rs_table = 1;
}
@@ -1111,6 +1117,8 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
struct ip_vs_dest *dest;
struct netns_ipvs *ipvs = svc->ipvs;
+ lockdep_assert_held(&ipvs->service_mutex);
+
/*
* Find the destination in trash
*/
@@ -1144,24 +1152,57 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
return dest;
}
-/* Put destination in trash */
-static void ip_vs_trash_put_dest(struct netns_ipvs *ipvs,
+/* Add destination in temp list for trash */
+static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs,
struct ip_vs_dest *dest, unsigned long istart,
- bool cleanup)
+ struct list_head *dest_trash)
{
- spin_lock_bh(&ipvs->dest_trash_lock);
IP_VS_DBG_BUF(3, "Moving dest %s:%u into trash, dest->refcnt=%d\n",
IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port),
refcount_read(&dest->refcnt));
+ /* dest lives in trash with reference */
+ list_add(&dest->t_list, dest_trash);
+ dest->idle_start = istart;
+}
+
+/* Put destinations in trash */
+static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ spin_lock_bh(&ipvs->dest_trash_lock);
if (list_empty(&ipvs->dest_trash) && !cleanup)
mod_timer(&ipvs->dest_trash_timer,
jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1));
- /* dest lives in trash with reference */
- list_add(&dest->t_list, &ipvs->dest_trash);
- dest->idle_start = istart;
+ list_splice(dest_trash, &ipvs->dest_trash);
spin_unlock_bh(&ipvs->dest_trash_lock);
}
+/* Put destination back in trash */
+static void ip_vs_trash_put_back(struct netns_ipvs *ipvs,
+ struct ip_vs_dest *dest)
+{
+ LIST_HEAD(dest_trash);
+
+ ip_vs_trash_add_dest(ipvs, dest, dest->idle_start, &dest_trash);
+ ip_vs_trash_put_dests(ipvs, &dest_trash, false);
+}
+
+/* Put destinations in trash and save the RCU state */
+static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ struct ip_vs_dest *dest;
+ unsigned long rcu_state;
+
+ if (!list_empty(dest_trash)) {
+ /* Remember when dests were removed and added to dest_trash */
+ rcu_state = get_state_synchronize_rcu();
+ list_for_each_entry(dest, dest_trash, t_list)
+ dest->rcu_state = rcu_state;
+ ip_vs_trash_put_dests(ipvs, dest_trash, cleanup);
+ }
+}
+
static void ip_vs_dest_rcu_free(struct rcu_head *head)
{
struct ip_vs_dest *dest;
@@ -1377,8 +1418,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if ((udest->conn_flags & IP_VS_CONN_F_FWD_MASK) !=
IP_VS_DFWD_METHOD(dest) ||
udest->tun_type != dest->tun_type ||
- udest->tun_port != dest->tun_port)
+ udest->tun_port != dest->tun_port) {
+ bool unlinked = dest->in_rs_table;
+
ip_vs_rs_unhash(dest);
+ if (unlinked) {
+ dest->rcu_state = get_state_synchronize_rcu();
+ /* Need grace period in this or next dest update */
+ dest->need_gp = 1;
+ }
+ }
/* set the tunnel info */
dest->tun_type = udest->tun_type;
@@ -1562,6 +1611,11 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
if (dest != NULL) {
+ /* Readers may still follow the n_list, d_list or estimator list
+ * links. Wait before reusing any of them.
+ */
+ cond_synchronize_rcu(dest->rcu_state);
+
IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
"dest->refcnt=%d, service %u/%s:%u\n",
IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport),
@@ -1572,11 +1626,14 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
ret = ip_vs_start_estimator(svc->ipvs, &dest->stats);
/* On error put back dest into the trash */
- if (ret < 0)
- ip_vs_trash_put_dest(svc->ipvs, dest, dest->idle_start,
- false);
- else
+ if (ret < 0) {
+ ip_vs_trash_put_back(svc->ipvs, dest);
+ } else {
+ /* need_gp matters only on dest edit, reinit it */
+ dest->need_gp = 0;
+
__ip_vs_update_dest(svc, dest, udest, 1);
+ }
} else {
/*
* Allocate and initialize the dest structure
@@ -1640,7 +1697,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
* Delete a destination (must be already unlinked from the service)
*/
static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
- bool cleanup)
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_stop_estimator(ipvs, &dest->stats);
@@ -1649,7 +1706,7 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
*/
ip_vs_rs_unhash(dest);
- ip_vs_trash_put_dest(ipvs, dest, 0, cleanup);
+ ip_vs_trash_add_dest(ipvs, dest, 0, dest_trash);
/* Queue up delayed work to expire all no destination connections.
* No-op when CONFIG_SYSCTL is disabled.
@@ -1699,6 +1756,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
{
struct ip_vs_dest *dest;
__be16 dport = udest->port;
+ LIST_HEAD(dest_trash);
/* We use function that requires RCU lock */
rcu_read_lock();
@@ -1718,7 +1776,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
/*
* Delete the destination
*/
- __ip_vs_del_dest(svc->ipvs, dest, false);
+ __ip_vs_del_dest(svc->ipvs, dest, &dest_trash, false);
+
+ ip_vs_trash_save_dests(svc->ipvs, &dest_trash, false);
return 0;
}
@@ -2063,7 +2123,8 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
* - The service must be unlinked, unlocked and not referenced!
* - We are called under _bh lock
*/
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
struct ip_vs_dest *dest, *nxt;
struct ip_vs_scheduler *old_sched;
@@ -2097,7 +2158,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
*/
list_for_each_entry_safe(dest, nxt, &svc->destinations, n_list) {
__ip_vs_unlink_dest(svc, dest, 0);
- __ip_vs_del_dest(svc->ipvs, dest, cleanup);
+ __ip_vs_del_dest(svc->ipvs, dest, dest_trash, cleanup);
}
/*
@@ -2120,7 +2181,8 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
/*
* Unlink a service from list and try to delete it if its refcnt reached 0
*/
-static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
+static void ip_vs_unlink_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_unregister_conntrack(svc);
/* Hold svc to avoid double release from dest_trash */
@@ -2130,7 +2192,7 @@ static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
*/
ip_vs_svc_unhash(svc);
- __ip_vs_del_service(svc, cleanup);
+ __ip_vs_del_service(svc, dest_trash, cleanup);
}
/*
@@ -2140,12 +2202,14 @@ static int ip_vs_del_service(struct ip_vs_service *svc)
{
struct netns_ipvs *ipvs;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
int ns;
if (svc == NULL)
return -EEXIST;
ipvs = svc->ipvs;
- ip_vs_unlink_service(svc, false);
+ ip_vs_unlink_service(svc, &dest_trash, false);
+ ip_vs_trash_save_dests(ipvs, &dest_trash, false);
/* Drop the table if no more services */
ns = ip_vs_get_num_services(ipvs);
@@ -2196,6 +2260,7 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
struct hlist_bl_node *ne;
struct hlist_bl_node *e;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
/* Stop the resizer and drop the tables */
if (!test_and_set_bit(IP_VS_WORK_SVC_NORESIZE, &ipvs->work_flags))
@@ -2205,8 +2270,9 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
if (ip_vs_get_num_services(ipvs)) {
ip_vs_rht_walk_buckets(ipvs->svc_table, head) {
hlist_bl_for_each_entry_safe(svc, e, ne, head, s_list)
- ip_vs_unlink_service(svc, cleanup);
+ ip_vs_unlink_service(svc, &dest_trash, cleanup);
}
+ ip_vs_trash_save_dests(ipvs, &dest_trash, cleanup);
}
/* Unregister the hash table and release it after RCU grace period */
--
2.47.3
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH net 11/11] ipvs: wait grace period before reusing destinations
2026-11-16 0:44 ` [PATCH net 11/11] ipvs: wait grace period before reusing destinations Pablo Neira Ayuso
@ 2026-11-17 1:40 ` netdev-bot+sashiko
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 1:40 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message describes pre-patch code that does not exist.
Pre-existing issues:
- [Low] The header comment on __ip_vs_del_service() in
net/netfilter/ipvs/ip_vs_ctl.c still says " * - We are called under…
--
ipvs: wait grace period before reusing destinations
This patch saves an RCU grace-period cookie when an IPVS destination is
moved to dest_trash or unhashed for an edit. It then waits with
cond_synchronize_rcu() before the destination's n_list, d_list or
estimator list links are reused. Trash additions are collected in a
temporary list, so one cookie is taken after all unlinks in a delete or
flush.
> When a destination is retrieved from dest_trash, ip_vs_add_dest() currently
> restarts its estimator before waiting for the grace period.
[ ... ]
> ip_vs_start_estimator() rewrites the node on its temporary list on success,
> or initializes it on failure, before the current wait. A reader can then
> follow the changed link or stop traversing the chain early.
>
> Wait immediately after retrieving the destination, before starting its
> estimator.
[Severity: Low]
Does this paragraph match the tree being patched? It reads as if an
existing grace-period wait is being moved earlier. However, the baseline
ip_vs_add_dest() has no wait between ip_vs_trash_get_dest() and
ip_vs_start_estimator():
net/netfilter/ipvs/ip_vs_ctl.c:ip_vs_add_dest() {
...
dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
if (dest != NULL) {
IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
...
ret = ip_vs_start_estimator(svc->ipvs, &dest->stats);
...
}
This patch adds cond_synchronize_rcu(dest->rcu_state) from scratch, along
with the rcu_state and need_gp bookkeeping. The phrases "currently" and
"before the current wait" seem to describe an earlier revision of the
patch, where the wait came after ip_vs_start_estimator().
Since this is Cc: stable, could the paragraph be reworded to describe the
new wait being added, so backporters don't go looking for an existing wait
to move?
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index 5868adda6ed6e..be818bf7d3806 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
[ ... ]
> @@ -2063,7 +2123,8 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
> * - The service must be unlinked, unlocked and not referenced!
> * - We are called under _bh lock
> */
> -static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
> +static void __ip_vs_del_service(struct ip_vs_service *svc,
> + struct list_head *dest_trash, bool cleanup)
> {
> struct ip_vs_dest *dest, *nxt;
> struct ip_vs_scheduler *old_sched;
[Severity: Low]
This isn't a bug introduced by this patch, but is the "We are called
under _bh lock" line above __ip_vs_del_service() still accurate?
__ip_vs_del_service() calls ip_vs_stop_estimator() for svc->stats. It
also calls it for each dest through __ip_vs_del_dest(). Both of these can
sleep:
net/netfilter/ipvs/ip_vs_est.c:ip_vs_stop_estimator() {
...
if (ktid > 0) {
mutex_lock(&ipvs->est_mutex);
ip_vs_est_kthread_destroy(kd);
...
}
The callers are ip_vs_del_service() and ip_vs_flush(), both through
ip_vs_unlink_service(). They run in process context under service_mutex,
not under a BH lock.
Since this patch already changes the signature here, could the stale
comment line be dropped or corrected at the same time?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
^ permalink raw reply [flat|nested] 23+ messages in thread