Skip to contentSkip to conversation

sctp conntrack fixes

PATCH Superseded Sriram Yagnaraman 2 participants 9 messages Jan 16, 2023 – Jan 17, 2023

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover sctp conntrack fixes

A less diruptive change as opposed to below RFC patch:
https://lore.kernel.org/netfilter-devel/[email protected]/

This contains a couple of bug fixes to existing bugs that were found during the review of the above patch series, and also a patch that unifies the ESTABLISHED states for primary and secondary paths.

Sriram Yagnaraman (3):
netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
netfilter: conntrack: fix bug in for_each_sctp_chunk
netfilter: conntrack: unify established states for SCTP paths

 .../uapi/linux/netfilter/nf_conntrack_sctp.h  |   4 +-
 .../linux/netfilter/nfnetlink_cttimeout.h     |   4 +-
 net/netfilter/nf_conntrack_proto_sctp.c       | 119 +++++++++---------
 net/netfilter/nf_conntrack_standalone.c       |  16 ---
 4 files changed, 60 insertions(+), 83 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE

RFC 9260, Sec 8.5.1 states that for ABORT/SHUTDOWN_COMPLETE, the chunk MUST be accepted if the vtag of the packet matches its own tag and the T bit is not set OR if it is set to its peer's vtag and the T bit is set in chunk flags. Otherwise the packet MUST be silently dropped.

Update vtag verification for ABORT/SHUTDOWN_COMPLETE based on the above description.

---
 net/netfilter/nf_conntrack_proto_sctp.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +16 -9
index d88b92a8ffca..2b2c549ba678 100644
@@ -424,22 +424,29 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
 	for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
 		/* Special cases of Verification tag check (Sec 8.5.1) */
 		if (sch->type == SCTP_CID_INIT) {
-			/* Sec 8.5.1 (A) */
+			/* (A) vtag MUST be zero */
 			if (sh->vtag != 0)
 				goto out_unlock;
 		} else if (sch->type == SCTP_CID_ABORT) {
-			/* Sec 8.5.1 (B) */
-			if (sh->vtag != ct->proto.sctp.vtag[dir] &&
-			    sh->vtag != ct->proto.sctp.vtag[!dir])
+			/* (B) vtag MUST match own vtag if T flag is unset OR
+			 * MUST match peer's vtag if T flag is set
+			 */
+			if ((!(sch->flags & SCTP_CHUNK_FLAG_T) &&
+			     sh->vtag != ct->proto.sctp.vtag[dir]) ||
+			    ((sch->flags & SCTP_CHUNK_FLAG_T) &&
+			     sh->vtag != ct->proto.sctp.vtag[!dir]))
 				goto out_unlock;
 		} else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
-			/* Sec 8.5.1 (C) */
-			if (sh->vtag != ct->proto.sctp.vtag[dir] &&
-			    sh->vtag != ct->proto.sctp.vtag[!dir] &&
-			    sch->flags & SCTP_CHUNK_FLAG_T)
+			/* (C) vtag MUST match own vtag if T flag is unset OR
+			 * MUST match peer's vtag if T flag is set
+			 */
+			if ((!(sch->flags & SCTP_CHUNK_FLAG_T) &&
+			     sh->vtag != ct->proto.sctp.vtag[dir]) ||
+			    ((sch->flags & SCTP_CHUNK_FLAG_T) &&
+			     sh->vtag != ct->proto.sctp.vtag[!dir]))
 				goto out_unlock;
 		} else if (sch->type == SCTP_CID_COOKIE_ECHO) {
-			/* Sec 8.5.1 (D) */
+			/* (D) vtag must be same as init_vtag as found in INIT_ACK */
 			if (sh->vtag != ct->proto.sctp.vtag[dir])
 				goto out_unlock;
 		} else if (sch->type == SCTP_CID_HEARTBEAT) {
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE

Quoted 7 lines · Sriram Yagnaraman

RFC 9260, Sec 8.5.1 states that for ABORT/SHUTDOWN_COMPLETE, the chunk MUST be accepted if the vtag of the packet matches its own tag and the T bit is not set OR if it is set to its peer's vtag and the T bit is set in chunk flags. Otherwise the packet MUST be silently dropped.

Update vtag verification for ABORT/SHUTDOWN_COMPLETE based on the above description.

I suspect this is broken since the beginning? Then a good Fixes: tag candidate it...

Fixes 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.")

?

#3 lore raw

PATCH 2/3 netfilter: conntrack: fix bug in for_each_sctp_chunk

In reply to Sriram Yagnaraman

skb_header_pointer() will return NULL if offset + sizeof(_sch) exceeds skb->len, so this offset < skb->len test is redundant.

if sch->length == 0, this will end up in an infinite loop, add a check for sch->length > 0

---
 net/netfilter/nf_conntrack_proto_sctp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +2 -2
index 2b2c549ba678..c561c1213704 100644
@@ -160,8 +160,8 @@ static void sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
 
 #define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count)	\
 for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0;	\
-	(offset) < (skb)->len &&					\
-	((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch)));	\
+	((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))) &&	\
+	(sch)->length;	\
 	(offset) += (ntohs((sch)->length) + 3) & ~3, (count)++)
 
 /* Some validity checks to make sure the chunks are fine */
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/3] netfilter: conntrack: fix bug in for_each_sctp_chunk

Quoted 5 lines · Sriram Yagnaraman

skb_header_pointer() will return NULL if offset + sizeof(_sch) exceeds skb->len, so this offset < skb->len test is redundant.

if sch->length == 0, this will end up in an infinite loop, add a check for sch->length > 0

If this is broken since the beginning, then:

Fixes 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.")

is sufficiently old for -stable kernels to pick up this.

Let me know if this looks good to you, thanks

#5 lore raw

PATCH 3/3 netfilter: conntrack: unify established states for SCTP paths

In reply to Sriram Yagnaraman

An SCTP endpoint can start an association through a path and tear it down over another one. That means the initial path will not see the shutdown sequence, and the conntrack entry will remain in ESTABLISHED state for 5 days.

By merging the HEARTBEAT_ACKED and ESTABLISHED states into one ESTABLISHED state, there remains no difference between a primary or secondary path. The timeout for the merged ESTABLISHED state is set to 210 seconds (hb_interval * max_path_retrans + rto_max). So, even if a path doesn't see the shutdown sequence, it will expire in a reasonable amount of time.

---
 .../uapi/linux/netfilter/nf_conntrack_sctp.h  |  4 +-
 .../linux/netfilter/nfnetlink_cttimeout.h     |  4 +-
 net/netfilter/nf_conntrack_proto_sctp.c       | 90 ++++++++-----------
 net/netfilter/nf_conntrack_standalone.c       | 16 ----
 4 files changed, 42 insertions(+), 72 deletions(-)
include/uapi/linux/netfilter/nf_conntrack_sctp.h +2 -2
index c742469afe21..150fc3c056ea 100644
@@ -15,8 +15,8 @@ enum sctp_conntrack {
 	SCTP_CONNTRACK_SHUTDOWN_RECD,
 	SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
 	SCTP_CONNTRACK_HEARTBEAT_SENT,
-	SCTP_CONNTRACK_HEARTBEAT_ACKED,
-	SCTP_CONNTRACK_DATA_SENT,
+	SCTP_CONNTRACK_HEARTBEAT_ACKED,	/* no longer used */
+	SCTP_CONNTRACK_DATA_SENT,	/* no longer used */
 	SCTP_CONNTRACK_MAX
 };
 
include/uapi/linux/netfilter/nfnetlink_cttimeout.h +2 -2
index 94e74034706d..282343d433a6 100644
@@ -94,8 +94,8 @@ enum ctattr_timeout_sctp {
 	CTA_TIMEOUT_SCTP_SHUTDOWN_RECD,
 	CTA_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT,
 	CTA_TIMEOUT_SCTP_HEARTBEAT_SENT,
-	CTA_TIMEOUT_SCTP_HEARTBEAT_ACKED,
-	CTA_TIMEOUT_SCTP_DATA_SENT,
+	CTA_TIMEOUT_SCTP_HEARTBEAT_ACKED,	/* no longer used */
+	CTA_TIMEOUT_SCTP_DATA_SENT,		/* no longer used */
 	__CTA_TIMEOUT_SCTP_MAX
 };
 #define CTA_TIMEOUT_SCTP_MAX (__CTA_TIMEOUT_SCTP_MAX - 1)
net/netfilter/nf_conntrack_proto_sctp.c +38 -52

134 lines not on this page · raw message

net/netfilter/nf_conntrack_standalone.c +0 -16
index 0250725e38a4..460294bd4b60 100644
@@ -601,8 +601,6 @@ enum nf_ct_sysctl_index {
 	NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_RECD,
 	NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT,
 	NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_SENT,
-	NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_ACKED,
-	NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_DATA_SENT,
 #endif
 #ifdef CONFIG_NF_CT_PROTO_DCCP
 	NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST,
@@ -887,18 +885,6 @@ static struct ctl_table nf_ct_sysctl_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec_jiffies,
 	},
-	[NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_ACKED] = {
-		.procname       = "nf_conntrack_sctp_timeout_heartbeat_acked",
-		.maxlen         = sizeof(unsigned int),
-		.mode           = 0644,
-		.proc_handler   = proc_dointvec_jiffies,
-	},
-	[NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_DATA_SENT] = {
-		.procname       = "nf_conntrack_sctp_timeout_data_sent",
-		.maxlen         = sizeof(unsigned int),
-		.mode           = 0644,
-		.proc_handler   = proc_dointvec_jiffies,
-	},
 #endif
 #ifdef CONFIG_NF_CT_PROTO_DCCP
 	[NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST] = {
@@ -1042,8 +1028,6 @@ static void nf_conntrack_standalone_init_sctp_sysctl(struct net *net,
 	XASSIGN(SHUTDOWN_RECD, sn);
 	XASSIGN(SHUTDOWN_ACK_SENT, sn);
 	XASSIGN(HEARTBEAT_SENT, sn);
-	XASSIGN(HEARTBEAT_ACKED, sn);
-	XASSIGN(DATA_SENT, sn);
 #undef XASSIGN
 #endif
 }
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 3/3] netfilter: conntrack: unify established states for SCTP paths

Quoted 25 lines · Sriram Yagnaraman

An SCTP endpoint can start an association through a path and tear it down over another one. That means the initial path will not see the shutdown sequence, and the conntrack entry will remain in ESTABLISHED state for 5 days.

By merging the HEARTBEAT_ACKED and ESTABLISHED states into one ESTABLISHED state, there remains no difference between a primary or secondary path. The timeout for the merged ESTABLISHED state is set to 210 seconds (hb_interval * max_path_retrans + rto_max). So, even if a path doesn't see the shutdown sequence, it will expire in a reasonable amount of time.

---
 .../uapi/linux/netfilter/nf_conntrack_sctp.h  |  4 +-
 .../linux/netfilter/nfnetlink_cttimeout.h     |  4 +-
 net/netfilter/nf_conntrack_proto_sctp.c       | 90 ++++++++-----------
 net/netfilter/nf_conntrack_standalone.c       | 16 ----
 4 files changed, 42 insertions(+), 72 deletions(-)
include/uapi/linux/netfilter/nf_conntrack_sctp.h +0 -0
index c742469afe21..150fc3c056ea 100644

include/uapi/linux/netfilter/nf_conntrack_sctp.h enum sctp_conntrack { · line 19

Quoted 7 lines
include/uapi/linux/netfilter/nf_conntrack_sctp.h +2 -2
@@ -15,8 +15,8 @@ enum sctp_conntrack {
 	SCTP_CONNTRACK_SHUTDOWN_RECD,
 	SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
 	SCTP_CONNTRACK_HEARTBEAT_SENT,
-	SCTP_CONNTRACK_HEARTBEAT_ACKED,
-	SCTP_CONNTRACK_DATA_SENT,
+	SCTP_CONNTRACK_HEARTBEAT_ACKED,	/* no longer used */
+	SCTP_CONNTRACK_DATA_SENT,	/* no longer used */

_DATA_SENT was added in the previous development cycle, to my knowledged it has been present in 6.1-rc only. Then I think you can post a patch to revert this explaining why there is no need for _DATA_SENT anymore. You can revert it before this patch (with my suggestion, your series will contain with 4 patches).

One question of mine: Did you extract the new established timeout from RFC, where this formula came from?

210 seconds = hb_interval * max_path_retrans + rto_max

And thanks, if this works for you, I prefer this incremental approach by improving the existing SCTP tracker.

#7 lore raw

Re: [PATCH 3/3] netfilter: conntrack: unify established states for SCTP paths

Quoted 21 lines · Pablo Neira Ayuso
Quoted 20 lines · Sriram Yagnaraman

An SCTP endpoint can start an association through a path and tear it down over another one. That means the initial path will not see the shutdown sequence, and the conntrack entry will remain in ESTABLISHED state for 5 days.

By merging the HEARTBEAT_ACKED and ESTABLISHED states into one ESTABLISHED state, there remains no difference between a primary or secondary path. The timeout for the merged ESTABLISHED state is set to 210 seconds (hb_interval * max_path_retrans + rto_max). So, even if a path doesn't see the shutdown sequence, it will expire in a reasonable amount of time.

---
 .../uapi/linux/netfilter/nf_conntrack_sctp.h  |  4 +-
 .../linux/netfilter/nfnetlink_cttimeout.h     |  4 +-
 net/netfilter/nf_conntrack_proto_sctp.c       | 90 ++++++++-----------
 net/netfilter/nf_conntrack_standalone.c       | 16 ----
 4 files changed, 42 insertions(+), 72 deletions(-)
Quoted 15 lines

include/uapi/linux/netfilter/nf_conntrack_sctp.h enum sctp_conntrack { · line 19

Quoted 12 lines
include/uapi/linux/netfilter/nf_conntrack_sctp.h +2 -2
index c742469afe21..150fc3c056ea 100644
@@ -15,8 +15,8 @@ enum sctp_conntrack {
 	SCTP_CONNTRACK_SHUTDOWN_RECD,
 	SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
 	SCTP_CONNTRACK_HEARTBEAT_SENT,
-	SCTP_CONNTRACK_HEARTBEAT_ACKED,
-	SCTP_CONNTRACK_DATA_SENT,
+	SCTP_CONNTRACK_HEARTBEAT_ACKED,	/* no longer used */
+	SCTP_CONNTRACK_DATA_SENT,	/* no longer used */

_DATA_SENT was added in the previous development cycle, to my knowledged it has been present in 6.1-rc only. Then I think you can

Actually, I mean 6.2-rc releases.

Quoted 11 lines

post a patch to revert this explaining why there is no need for _DATA_SENT anymore. You can revert it before this patch (with my suggestion, your series will contain with 4 patches).

One question of mine: Did you extract the new established timeout from RFC, where this formula came from?

210 seconds = hb_interval * max_path_retrans + rto_max

And thanks, if this works for you, I prefer this incremental approach by improving the existing SCTP tracker.

#8 lore raw

RE: [PATCH 3/3] netfilter: conntrack: unify established states for SCTP paths

Quoted 50 lines

-----Original Message-----
From: Pablo Neira Ayuso <[email protected]>
Sent: Tuesday, 17 January 2023 13:02
To: Sriram Yagnaraman <[email protected]>
Cc: [email protected]; Florian Westphal <[email protected]>; Marcelo Ricardo Leitner <[email protected]>; Long Xin <[email protected]>; Claudio Porfiri <[email protected]>
Subject: Re: [PATCH 3/3] netfilter: conntrack: unify established states for SCTP paths

Quoted 22 lines · Pablo Neira Ayuso
Quoted 21 lines · Sriram Yagnaraman

An SCTP endpoint can start an association through a path and tear it down over another one. That means the initial path will not see the shutdown sequence, and the conntrack entry will remain in ESTABLISHED state for 5 days.

By merging the HEARTBEAT_ACKED and ESTABLISHED states into one ESTABLISHED state, there remains no difference between a primary or secondary path. The timeout for the merged ESTABLISHED state is set to
210 seconds (hb_interval * max_path_retrans + rto_max). So, even if a path doesn't see the shutdown sequence, it will expire in a reasonable amount of time.

---
 .../uapi/linux/netfilter/nf_conntrack_sctp.h  |  4 +-
 .../linux/netfilter/nfnetlink_cttimeout.h     |  4 +-
 net/netfilter/nf_conntrack_proto_sctp.c       | 90 ++++++++-----------
 net/netfilter/nf_conntrack_standalone.c       | 16 ----
 4 files changed, 42 insertions(+), 72 deletions(-)
Quoted 16 lines

include/uapi/linux/netfilter/nf_conntrack_sctp.h enum sctp_conntrack { · line 19

Quoted 13 lines
include/uapi/linux/netfilter/nf_conntrack_sctp.h +2 -2
index c742469afe21..150fc3c056ea 100644
@@ -15,8 +15,8 @@ enum sctp_conntrack {
 	SCTP_CONNTRACK_SHUTDOWN_RECD,
 	SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
 	SCTP_CONNTRACK_HEARTBEAT_SENT,
-	SCTP_CONNTRACK_HEARTBEAT_ACKED,
-	SCTP_CONNTRACK_DATA_SENT,
+	SCTP_CONNTRACK_HEARTBEAT_ACKED,	/* no longer used */
+	SCTP_CONNTRACK_DATA_SENT,	/* no longer used */

_DATA_SENT was added in the previous development cycle, to my knowledged it has been present in 6.1-rc only. Then I think you can

Quoted 5 lines

Actually, I mean 6.2-rc releases.

Quoted 3 lines

post a patch to revert this explaining why there is no need for _DATA_SENT anymore. You can revert it before this patch (with my suggestion, your series will contain with 4 patches).

I only removed the DATA_SENT state, SCTP tracker still reacts to DATA/SACK chunks to move to HEARTBEAT_SENT state. But I realize that reacting to DATA/SACK works only for new connections, while on connection re-use we still depend on HEARTBEAT for the secondary paths. Perhaps, I should revert the whole patch as you suggest.

Quoted 5 lines
Quoted 5 lines

One question of mine: Did you extract the new established timeout from RFC, where this formula came from?

210 seconds = hb_interval * max_path_retrans + rto_max

Took it from the HEARTBEAT_ACKED state timeout, explained in the patch that introduced the state: https://lore.kernel.org/all/[email protected]/
An SCTP endpoint will retry a path every "hb_interval" seconds for "max_path_retrans" times with a timeout of "rto_max", before treating it as unreachable. So, I am guessing that is the science behind the formula.

Quoted 3 lines
Quoted 3 lines

And thanks, if this works for you, I prefer this incremental approach by improving the existing SCTP tracker.

Thanks for taking the time to review. I will come back with more improvements once this series is approved :)