From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net 09/11] ipvs: skip cport 0 connections in ip_vs_conn_out_get()
Date: Tue, 17 Nov 2026 01:40:32 +0000 [thread overview]
Message-ID: <179487963213.3136.15958589947509607287@kernel.org> (raw)
In-Reply-To: <20261116004404.2821183-10-pablo@netfilter.org>
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
next prev parent reply other threads:[~2026-11-17 1:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
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:47 ` netdev-bot+sinfo
2026-11-16 0:48 ` 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 ` [PATCH net 03/11] ipvs: reject FTP control ports as data ports 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
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-16 0:43 ` [PATCH net 06/11] ipvs: read flags and seqs in master atomically 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
2026-11-16 0:44 ` [PATCH net 08/11] ipvs: validate cport in received sync records 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
2026-11-17 1:40 ` netdev-bot+sashiko [this message]
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-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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179487963213.3136.15958589947509607287@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox