Skip to content

Commit 646d2ac

Browse files
committed
Merge branch 'tcp-make-simultaneous-connect-rfc-compliant'
Kuniyuki Iwashima says: ==================== tcp: Make simultaneous connect() RFC-compliant. Patch 1 fixes an issue that BPF TCP option parser is triggered for ACK instead of SYN+ACK in the case of simultaneous connect(). Patch 2 removes an wrong assumption in tcp_ao/self-connnect tests. v2: https://lore.kernel.org/netdev/[email protected]/ v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 42ffe24 + b3bb4d2 commit 646d2ac

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

net/ipv4/tcp_input.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,6 +5998,11 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
59985998
* RFC 5961 4.2 : Send a challenge ack
59995999
*/
60006000
if (th->syn) {
6001+
if (sk->sk_state == TCP_SYN_RECV && sk->sk_socket && th->ack &&
6002+
TCP_SKB_CB(skb)->seq + 1 == TCP_SKB_CB(skb)->end_seq &&
6003+
TCP_SKB_CB(skb)->seq + 1 == tp->rcv_nxt &&
6004+
TCP_SKB_CB(skb)->ack_seq == tp->snd_nxt)
6005+
goto pass;
60016006
syn_challenge:
60026007
if (syn_inerr)
60036008
TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS);
@@ -6007,6 +6012,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
60076012
goto discard;
60086013
}
60096014

6015+
pass:
60106016
bpf_skops_parse_hdr(sk, skb);
60116017

60126018
return true;
@@ -6813,6 +6819,9 @@ tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
68136819
tcp_fast_path_on(tp);
68146820
if (sk->sk_shutdown & SEND_SHUTDOWN)
68156821
tcp_shutdown(sk, SEND_SHUTDOWN);
6822+
6823+
if (sk->sk_socket)
6824+
goto consume;
68166825
break;
68176826

68186827
case TCP_FIN_WAIT1: {

tools/testing/selftests/net/tcp_ao/self-connect.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ static void setup_lo_intf(const char *lo_intf)
3030
static void tcp_self_connect(const char *tst, unsigned int port,
3131
bool different_keyids, bool check_restore)
3232
{
33-
uint64_t before_challenge_ack, after_challenge_ack;
34-
uint64_t before_syn_challenge, after_syn_challenge;
3533
struct tcp_ao_counters before_ao, after_ao;
3634
uint64_t before_aogood, after_aogood;
3735
struct netstat *ns_before, *ns_after;
@@ -62,8 +60,6 @@ static void tcp_self_connect(const char *tst, unsigned int port,
6260

6361
ns_before = netstat_read();
6462
before_aogood = netstat_get(ns_before, "TCPAOGood", NULL);
65-
before_challenge_ack = netstat_get(ns_before, "TCPChallengeACK", NULL);
66-
before_syn_challenge = netstat_get(ns_before, "TCPSYNChallenge", NULL);
6763
if (test_get_tcp_ao_counters(sk, &before_ao))
6864
test_error("test_get_tcp_ao_counters()");
6965

@@ -82,8 +78,6 @@ static void tcp_self_connect(const char *tst, unsigned int port,
8278

8379
ns_after = netstat_read();
8480
after_aogood = netstat_get(ns_after, "TCPAOGood", NULL);
85-
after_challenge_ack = netstat_get(ns_after, "TCPChallengeACK", NULL);
86-
after_syn_challenge = netstat_get(ns_after, "TCPSYNChallenge", NULL);
8781
if (test_get_tcp_ao_counters(sk, &after_ao))
8882
test_error("test_get_tcp_ao_counters()");
8983
if (!check_restore) {
@@ -98,18 +92,6 @@ static void tcp_self_connect(const char *tst, unsigned int port,
9892
close(sk);
9993
return;
10094
}
101-
if (after_challenge_ack <= before_challenge_ack ||
102-
after_syn_challenge <= before_syn_challenge) {
103-
/*
104-
* It's also meant to test simultaneous open, so check
105-
* these counters as well.
106-
*/
107-
test_fail("%s: Didn't challenge SYN or ACK: %zu <= %zu OR %zu <= %zu",
108-
tst, after_challenge_ack, before_challenge_ack,
109-
after_syn_challenge, before_syn_challenge);
110-
close(sk);
111-
return;
112-
}
11395

11496
if (test_tcp_ao_counters_cmp(tst, &before_ao, &after_ao, TEST_CNT_GOOD)) {
11597
close(sk);

0 commit comments

Comments
 (0)