IPVS fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainerv2 cover IPVS fixes for net
v2: keeping back previous 1, 2, 7 and 15 as discussed with Julian.
-o-
Hi,
The following patchset contains IPVS fixes for net:
1) Rework connection refcounting so the pending and running timer hold a reference. This fixes a use-after-free race between connection deletion and a concurrent timer callback, from Julian Anastasov.
2) Expire controlled connection chains iteratively instead of recursively to avoid kernel stack exhaustion, from Zihan Xi.
3) Reject zero and configured FTP control ports as data ports in the FTP helper, from Zihan Xi.
4) Skip conntrack templates in ip_vs_ftp_out() to fix a UAF in the expectation list after the CT rule is removed, from Theodor Arsenij Larionov Trichkine.
5) Update conn flags, seqs and related fields in the backup server
under cp->lock, from Julian Anastasov.
6) Read conn flags and seqs atomically in the master when building sync messages, from Julian Anastasov.
7) Fix a race that can leave a destination in the overload state forever. Also make the LBLC/LBLCR schedulers honor the overload state for cached destinations, from Julian Anastasov.
8) Validate cport and IP_VS_CONN_F_NO_CPORT in received sync records. This rejects templates and connections that incoming lookups cannot match, from Axel Mierczuk.
9) Skip cport 0 connections in ip_vs_conn_out_get(), using the same rule as __ip_vs_conn_in_get(). Also from Axel.
10) Do not create connections from packets with client or virtual port 0, which could create a duplicate connection for every packet, from Julian Anastasov.
11) Wait for an RCU grace period before reusing a destination from dest_trash, and before restarting its estimator, from Darong Lu.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-11-16
Thanks.
----------------------------------------------------------------
The following changes since commit d1bb235aa409a4e5aeba6c748d953d948625b1e9:
netfilter: nat: zero newrange before filling it in (2026-11-05 13:31:11 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-11-16
for you to fetch changes up to 5367e14e92bbb0779612d36cce7c6e95d3bc5e68:
ipvs: wait grace period before reusing destinations (2026-11-16 01:40:31 +0100)
----------------------------------------------------------------
netfilter pull request 26-11-16
----------------------------------------------------------------
Axel Mierczuk (2):
ipvs: validate cport in received sync records
ipvs: skip cport 0 connections in ip_vs_conn_out_get()
Darong Lu (1):
ipvs: wait grace period before reusing destinations
Julian Anastasov (5):
ipvs: fix problems during connection deletion
ipvs: update flags and seqs in backup server under lock
ipvs: read flags and seqs in master atomically
ipvs: honor the overload state and do not enter it forever
ipvs: do not create conns from packets with port 0
Theodor Arsenij Larionov Trichkine (1):
ipvs: ftp: skip conntrack templates in ip_vs_ftp_out
Zihan Xi (2):
ipvs: avoid stack overflow from recursive connection expiration
ipvs: reject FTP control ports as data ports
include/net/ip_vs.h | 7 +- net/netfilter/ipvs/ip_vs_conn.c | 131 ++++++++++++++++++------------- net/netfilter/ipvs/ip_vs_core.c | 3 +- net/netfilter/ipvs/ip_vs_ctl.c | 140 +++++++++++++++++++++++++--------- net/netfilter/ipvs/ip_vs_ftp.c | 20 ++++- net/netfilter/ipvs/ip_vs_lblc.c | 8 +- net/netfilter/ipvs/ip_vs_lblcr.c | 13 ++-- 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 ++ net/netfilter/ipvs/ip_vs_sync.c | 53 +++++++++++-- 11 files changed, 289 insertions(+), 106 deletions(-)
Pablo Neira Ayuso
maintainerPATCH v2 1/11 ipvs: fix problems during connection deletion
From: Julian Anastasov <[email protected]>
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.
--- 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(-)
include/net/ip_vs.h +0 -1
@@ -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);
net/netfilter/ipvs/ip_vs_conn.c +54 -45
179 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -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
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 01/11] ipvs: fix problems during connection deletion
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
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.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Pablo Neira Ayuso
maintainerRe: [PATCH net 01/11] ipvs: fix problems during connection deletion
Quoted 9 lines · On Mon, Nov 16, 2026 at 12:47:24AM +0000, [email protected] 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.
Quoted 7 lines
- 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.
Quoted 6 lines
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net 01/11] ipvs: fix problems during connection deletion
In reply to Pablo Neira AyusoThis series was applied to netdev/net.git (main) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <[email protected]>:
Quoted 17 lines · On Mon, 16 Nov 2026 01:43:54 +0100 you wrote:
From: Julian Anastasov <[email protected]>
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 itscp->controlchain withip_vs_conn_del_put()without holding a RCU read lock.
Quoted 1 line
[...]
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH v2 2/11 ipvs: avoid stack overflow from recursive connection expiration
In reply to Pablo Neira AyusoFrom: Zihan Xi <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_conn.c | 40 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +29 -11
@@ -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.
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 3/11 ipvs: reject FTP control ports as data ports
In reply to Pablo Neira AyusoFrom: Zihan Xi <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_ftp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
net/netfilter/ipvs/ip_vs_ftp.c +18 -0
@@ -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 ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 03/11] ipvs: reject FTP control ports as data ports
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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).
Quoted 3 lines
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.
Quoted 4 lines
net/netfilter/ipvs/ip_vs_ftp.c +0
-0
[ ... ]
Quoted 12 lines
net/netfilter/ipvs/ip_vs_ftp.c +4
-0@@ -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;
net/netfilter/ipvs/ip_vs_ftp.c static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp, · line 552
Quoted 9 lines
net/netfilter/ipvs/ip_vs_ftp.c +3
-0@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Pablo Neira Ayuso
maintainerPATCH v2 4/11 ipvs: ftp: skip conntrack templates in ip_vs_ftp_out
In reply to Pablo Neira AyusoFrom: Theodor Arsenij Larionov Trichkine <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_ftp.c +1 -1
@@ -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
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 5/11 ipvs: update flags and seqs in backup server under lock
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_sync.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +6 -3
@@ -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 *paelse 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); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
Quoted 4 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-0
[ ... ]
Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-3@@ -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.
[ ... ]
net/netfilter/ipvs/ip_vs_sync.c static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa · line 956
Quoted 7 lines
net/netfilter/ipvs/ip_vs_sync.c +3
-0@@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *paelse 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?
Quoted 3 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-0ip_vs_conn_put (cp); }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Julian Anastasov
maintainerRe: [PATCH net 05/11] ipvs: update flags and seqs in backup server under lock
Hello,
Quoted 74 lines · On Tue, 17 Nov 2026, [email protected] 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->lockregion inip_vs_proc_conn()so that the backup server updates the conn flags, seqs, state,old_stateand timeout under the lock. Newly created conns now also takecp->lockbefore these updates.ip_vs_try_bind_dest()is now called after the unlock.Quoted 4 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-0[ ... ]
Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-3@@ -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. [ ... ]
net/netfilter/ipvs/ip_vs_sync.c static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa · line 956
Quoted 7 lines
net/netfilter/ipvs/ip_vs_sync.c +3
-0@@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *paelse 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 writecp->flagswithoutcp->lockthrough thisip_vs_try_bind_dest()call?
ip_vs_try_bind_dest()holdscp->lockonly aroundip_vs_unbind_app()andip_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); ... }
Quoted 6 lines
For a MASQ conn,
ip_vs_bind_app()reachestcp_app_conn_bind(), which setscp->appand callsinc->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.
Quoted 41 lines
return 0; }This is a non-atomic read-modify-write of
cp->flagson a conn that is already hashed. The other runtime writers ofcp->flagsholdcp->lock:-
set_tcp_state()andset_sctp_state()toggleIP_VS_CONN_F_INACTIVEand 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 setsIP_VS_CONN_F_INACTIVEundercp->lockand 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:
Quoted 11 lines
"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?
Quoted 3 lines
net/netfilter/ipvs/ip_vs_sync.c +0
-0ip_vs_conn_put (cp); }Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Regards
--
Julian Anastasov <[email protected]>
Pablo Neira Ayuso
maintainerPATCH v2 6/11 ipvs: read flags and seqs in master atomically
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_sync.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +20 -3
@@ -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 */
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 7/11 ipvs: honor the overload state and do not enter it forever
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
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.
--- 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(-)
include/net/ip_vs.h +1 -1
@@ -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)
net/netfilter/ipvs/ip_vs_conn.c +2 -2
@@ -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 */
net/netfilter/ipvs/ip_vs_ctl.c +18 -12
@@ -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;
net/netfilter/ipvs/ip_vs_lblc.c +5 -3
@@ -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; }
net/netfilter/ipvs/ip_vs_lblcr.c +7 -6
@@ -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;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 8/11 ipvs: validate cport in received sync records
In reply to Pablo Neira AyusoFrom: Axel Mierczuk <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_sync.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
net/netfilter/ipvs/ip_vs_sync.c +19 -0
@@ -871,6 +871,25 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pastruct 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) ||
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 9/11 ipvs: skip cport 0 connections in ip_vs_conn_out_get()
In reply to Pablo Neira AyusoFrom: Axel Mierczuk <[email protected]>
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.
--- net/netfilter/ipvs/ip_vs_conn.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/ipvs/ip_vs_conn.c +2 -0
@@ -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;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
net/netfilter/ipvs/ip_vs_conn.c struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p) · line 597
Quoted 13 lines
net/netfilter/ipvs/ip_vs_conn.c +2
-0@@ -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))
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Pablo Neira Ayuso
maintainerPATCH v2 10/11 ipvs: do not create conns from packets with port 0
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
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.
--- 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(-)
net/netfilter/ipvs/ip_vs_core.c +2 -1
@@ -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 */
net/netfilter/ipvs/ip_vs_proto_sctp.c +7 -0
@@ -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.
net/netfilter/ipvs/ip_vs_proto_tcp.c +7 -0
@@ -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.
net/netfilter/ipvs/ip_vs_proto_udp.c +6 -0
@@ -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.
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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.
Quoted 4 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +0
-0
[ ... ]
net/netfilter/ipvs/ip_vs_proto_tcp.c tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, · line 82
Quoted 9 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +5
-0@@ -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.
[ ... ]
net/netfilter/ipvs/ip_vs_proto_udp.c udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, · line 69
Quoted 13 lines
net/netfilter/ipvs/ip_vs_proto_udp.c +5
-0@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org
Paolo Abeni
maintainerRe: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
Quoted 5 lines · On 11/17/26 02:40, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
Quoted 8 lines
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
Julian Anastasov
maintainerRe: [PATCH net 10/11] ipvs: do not create conns from packets with port 0
Hello,
Quoted 12 lines · Paolo Abeni
Quoted 11 lines · On 11/17/26 02:40, [email protected] 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).
Quoted 5 lines
Quoted 2 lines
- [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.
Quoted 6 lines
Likely no additional revision needed, a confirmation this under control would suffice.
Thanks,
Paolo
Regards
--
Julian Anastasov <[email protected]>
Pablo Neira Ayuso
maintainerPATCH v2 11/11 ipvs: wait grace period before reusing destinations
In reply to Pablo Neira AyusoFrom: Darong Lu <[email protected]>
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.
--- include/net/ip_vs.h | 4 +- net/netfilter/ipvs/ip_vs_ctl.c | 110 ++++++++++++++++++++++++++------- 2 files changed, 91 insertions(+), 23 deletions(-)
include/net/ip_vs.h +3 -1
@@ -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 */
net/netfilter/ipvs/ip_vs_ctl.c +88 -22
237 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 11/11] ipvs: wait grace period before reusing destinations
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…
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.
Quoted 2 lines
When a destination is retrieved from
dest_trash,ip_vs_add_dest()currently restarts its estimator before waiting for the grace period.
[ ... ]
Quoted 6 lines
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?
Quoted 4 lines
net/netfilter/ipvs/ip_vs_ctl.c +0
-0
[ ... ]
net/netfilter/ipvs/ip_vs_ctl.c ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u) · line 2130
Quoted 10 lines
net/netfilter/ipvs/ip_vs_ctl.c +2
-1@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116004404.2821183-2-pablo%40netfilter.org