sctp conntrack fixes
Subsystems (3)
v3 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.
Changes since v2:
- Remove UAPI changes for DATA_SENT since it is only part of 6.1-rc
Changes since v1:
- Reverted bff3d0534804: DATA_SENT state
- Set assured bit if new state is ESTABLISHED and direction is reply, regardless of the old state. Paths established by HEARTBEAT also gets the assured bit.
- Update nf_conntrack_sysctl documentation
Sriram Yagnaraman (4):
netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
netfilter: conntrack: fix bug in for_each_sctp_chunk Revert "netfilter: conntrack: add sctp DATA_SENT state"
netfilter: conntrack: unify established states for SCTP paths
.../networking/nf_conntrack-sysctl.rst | 10 +- .../uapi/linux/netfilter/nf_conntrack_sctp.h | 3 +- .../linux/netfilter/nfnetlink_cttimeout.h | 3 +- net/netfilter/nf_conntrack_proto_sctp.c | 159 ++++++++---------- net/netfilter/nf_conntrack_standalone.c | 16 -- 5 files changed, 73 insertions(+), 118 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 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
@@ -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
PATCH v3 2/4 netfilter: conntrack: fix bug in for_each_sctp_chunk
In reply to Sriram Yagnaramanskb_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
@@ -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
PATCH v3 3/4 Revert "netfilter: conntrack: add sctp DATA_SENT state"
In reply to Sriram YagnaramanThis reverts commit (bff3d0534804: "netfilter: conntrack: add sctp DATA_SENT state")
Using DATA/SACK to detect a new connection on secondary/alternate paths works only on new connections, while a HEARTBEAT is required on connection re-use. It is probably consistent to wait for HEARTBEAT to create a secondary connection in conntrack.
--- .../uapi/linux/netfilter/nf_conntrack_sctp.h | 1 - .../linux/netfilter/nfnetlink_cttimeout.h | 1 - net/netfilter/nf_conntrack_proto_sctp.c | 102 ++++++++---------- net/netfilter/nf_conntrack_standalone.c | 8 -- 4 files changed, 42 insertions(+), 70 deletions(-)
include/uapi/linux/netfilter/nf_conntrack_sctp.h +0 -1
@@ -16,7 +16,6 @@ enum sctp_conntrack {SCTP_CONNTRACK_SHUTDOWN_ACK_SENT ,SCTP_CONNTRACK_HEARTBEAT_SENT ,SCTP_CONNTRACK_HEARTBEAT_ACKED , -SCTP_CONNTRACK_DATA_SENT , SCTP_CONNTRACK_MAX };
include/uapi/linux/netfilter/nfnetlink_cttimeout.h +0 -1
@@ -95,7 +95,6 @@ enum ctattr_timeout_sctp {CTA_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT ,CTA_TIMEOUT_SCTP_HEARTBEAT_SENT ,CTA_TIMEOUT_SCTP_HEARTBEAT_ACKED , -CTA_TIMEOUT_SCTP_DATA_SENT , __CTA_TIMEOUT_SCTP_MAX };#define CTA_TIMEOUT_SCTP_MAX (__CTA_TIMEOUT_SCTP_MAX - 1)
net/netfilter/nf_conntrack_proto_sctp.c +42 -60
161 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +0 -8
@@ -602,7 +602,6 @@ enum nf_ct_sysctl_index {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,
@@ -893,12 +892,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { .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] = {
@@ -1043,7 +1036,6 @@ static void nf_conntrack_standalone_init_sctp_sysctl(struct net *net,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
PATCH v3 4/4 netfilter: conntrack: unify established states for SCTP paths
In reply to Sriram YagnaramanAn 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.
--- .../networking/nf_conntrack-sysctl.rst | 10 +-- .../uapi/linux/netfilter/nf_conntrack_sctp.h | 2 +- .../linux/netfilter/nfnetlink_cttimeout.h | 2 +- net/netfilter/nf_conntrack_proto_sctp.c | 82 ++++++++----------- net/netfilter/nf_conntrack_standalone.c | 8 -- 5 files changed, 40 insertions(+), 64 deletions(-)
Documentation/networking/nf_conntrack-sysctl.rst +3 -7
@@ -173,7 +173,9 @@ nf_conntrack_sctp_timeout_cookie_echoed - INTEGER (seconds) default 3 nf_conntrack_sctp_timeout_established - INTEGER (seconds) - default 432000 (5 days) + default 210 + + Default is set to (hb_interval * path_max_retrans + rto_max) nf_conntrack_sctp_timeout_shutdown_sent - INTEGER (seconds) default 0.3
@@ -190,12 +192,6 @@ nf_conntrack_sctp_timeout_heartbeat_sent - INTEGER (seconds) This timeout is used to setup conntrack entry on secondary paths. Default is set to hb_interval. -nf_conntrack_sctp_timeout_heartbeat_acked - INTEGER (seconds) - default 210 - - This timeout is used to setup conntrack entry on secondary paths. - Default is set to (hb_interval * path_max_retrans + rto_max) - nf_conntrack_udp_timeout - INTEGER (seconds) default 30
include/uapi/linux/netfilter/nf_conntrack_sctp.h +1 -1
@@ -15,7 +15,7 @@ enum sctp_conntrack {SCTP_CONNTRACK_SHUTDOWN_RECD ,SCTP_CONNTRACK_SHUTDOWN_ACK_SENT ,SCTP_CONNTRACK_HEARTBEAT_SENT , -SCTP_CONNTRACK_HEARTBEAT_ACKED , +SCTP_CONNTRACK_HEARTBEAT_ACKED ,/* no longer used */ SCTP_CONNTRACK_MAX };
include/uapi/linux/netfilter/nfnetlink_cttimeout.h +1 -1
@@ -94,7 +94,7 @@ 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_HEARTBEAT_ACKED ,/* no longer used */ __CTA_TIMEOUT_SCTP_MAX };#define CTA_TIMEOUT_SCTP_MAX (__CTA_TIMEOUT_SCTP_MAX - 1)
net/netfilter/nf_conntrack_proto_sctp.c +35 -47
126 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +0 -8
@@ -601,7 +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 , #endif #ifdef CONFIG_NF_CT_PROTO_DCCP NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST,
@@ -886,12 +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, - },#endif #ifdef CONFIG_NF_CT_PROTO_DCCP [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST] = {
@@ -1035,7 +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);#undef XASSIGN#endif }
Signature · 1 line
2.34.1
Pablo Neira Ayuso
maintainerRe: [PATCH v3 4/4] netfilter: conntrack: unify established states for SCTP paths
Quoted 11 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_ACKEDand 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.
Thanks for new patchset version. One question below.
net/netfilter/nf_conntrack_proto_sctp.c int nf_conntrack_sctp_packet(struct nf_conn *ct, · line 518
Quoted 10 lines
net/netfilter/nf_conntrack_proto_sctp.c +1
-2@@ -523,8 +512,7 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,nf_ct_refresh_acct (ct, ctinfo, skb, timeouts[new_state]); -if (old_state ==SCTP_CONNTRACK_COOKIE_ECHOED && - dir ==IP_CT_DIR_REPLY && +if (dir ==IP_CT_DIR_REPLY && new_state ==SCTP_CONNTRACK_ESTABLISHED ) {pr_debug ("Setting assured bit\n" );set_bit (IPS_ASSURED_BIT , &ct->status);
Why old_state == SCTP_CONNTRACK_COOKIE_ECHOED was removed to set on the assured bit?
Thanks.
RE: [PATCH v3 4/4] netfilter: conntrack: unify established states for SCTP paths
Quoted 29 lines
-----Original Message-----
From: Pablo Neira Ayuso <[email protected]>
Sent: Wednesday, 18 January 2023 16:29
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 v3 4/4] netfilter: conntrack: unify established states for SCTP pathsQuoted 11 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_ACKEDand 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.Thanks for new patchset version. One question below.
Quoted 4 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-0@@ -523,8 +512,7 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,nf_ct_refresh_acct (ct, ctinfo, skb, timeouts[new_state]);
Quoted 10 lines
net/netfilter/nf_conntrack_proto_sctp.c int nf_conntrack_sctp_packet(struct nf_conn *ct, · line 518
Quoted 6 lines
net/netfilter/nf_conntrack_proto_sctp.c +1
-2-if (old_state ==SCTP_CONNTRACK_COOKIE_ECHOED && - dir ==IP_CT_DIR_REPLY && +if (dir ==IP_CT_DIR_REPLY && new_state ==SCTP_CONNTRACK_ESTABLISHED ) {pr_debug ("Setting assured bit\n" );set_bit (IPS_ASSURED_BIT , &ct->status);Why
old_state==SCTP_CONNTRACK_COOKIE_ECHOEDwas removed to set on the assured bit?
There is more than one state from which we can transition to ESTABLISHED now, COOKIE_ECHOED and HEARTBEAT_SENT. I will add a "old_state != new_state" check instead, so we don't set ASSURED every time there is a packet in the REPLY direction. I will wait for other review comments, before pushing another patchset version.
Quoted 1 line
Thanks.
Pablo Neira Ayuso
maintainerRe: [PATCH v3 4/4] netfilter: conntrack: unify established states for SCTP paths
Quoted 40 lines · Sriram Yagnaraman
Quoted 29 lines
-----Original Message-----
From: Pablo Neira Ayuso <[email protected]>
Sent: Wednesday, 18 January 2023 16:29
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 v3 4/4] netfilter: conntrack: unify established states for SCTP pathsQuoted 11 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_ACKEDand 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.Thanks for new patchset version. One question below.
Quoted 4 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-0@@ -523,8 +512,7 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,nf_ct_refresh_acct (ct, ctinfo, skb, timeouts[new_state]);Quoted 10 lines
net/netfilter/nf_conntrack_proto_sctp.c int nf_conntrack_sctp_packet(struct nf_conn *ct, · line 518
Quoted 6 lines
net/netfilter/nf_conntrack_proto_sctp.c +1
-2-if (old_state ==SCTP_CONNTRACK_COOKIE_ECHOED && - dir ==IP_CT_DIR_REPLY && +if (dir ==IP_CT_DIR_REPLY && new_state ==SCTP_CONNTRACK_ESTABLISHED ) {pr_debug ("Setting assured bit\n" );set_bit (IPS_ASSURED_BIT , &ct->status);Why
old_state==SCTP_CONNTRACK_COOKIE_ECHOEDwas removed to set on the assured bit?
Quoted 5 lines
There is more than one state from which we can transition to ESTABLISHED now,
COOKIE_ECHOEDandHEARTBEAT_SENT. I will add a "old_state!=new_state" check instead, so we don't set ASSURED every time there is a packet in the REPLY direction. I will wait for other review comments, before pushing another patchset version.
Thanks for explaining.
Please add this information to the commit description in the next version.