Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Perform SCTP vtag verification for ABORT/SHUTDOWN_COMPLETE according to RFC 9260, Sect 8.5.1.
2) Fix infinite loop if SCTP chunk size is zero in for_each_sctp_chunk(). And remove useless check in this macro too.
3) Revert DATA_SENT state in the SCTP tracker, this was applied in the previous merge window. Next patch in this series provides a more simple approach to multihoming support.
4) Unify HEARTBEAT_ACKED and ESTABLISHED states for SCTP multihoming support, use default ESTABLISHED of 210 seconds based on heartbeat timeout * maximum number of retransmission + round-trip timeout. Otherwise, SCTP conntrack entry that represents secondary paths remain stale in the table for up to 5 days.
This is a slightly large batch with fixes for the SCTP connection tracking helper, all patches from Sriram Yagnaraman.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit 208a21107ef0ae86c92078caf84ce80053e73f7a:
Merge branch '40GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue (2023-01-23 22:36:59 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git HEAD
for you to fetch changes up to a44b7651489f26271ac784b70895e8a85d0cebf4:
netfilter: conntrack: unify established states for SCTP paths (2023-01-24 09:52:52 +0100)
----------------------------------------------------------------
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
Documentation/networking/nf_conntrack-sysctl.rst | 10 +- include/uapi/linux/netfilter/nf_conntrack_sctp.h | 3 +- include/uapi/linux/netfilter/nfnetlink_cttimeout.h | 3 +- net/netfilter/nf_conntrack_proto_sctp.c | 170 +++++++++------------ net/netfilter/nf_conntrack_standalone.c | 16 -- 5 files changed, 77 insertions(+), 125 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/4 netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
From: Sriram Yagnaraman <[email protected]>
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.30.2
Re: [PATCH net 1/4] netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:
Quoted 8 lines · On Tue, 24 Jan 2023 19:39:30 +0100 you wrote:
From: Sriram Yagnaraman <[email protected]>
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.
[...]
Here is the summary with links:
- [net,1/4] netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
https://git.kernel.org/netdev/net/c/a9993591fa94 - [net,2/4] netfilter: conntrack: fix bug in for_each_sctp_chunk https://git.kernel.org/netdev/net/c/98ee00774525 - [net,3/4] Revert "netfilter: conntrack: add sctp DATA_SENT state" https://git.kernel.org/netdev/net/c/13bd9b31a969 - [net,4/4] netfilter: conntrack: unify established states for SCTP paths https://git.kernel.org/netdev/net/c/a44b7651489f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/4 netfilter: conntrack: fix bug in for_each_sctp_chunk
In reply to Pablo Neira AyusoFrom: Sriram Yagnaraman <[email protected]>
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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 3/4 Revert "netfilter: conntrack: add sctp DATA_SENT state"
In reply to Pablo Neira AyusoFrom: Sriram Yagnaraman <[email protected]>
This 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.30.2
Pablo Neira Ayuso
maintainerPATCH 4/4 netfilter: conntrack: unify established states for SCTP paths
In reply to Pablo Neira AyusoFrom: Sriram Yagnaraman <[email protected]>
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.
With this change in place, there is now more than one state from which we can transition to ESTABLISHED, COOKIE_ECHOED and HEARTBEAT_SENT, so handle the setting of ASSURED bit whenever a state change has happened and the new state is ESTABLISHED. Removed the check for dir==REPLY since the transition to ESTABLISHED can happen only in the reply direction.
--- .../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 | 93 ++++++++----------- net/netfilter/nf_conntrack_standalone.c | 8 -- 5 files changed, 44 insertions(+), 71 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 +39 -54
144 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.30.2
Re: [PATCH net 0/4] Netfilter fixes for net: manual merge
In reply to Pablo Neira AyusoHello,
Quoted 3 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
(...)
Quoted 5 lines
Sriram Yagnaraman (4):
netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
netfilter: conntrack: fix bug infor_each_sctp_chunkRevert "netfilter: conntrack: add sctpDATA_SENTstate"
netfilter: conntrack: unify established states for SCTP paths
FYI, we got a small conflict when merging -net in net-next in the MPTCP tree due to the last two patches applied in -net:
13bd9b31a969 ("Revert "netfilter: conntrack: add sctp DATA_SENT state"") a44b7651489f ("netfilter: conntrack: unify established states for SCTP
paths")
and this one from net-next:
f71cb8f45d09 ("netfilter: conntrack: sctp: use nf log infrastructure
for invalid packets")
The conflict has been resolved on our side[1] and the resolution we suggest is attached to this email.
Cheers,
Matt
[1] https://github.com/multipath-tcp/mptcp_net-next/commit/4e2bc066dae4
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
net/netfilter/nf_conntrack_proto_sctp.c +0 -0
@@@ -243,16 -238,14 +227,12 @@@ static int sctp_new_state(enum ip_connt i =9 ;break ;case SCTP_CID_HEARTBEAT_ACK : -pr_debug ("SCTP_CID_HEARTBEAT_ACK" ); i =10 ;break ; -case SCTP_CID_DATA : -case SCTP_CID_SACK : - i =11 ; -break ;default :/* Other chunks like DATA or SACK do not change the state */ -pr_debug ("Unknown chunk type, Will stay in %s\n" , - sctp_conntrack_names[cur_state]); +pr_debug ("Unknown chunk type %d, Will stay in %s\n" , + chunk_type, sctp_conntrack_names[cur_state]);return cur_state; }if (!sctp_new (ct, skb, sh, dataoff))return -NF_ACCEPT ; - }else { -/* Check the verification tag (Sec 8.5) */ -if (!test_bit (SCTP_CID_INIT , map) && - !test_bit (SCTP_CID_SHUTDOWN_COMPLETE , map) && - !test_bit (SCTP_CID_COOKIE_ECHO , map) && - !test_bit (SCTP_CID_ABORT , map) && - !test_bit (SCTP_CID_SHUTDOWN_ACK , map) && - !test_bit (SCTP_CID_HEARTBEAT , map) && - !test_bit (SCTP_CID_HEARTBEAT_ACK , map) && - sh->vtag != ct->proto.sctp.vtag[dir]) { -nf_ct_l4proto_log_invalid (skb, ct, state, -"verification tag check failed %x vs %x for dir %d" , - sh->vtag, ct->proto.sctp.vtag[dir], dir); - goto out; - } + } + +/* Check the verification tag (Sec 8.5) */ +if (!test_bit (SCTP_CID_INIT , map) && + !test_bit (SCTP_CID_SHUTDOWN_COMPLETE , map) && + !test_bit (SCTP_CID_COOKIE_ECHO , map) && + !test_bit (SCTP_CID_ABORT , map) && + !test_bit (SCTP_CID_SHUTDOWN_ACK , map) && + !test_bit (SCTP_CID_HEARTBEAT , map) && + !test_bit (SCTP_CID_HEARTBEAT_ACK , map) && + sh->vtag != ct->proto.sctp.vtag[dir]) { -pr_debug ("Verification tag check failed\n" ); ++nf_ct_l4proto_log_invalid (skb, ct, state, ++"verification tag check failed %x vs %x for dir %d" , ++ sh->vtag, ct->proto.sctp.vtag[dir], dir); + goto out; } old_state = new_state =SCTP_CONNTRACK_NONE ;
RE: [PATCH net 0/4] Netfilter fixes for net: manual merge
Quoted 28 lines
-----Original Message-----
From: Matthieu Baerts <[email protected]>
Sent: Wednesday, 25 January 2023 10:14
To: Pablo Neira Ayuso <[email protected]>; [email protected]; Sriram Yagnaraman <[email protected]>; Florian Westphal <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 0/4] Netfilter fixes for net: manual mergeHello,
Quoted 3 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
(...)
Quoted 5 lines
Sriram Yagnaraman (4):
netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE
netfilter: conntrack: fix bug infor_each_sctp_chunkRevert "netfilter: conntrack: add sctpDATA_SENTstate"
netfilter: conntrack: unify established states for SCTP pathsFYI, we got a small conflict when merging -net in net-next in the MPTCP tree due to the last two patches applied in -net:
Quoted 8 lines
13bd9b31a969("Revert "netfilter: conntrack: add sctpDATA_SENTstate"")a44b7651489f("netfilter: conntrack: unify established states for SCTP
paths")and this one from net-next:
f71cb8f45d09("netfilter: conntrack: sctp: use nf log infrastructure for invalid
packets")
Ah, that's my bad. I should have pushed to nf-next/net-next instead.
Maintainers: I am not fully aware of what needs to be done in this case, please advise.
Quoted 3 lines
The conflict has been resolved on our side[1] and the resolution we suggest is attached to this email.
The attached patch looks fine to me.
Quoted 7 lines
Cheers,
Matt[1] https://github.com/multipath-tcp/mptcp_net-next/commit/4e2bc066dae4
--
Tessares | Belgium | Hybrid Access Solutions www.tessares.net