Netdev List
 help / color / mirror / Atom feed
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 05/11] ipvs: update flags and seqs in backup server under lock
Date: Tue, 17 Nov 2026 01:40:31 +0000	[thread overview]
Message-ID: <179487963105.3136.8669444891088576096@kernel.org> (raw)
In-Reply-To: <20261116004404.2821183-6-pablo@netfilter.org>

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

  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 [this message]
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
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=179487963105.3136.8669444891088576096@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