Skip to contentSkip to conversation

ipvs: add per-service secure_tcp

PATCH Superseded Adriano Cordova 2 participants 7 messages Sep 20 – Sep 21

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover ipvs: add per-service secure_tcp

IPVS currently exposes secure_tcp as a per-netns sysctl. It switches the TCP state machine to the hardened tcp_states_dos table.

These patches make it per-service: a virtual service can set IP_VS_SVC_F_SECURE_TCP which is passed into IP_VS_CONN_F_SECURE_TCP at connection creation. set_tcp_state() then selects tcp_states_dos for those connections with IP_VS_CONN_F_SECURE_TCP set and keeps pd->tcp_state_table (the netns default, including the nomem floor) otherwise.

1. uapi: define the per-service secure_tcp flags and stamp the flag in ip_vs_bind_dest() (cache-bypass has no dest)
2. honor it in the TCP state machine, resolving the stale FIXME
3. kselftest contrasting a secure vs. a plain service

Changes in v2:
- Let IP_VS_SVC_F_SECURE_TCP be 0x0100, leaving 0x0040/0x0080 for the scheduler flags. Let IP_VS_CONN_F_SECURE_TCP be (1 << 17) and no longer in IP_VS_CONN_F_BACKUP_MASK.
- Set flag in ip_vs_bind_dest() instead of at every ip_vs_conn_new() call site.
- selftest: send probes with TTL=1 instead of an nft drop, and fix Sashiko comments.

Changes in v3:
- Merge patch 1/4 and 2/4
- Re-send patches (v2 dropped patches 3/4 and 4/4)

Changes in v4:
- selftest: check the return values of setsockopt(IP_HDRINCL), sendto() and mnl_socket_bind(), and fail do_add() when IPVS does not reply.
- selftest: fix the remaining Sashiko comments: check inet_pton(), initialize fam and the parsed addresses, and verify the flags attribute length before copying it.

Adriano Cordova (3):
ipvs: add flags for per-service secure TCP state table
ipvs: tcp: enable per-connection secure_tcp in state machine
selftests: netfilter: ipvs: add per-service secure_tcp test

 include/uapi/linux/ip_vs.h                    |   2 +
 net/netfilter/ipvs/ip_vs_conn.c               |   4 +
 net/netfilter/ipvs/ip_vs_core.c               |   3 +
 net/netfilter/ipvs/ip_vs_proto_tcp.c          |  16 +-
 .../testing/selftests/net/netfilter/Makefile  |   6 +
 .../selftests/net/netfilter/gen_tcp_probe.c   | 158 ++++++++
 .../net/netfilter/ipvs_secure_tcp.sh          | 153 ++++++++
 .../net/netfilter/ipvs_secure_tcp_mln.c       | 337 ++++++++++++++++++
 8 files changed, 672 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/net/netfilter/gen_tcp_probe.c
 create mode 100755 tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh
 create mode 100644 tools/testing/selftests/net/netfilter/ipvs_secure_tcp_mln.c

base-commit: 87b80c2f6b05cad9f0ff9136709c62a0f59923e3

Signature · 1 line
2.51.0
#1 lore raw

PATCH v4 1/3 ipvs: add flags for per-service secure TCP state table

Add IP_VS_SVC_F_SECURE_TCP to mark a virtual service for the DoS-hardened TCP connection state table, and IP_VS_CONN_F_SECURE_TCP to carry that capability on a connection so the TCP state machine can select the hardened table for it.

The service flag is 0x0100: bits 0x0008/0x0010/0x0020 are the scheduler bits, so leave 0x0040/0x0080 free for schedulers.

Set IP_VS_CONN_F_SECURE_TCP on every connection bound to a destination whose service carries IP_VS_SVC_F_SECURE_TCP.

---
Changes in v2:
- Let IP_VS_SVC_F_SECURE_TCP be 0x0100, leaving 0x0040/0x0080 free for scheduler flags.
- Let IP_VS_CONN_F_SECURE_TCP be (1 << 17) and drop it from IP_VS_CONN_F_BACKUP_MASK.
- Set the flag in ip_vs_bind_dest() instead of at every ip_vs_conn_new() call site.

Changes in v3:
- Merge the uapi flag definition and the ip_vs_bind_dest() stamping into a single patch.

(no changes since v3)

 include/uapi/linux/ip_vs.h      | 2 ++
 net/netfilter/ipvs/ip_vs_conn.c | 4 ++++
 net/netfilter/ipvs/ip_vs_core.c | 3 +++
 3 files changed, 9 insertions(+)
include/uapi/linux/ip_vs.h +2 -0
index 2c37c6ac7525..ade170109ff4 100644
@@ -27,6 +27,7 @@
 
 #define IP_VS_SVC_F_SCHED_SH_FALLBACK	IP_VS_SVC_F_SCHED1 /* SH fallback */
 #define IP_VS_SVC_F_SCHED_SH_PORT	IP_VS_SVC_F_SCHED2 /* SH use port */
+#define IP_VS_SVC_F_SECURE_TCP	0x0100		/* use the hardened TCP table */
 
 /*
  *      IPVS sync daemon states
@@ -105,6 +106,7 @@
 
 /* Flags that are not sent to backup server start from bit 16 */
 #define IP_VS_CONN_F_NFCT	(1 << 16)	/* use netfilter conntrack */
+#define IP_VS_CONN_F_SECURE_TCP	(1 << 17)	/* use the hardened TCP table */
 
 /* Connection flags from destination that can be changed by user space */
 #define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \
net/netfilter/ipvs/ip_vs_conn.c +4 -0
index 6fa3e1dc534c..0b465298b64b 100644
@@ -1090,6 +1090,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
 {
 	unsigned int conn_flags;
 	__u32 flags;
+	struct ip_vs_service *svc;
 
 	/* if dest is NULL, then return directly */
 	if (!dest)
@@ -1102,6 +1103,9 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
 	if (cp->protocol != IPPROTO_UDP)
 		conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
 	flags = cp->flags;
+	svc = rcu_dereference(dest->svc);
+	if (svc && (svc->flags & IP_VS_SVC_F_SECURE_TCP))
+		flags |= IP_VS_CONN_F_SECURE_TCP;
 	/* Bind with the destination and its corresponding transmitter */
 	if (flags & IP_VS_CONN_F_SYNC) {
 		/* Synced conns are hashed, so they can not get this flag */
net/netfilter/ipvs/ip_vs_core.c +3 -0
index ba0957798bad..aa8a3a964ffd 100644
@@ -784,6 +784,9 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
 				      IP_VS_CONN_F_ONE_PACKET : 0;
 		union nf_inet_addr daddr = { .all = { 0, 0, 0, 0 } };
 
+		if (svc->flags & IP_VS_SVC_F_SECURE_TCP)
+			flags |= IP_VS_CONN_F_SECURE_TCP;
+
 		/* create a new connection entry */
 		IP_VS_DBG(6, "%s(): create a cache_bypass entry\n", __func__);
 		{
Signature · 1 line
2.51.0
#3 lore raw

PATCH v4 2/3 ipvs: tcp: enable per-connection secure_tcp in state machine

In reply to Adriano Cordova

Let set_tcp_state select tcp_states_dos when the connection carries IP_VS_CONN_F_SECURE_TCP, otherwise keep using the global pd->tcp_state_table (the netns default / or if nomem).

---
(no changes since v1)

 net/netfilter/ipvs/ip_vs_proto_tcp.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_proto_tcp.c +9 -7
index fec0e8b47b71..3b9a2c8e9a52 100644
@@ -451,11 +451,10 @@ static void tcp_timeout_change(struct ip_vs_proto_data *pd, int flags)
 	int on = (flags & 1);		/* secure_tcp */
 
 	/*
-	** FIXME: change secure_tcp to independent sysctl var
-	** or make it per-service or per-app because it is valid
-	** for most if not for all of the applications. Something
-	** like "capabilities" (flags) for each object.
-	*/
+	 * This remains the netns-wide default / global floor (e.g. when
+	 * memory pressure kicks in). Per-service hardening is now carried
+	 * by IP_VS_CONN_F_SECURE_TCP on each connection (set_tcp_state).
+	 */
 	pd->tcp_state_table = (on ? tcp_states_dos : tcp_states);
 }
 
@@ -479,6 +478,7 @@ set_tcp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
 	int state_idx;
 	int new_state = IP_VS_TCP_S_CLOSE;
 	int state_off = tcp_state_off[direction];
+	const struct tcp_states_t *table;
 
 	/*
 	 *    Update state offset to INPUT_ONLY if necessary
@@ -496,8 +496,10 @@ set_tcp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
 		goto tcp_state_out;
 	}
 
-	new_state =
-		pd->tcp_state_table[state_off+state_idx].next_state[cp->state];
+	table = pd->tcp_state_table;
+	if (cp->flags & IP_VS_CONN_F_SECURE_TCP)
+		table = tcp_states_dos;
+	new_state = table[state_off + state_idx].next_state[cp->state];
 
   tcp_state_out:
 	if (new_state != cp->state) {
Signature · 1 line
2.51.0
#5 lore raw

PATCH v4 3/3 selftests: netfilter: ipvs: add per-service secure_tcp test

In reply to Adriano Cordova

Two services share a VIP, one carrying IP_VS_SVC_F_SECURE_TCP. A bare SYN+ACK suffices to test the state machine: the normal service reaches ESTABLISHED, but the secure one stays in SYN_RECV.

Assisted-by opencode:deepseek-flash

---
Changes in v2:
- send probes with TTL=1 instead of an nft drop, and fix Sashiko comments.

Changes in v4:
- Check the return value of setsockopt(IP_HDRINCL), sendto() and mnl_socket_bind(), and fail do_add() when IPVS does not reply.
- Check inet_pton(), initialize fam and the parsed addresses, and verify the flags attribute length before copying it (Sashiko).

 .../testing/selftests/net/netfilter/Makefile  |   6 +
 .../selftests/net/netfilter/gen_tcp_probe.c   | 158 ++++++++
 .../net/netfilter/ipvs_secure_tcp.sh          | 153 ++++++++
 .../net/netfilter/ipvs_secure_tcp_mln.c       | 337 ++++++++++++++++++
 4 files changed, 654 insertions(+)
 create mode 100644 tools/testing/selftests/net/netfilter/gen_tcp_probe.c
 create mode 100755 tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh
 create mode 100644 tools/testing/selftests/net/netfilter/ipvs_secure_tcp_mln.c
tools/testing/selftests/net/netfilter/Makefile +6 -0
index df3c20c90f5d..f88bf69cc874 100644
@@ -22,6 +22,7 @@ TEST_PROGS := \
 	conntrack_tcp_unreplied.sh \
 	conntrack_vrf.sh \
 	ipvs.sh \
+	ipvs_secure_tcp.sh \
 	nf_conntrack_packetdrill.sh \
 	nf_nat_edemux.sh \
 	nft_audit.sh \
@@ -52,6 +53,8 @@ TEST_GEN_FILES = \
 	connect_close \
 	conntrack_dump_flush \
 	conntrack_reverse_clash \
+	gen_tcp_probe \
+	ipvs_secure_tcp_mln \
 	nf_queue \
 	sctp_collision \
 	udpclash \
@@ -62,6 +65,9 @@ include ../../lib.mk
 $(OUTPUT)/nf_queue: CFLAGS += $(MNL_CFLAGS)
 $(OUTPUT)/nf_queue: LDLIBS += $(MNL_LDLIBS)
 
+$(OUTPUT)/ipvs_secure_tcp_mln: CFLAGS += $(MNL_CFLAGS)
+$(OUTPUT)/ipvs_secure_tcp_mln: LDLIBS += $(MNL_LDLIBS)
+
 $(OUTPUT)/conntrack_dump_flush: CFLAGS += $(MNL_CFLAGS)
 $(OUTPUT)/conntrack_dump_flush: LDLIBS += $(MNL_LDLIBS)
 $(OUTPUT)/udpclash: LDLIBS += -lpthread
tools/testing/selftests/net/netfilter/gen_tcp_probe.c new file +158 -0

158 lines not on this page · raw message

tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +153 -0

153 lines not on this page · raw message

tools/testing/selftests/net/netfilter/ipvs_secure_tcp_mln.c new file +337 -0

337 lines not on this page · raw message

Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v4 nf-next 1/3] ipvs: add flags for per-service secure TCP state table

In reply to Adriano Cordova
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] Reported for policy completeness only; my verification concludes this is NOT a defect in the series.

Pre-existing issues:
- [Low] Reported for policy completeness only; verified as a pre-existing cosmetic discrepancy with no functional effect.

--

ipvs: add flags for per-service secure TCP state table

This adds the uAPI bits IP_VS_SVC_F_SECURE_TCP (0x0100) and IP_VS_CONN_F_SECURE_TCP (1 << 17), and stamps the connection flag in ip_vs_bind_dest() for connections bound to a destination whose service carries the service flag, plus in the cache_bypass path of ip_vs_leave().

A couple of small observations on the new header bits below.

include/uapi/linux/ip_vs.h line 30

Quoted 9 lines
include/uapi/linux/ip_vs.h +1 -0
index 2c37c6ac7525..ade170109ff4 100644
@@ -27,6 +27,7 @@
 
 #define IP_VS_SVC_F_SCHED_SH_FALLBACK	IP_VS_SVC_F_SCHED1 /* SH fallback */
 #define IP_VS_SVC_F_SCHED_SH_PORT	IP_VS_SVC_F_SCHED2 /* SH use port */
+#define IP_VS_SVC_F_SECURE_TCP	0x0100		/* use the hardened TCP table */

[Severity: Low]
Both new bits are documented as "use the hardened TCP table", but nothing in this commit reads either of them, so in this tree state the bits are accepted from user space and stamped onto connections without changing behaviour.

Checking the rest of the series, the consumer does arrive in the following patch, "ipvs: tcp: enable per-connection secure_tcp in state machine", which changes set_tcp_state() in net/netfilter/ipvs/ip_vs_proto_tcp.c to:

	table = pd->tcp_state_table;
	if (cp->flags & IP_VS_CONN_F_SECURE_TCP)
		table = tcp_states_dos;
	new_state = table[state_off + state_idx].next_state[cp->state];

So by the end of the series the header comment matches the implementation and this looks like a plain producer/consumer split rather than a defect. Noting it only in case the intermediate state matters for bisect, since the bit is settable by CAP_NET_ADMIN through ip_vs_ctl.c before it has any effect.

include/uapi/linux/ip_vs.h line 109

Quoted 8 lines
include/uapi/linux/ip_vs.h +1 -0
 /*
  *      IPVS sync daemon states
@@ -105,6 +106,7 @@
 
 /* Flags that are not sent to backup server start from bit 16 */
 #define IP_VS_CONN_F_NFCT	(1 << 16)	/* use netfilter conntrack */
+#define IP_VS_CONN_F_SECURE_TCP	(1 << 17)	/* use the hardened TCP table */

[Severity: Low]
This isn't an issue introduced by this patch, but the new bit lands under the comment saying these flags are not sent to the backup server, while the v1 serializer actually puts the whole flags word on the wire.

net/netfilter/ipvs/ip_vs_sync.c:ip_vs_sync_conn()

	s->v4.flags = htonl(cp->flags & ~IP_VS_CONN_F_HASHED);

So a connection carrying IP_VS_CONN_F_SECURE_TCP does transmit bit 17.

The receiving side drops it again in ip_vs_process_message_v1():

	flags  = ntohl(s->v4.flags) & IP_VS_CONN_F_BACKUP_MASK;

and IP_VS_CONN_F_BACKUP_MASK only contains FWD_MASK, NOOUTPUT, INACTIVE, SEQ_MASK, NO_CPORT and TEMPLATE, so no high bit survives on the backup.

IP_VS_CONN_F_NFCT at bit 16 is already transmitted the same way, so the mismatch between the comment and the wire format predates this change; this just adds one more flag to it. Would it be worth adjusting the comment to say the backup masks these bits off on receive rather than that they are not sent?

Quoted 3 lines
include/uapi/linux/ip_vs.h +0 -0
 /* Connection flags from destination that can be changed by user space */
 #define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260920054708.988867-1-adrianox%40gmail.com
#4 lore raw

Re: [PATCH v4 nf-next 2/3] ipvs: tcp: enable per-connection secure_tcp in state machine

In reply to Adriano Cordova
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] Documentation/networking/ipvs-sysctl.rst:283-288 documents the hardened ("more complicated") TCP state transition table as reachable…

--

ipvs: tcp: enable per-connection secure_tcp in state machine

This changes set_tcp_state() so that a connection carrying IP_VS_CONN_F_SECURE_TCP is driven by tcp_states_dos instead of pd->tcp_state_table, leaving the netns-wide table as the fallback. The old FIXME comment in tcp_timeout_change() is replaced with a note describing the sysctl as the netns-wide default.

Quoted 9 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +0 -1
index fec0e8b47b71..3b9a2c8e9a52 100644
@@ -451,11 +451,10 @@ static void tcp_timeout_change(struct ip_vs_proto_data *pd, int flags)
 	int on = (flags & 1);		/* secure_tcp */
 
 	/*
-	** FIXME: change secure_tcp to independent sysctl var

net/netfilter/ipvs/ip_vs_proto_tcp.c static void tcp_timeout_change(struct ip_vs_proto_data *pd, int flags) · line 459

Quoted 10 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +4 -4
-	** or make it per-service or per-app because it is valid
-	** for most if not for all of the applications. Something
-	** like "capabilities" (flags) for each object.
-	*/
+	 * This remains the netns-wide default / global floor (e.g. when
+	 * memory pressure kicks in). Per-service hardening is now carried
+	 * by IP_VS_CONN_F_SECURE_TCP on each connection (set_tcp_state).
+	 */
 	pd->tcp_state_table = (on ? tcp_states_dos : tcp_states);
 }

[Severity: Low]
Should Documentation/networking/ipvs-sysctl.rst be updated along with this comment change?

The only in-tree description of the hardened table currently ties it exclusively to the sysctl:

Documentation/networking/ipvs-sysctl.rst:

secure_tcp - INTEGER
- 0 - disabled (default)

The secure_tcp defense is to use a more complicated TCP state transition table. ...

The new comment recharacterises that knob as a netns-wide default/floor, but the .rst still reads as if 0 means no connection uses the hardened table.

Quoted 6 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -0
@@ -479,6 +478,7 @@ set_tcp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
 	int state_idx;
 	int new_state = IP_VS_TCP_S_CLOSE;
 	int state_off = tcp_state_off[direction];
+	const struct tcp_states_t *table;

[ ... ]

net/netfilter/ipvs/ip_vs_proto_tcp.c set_tcp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp, · line 502

Quoted 10 lines
net/netfilter/ipvs/ip_vs_proto_tcp.c +4 -2
@@ -496,8 +496,10 @@ set_tcp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
 		goto tcp_state_out;
 	}
 
-	new_state =
-		pd->tcp_state_table[state_off+state_idx].next_state[cp->state];
+	table = pd->tcp_state_table;
+	if (cp->flags & IP_VS_CONN_F_SECURE_TCP)
+		table = tcp_states_dos;
+	new_state = table[state_off + state_idx].next_state[cp->state];

[Severity: Low]
With this override in set_tcp_state(), can an operator still conclude from net.ipv4.vs.secure_tcp = 0 that no connection is using tcp_states_dos?

A service carrying the new IP_VS_SVC_F_SECURE_TCP bit (include/uapi/linux/ip_vs.h, settable via IPVS_SVC_ATTR_FLAGS) propagates IP_VS_CONN_F_SECURE_TCP to its connections, and then set_tcp_state() picks tcp_states_dos regardless of the sysctl value, so for example SYN_RECV no longer advances to ESTABLISHED on a bare SYN+ACK.

There is no entry under Documentation/ for IP_VS_SVC_F_SECURE_TCP or for this new interaction with secure_tcp. Could a documentation update be added for the new user-settable flag?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260920054708.988867-1-adrianox%40gmail.com
#6 lore raw

Re: [PATCH v4 nf-next 3/3] selftests: netfilter: ipvs: add per-service secure_tcp test

In reply to Adriano Cordova
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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] tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh has no kernel-side prerequisite check and no $ksft_skip path.
- [Medium] The secure-service assertion cannot distinguish 'per-service secure_tcp worked' from 'the ACK probe never arrived'.
- [Low] The commit message states "A bare SYN+ACK suffices to test the state machine: the normal service reaches ESTABLISHED, but the secure…

--

selftests: netfilter: ipvs: add per-service secure_tcp test

This adds a new netfilter selftest that creates two IPVS TCP services on the same VIP, one with IP_VS_SVC_F_SECURE_TCP, and checks the resulting connection states with ipvsadm -Lnc. Two helpers are added: a libmnl program to set/query the per-service flag and a raw-socket probe that sends a bare SYN followed by a bare ACK.

Quoted 3 lines

Two services share a VIP, one carrying IP_VS_SVC_F_SECURE_TCP. A bare SYN+ACK suffices to test the state machine: the normal service reaches ESTABLISHED, but the secure one stays in SYN_RECV.

[Severity: Low]
Does the changelog wording match what gen_tcp_probe.c actually sends?

main() transmits two separate bare segments, a SYN and then a pure ACK:

	if (send_seg(fd, &sip, sport, &dip, dport, seq, 1, 0) < 0) {
	...
	usleep(100000);
	if (send_seg(fd, &sip, sport, &dip, dport, seq + 1, 0, 1) < 0) {

A single segment with both bits set would not show anything, since tcp_state_idx() in net/netfilter/ipvs/ip_vs_proto_tcp.c tests rst, then syn, then fin, then ack:

	if (th->rst)
		return 3;
	if (th->syn)
		return 0;
	if (th->fin)
		return 1;
	if (th->ack)
		return 2;

so SYN|ACK is classified as syn, and the INPUT syn row of both tcp_states and tcp_states_dos maps sNO -> sSR, i.e. no difference between the secure and the plain service.

Would "a bare SYN followed by a bare ACK" (the wording already used in the gen_tcp_probe.c header comment) be more accurate here?

Quoted 6 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +0 -0
new file mode 100755
index 000000000000..4d250bcbb2cf
@@ -0,0 +1,153 @@

[ ... ]

Quoted 3 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +3 -0
+source lib.sh
+
+ret=0

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +4 -0
+checktool "ipvsadm -v" "run test without ipvsadm"
+
+setup() {
+	setup_ns ns0 ns1 ns2

[ ... ]

tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh line 72

Quoted 4 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +4 -0
+	# load ipvs, then the rr scheduler (separate calls: modprobe treats
+	# the second name as a module parameter, not a second module)
+	ip netns exec "${ns1}" modprobe ip_vs
+	ip netns exec "${ns1}" modprobe ip_vs_rr

[Severity: Medium]
What happens on a kernel built without CONFIG_IP_VS or without the rr scheduler?

The only pre-flight gate is checktool "ipvsadm -v", which validates the userspace binary only. Both modprobe calls in setup() have their exit status discarded (no set -e, no ||), so a missing ip_vs goes unnoticed:
ipvs_secure_tcp_mln add fails, the connection table stays empty, both assert_state() calls set ret=1, and the script exits 1.

$ksft_skip is never used anywhere in this script even though lib.sh is sourced. The pre-existing ipvs.sh in the same directory guards this:

if [ ! -d $sysipvsnet ]; then
if ! modprobe -q ip_vs; then
echo "skip: could not run test without ipvs module" exit $ksft_skip
fi
fi

Could the same skip be added here, so unsupported configurations are reported as skipped rather than failed?

Note that the helper's get readback cannot be used for feature detection
either: ip_vs_genl_parse_service() stores the requested bits without rejecting unknown ones,

		usvc->flags = (usvc->flags & ~flags.mask) |
			      (flags.flags & flags.mask);

so a kernel lacking per-service secure_tcp still echoes secure_tcp=1.

Quoted 3 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +3 -0
+
+	sleep 1
+}

[ ... ]

Quoted 11 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +11 -0
+assert_state() {
+	local port=$1 want=$2
+	local got
+	got="$(conn_state "$port")"
+	echo "  vip ${vip}:${port}: state=${got:-?}"
+	if [ "${got:-}" != "$want" ]; then
+		echo -e "${RED}FAIL${NC}: vip ${vip}:${port} expected state" \
+			"${want}, got ${got:-none}"
+		ret=1
+	fi
+}

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +4 -0
+	# Push SYN then ACK to each service from the client
+	ip netns exec "${ns0}" "$probe" "${cip}" 40000 "${vip}" "${port_secure}"
+	ip netns exec "${ns0}" "$probe" "${cip}" 40001 "${vip}" "${port_plain}"
+	sleep 1

[ ... ]

tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh line 141

Quoted 3 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +3 -0
+	assert_state "${port_plain}" ESTABLISHED
+	assert_state "${port_secure}" SYN_RECV
+}

[Severity: Medium]
Can assert_state "${port_secure}" SYN_RECV pass without the ACK ever being processed?

SYN_RECV is exactly the state the first SYN alone produces. In net/netfilter/ipvs/ip_vs_proto_tcp.c the INPUT syn row is sNO -> sSR in both tables, and only the following input ACK differs:

/*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSR }}, /* tcp_states */ /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSA }}, /* tcp_states_dos */

The probe exit status is discarded here:

	ip netns exec "${ns0}" "$probe" "${cip}" 40000 "${vip}" "${port_secure}"

There is no || and no set -e, while gen_tcp_probe.c main() returns 1 when the second send_seg() fails:

	usleep(100000);
	if (send_seg(fd, &sip, sport, &dip, dport, seq + 1, 0, 1) < 0) {
		close(fd);
		return 1;
	}

So a probe run that dies after the SYN (sendto failure, or the helper being killed during the usleep) leaves the connection in SYN_RECV and the secure-side assertion still succeeds. The plain-service assertion is only a partial control, since it is a separate invocation with a different source port.

Would checking the probe exit status, or asserting something that only the processed ACK can produce, make this assertion distinguish the two cases?

Quoted 12 lines
tools/testing/selftests/net/netfilter/ipvs_secure_tcp.sh new file +12 -0
+
+trap cleanup EXIT
+
+setup
+test_secure
+
+if [ "$ret" -ne 0 ]; then
+	echo -e "$(basename $0): ${RED}FAIL${NC}"
+	exit 1
+fi
+echo -e "$(basename $0): ${GREEN}PASS${NC}"
+exit 0

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260920054708.988867-1-adrianox%40gmail.com