Skip to content

Commit b27ed17

Browse files
madaidananthraxx
authored andcommitted
net: tcp: add option to disable TCP simultaneous connect
This is modified from Brad Spengler/PaX Team's code in the last public patch of grsecurity/PaX based on my understanding of the code. Changes or omissions from the original code are mine and don't reflect the original grsecurity/PaX code. TCP simultaneous connect adds a weakness in Linux's implementation of TCP that allows two clients to connect to each other without either entering a listening state. The weakness allows an attacker to easily prevent a client from connecting to a known server provided the source port for the connection is guessed correctly. As the weakness could be used to prevent an antivirus or IPS from fetching updates, or prevent an SSL gateway from fetching a CRL, it should be eliminated. This creates a net.ipv4.tcp_simult_connect sysctl that when disabled, disables TCP simultaneous connect. Reviewd-by: Thibaut Sautereau <[email protected]> Reviewd-by: Levente Polyak <[email protected]> Signed-off-by: Levente Polyak <[email protected]>
1 parent 52ff513 commit b27ed17

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

Documentation/networking/ip-sysctl.rst

+18
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,24 @@ tcp_comp_sack_nr - INTEGER
665665

666666
Default : 44
667667

668+
tcp_simult_connect - BOOLEAN
669+
Enable TCP simultaneous connect that adds a weakness in Linux's strict
670+
implementation of TCP that allows two clients to connect to each other
671+
without either entering a listening state. The weakness allows an attacker
672+
to easily prevent a client from connecting to a known server provided the
673+
source port for the connection is guessed correctly.
674+
675+
As the weakness could be used to prevent an antivirus or IPS from fetching
676+
updates, or prevent an SSL gateway from fetching a CRL, it should be
677+
eliminated by disabling this option. Though Linux is one of few operating
678+
systems supporting simultaneous connect, it has no legitimate use in
679+
practice and is rarely supported by firewalls.
680+
681+
Disabling this may break TCP STUNT which is used by some applications for
682+
NAT traversal.
683+
684+
Default: Value of CONFIG_TCP_SIMULT_CONNECT_DEFAULT_ON
685+
668686
tcp_slow_start_after_idle - BOOLEAN
669687
If set, provide RFC2861 behavior and time out the congestion
670688
window after an idle period. An idle period is defined at

include/net/tcp.h

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
245245
/* sysctl variables for tcp */
246246
extern int sysctl_tcp_max_orphans;
247247
extern long sysctl_tcp_mem[3];
248+
extern int sysctl_tcp_simult_connect;
248249

249250
#define TCP_RACK_LOSS_DETECTION 0x1 /* Use RACK to detect losses */
250251
#define TCP_RACK_STATIC_REO_WND 0x2 /* Use static RACK reo wnd */

net/ipv4/Kconfig

+23
Original file line numberDiff line numberDiff line change
@@ -743,3 +743,26 @@ config TCP_MD5SIG
743743
on the Internet.
744744

745745
If unsure, say N.
746+
747+
config TCP_SIMULT_CONNECT_DEFAULT_ON
748+
bool "Enable TCP simultaneous connect"
749+
help
750+
Enable TCP simultaneous connect that adds a weakness in Linux's strict
751+
implementation of TCP that allows two clients to connect to each other
752+
without either entering a listening state. The weakness allows an
753+
attacker to easily prevent a client from connecting to a known server
754+
provided the source port for the connection is guessed correctly.
755+
756+
As the weakness could be used to prevent an antivirus or IPS from
757+
fetching updates, or prevent an SSL gateway from fetching a CRL, it
758+
should be eliminated by disabling this option. Though Linux is one of
759+
few operating systems supporting simultaneous connect, it has no
760+
legitimate use in practice and is rarely supported by firewalls.
761+
762+
Disabling this may break TCP STUNT which is used by some applications
763+
for NAT traversal.
764+
765+
This setting can be overridden at runtime via the
766+
net.ipv4.tcp_simult_connect sysctl.
767+
768+
If unsure, say N.

net/ipv4/sysctl_net_ipv4.c

+9
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,15 @@ static struct ctl_table ipv4_table[] = {
588588
.mode = 0644,
589589
.proc_handler = proc_do_static_key,
590590
},
591+
{
592+
.procname = "tcp_simult_connect",
593+
.data = &sysctl_tcp_simult_connect,
594+
.maxlen = sizeof(int),
595+
.mode = 0644,
596+
.proc_handler = proc_dointvec_minmax,
597+
.extra1 = SYSCTL_ZERO,
598+
.extra2 = SYSCTL_ONE,
599+
},
591600
{ }
592601
};
593602

net/ipv4/tcp_input.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include <net/mptcp.h>
8383

8484
int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
85+
int sysctl_tcp_simult_connect __read_mostly = IS_ENABLED(CONFIG_TCP_SIMULT_CONNECT_DEFAULT_ON);
8586

8687
#define FLAG_DATA 0x01 /* Incoming frame contained data. */
8788
#define FLAG_WIN_UPDATE 0x02 /* Incoming ACK was a window update. */
@@ -6110,7 +6111,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
61106111
tcp_paws_reject(&tp->rx_opt, 0))
61116112
goto discard_and_undo;
61126113

6113-
if (th->syn) {
6114+
if (th->syn && sysctl_tcp_simult_connect) {
61146115
/* We see SYN without ACK. It is attempt of
61156116
* simultaneous connect with crossed SYNs.
61166117
* Particularly, it can be connect to self.

0 commit comments

Comments
 (0)