Skip to content

Commit 0a8e987

Browse files
q2vendavem330
authored andcommitted
tcp: Fix SYN option room calculation for TCP-AO.
When building SYN packet in tcp_syn_options(), MSS, TS, WS, and SACKPERM are used without checking the remaining bytes in the options area. To keep that logic as is, we limit the TCP-AO MAC length in tcp_ao_parse_crypto(). Currently, the limit is calculated as below. MAX_TCP_OPTION_SPACE - TCPOLEN_TSTAMP_ALIGNED - TCPOLEN_WSCALE_ALIGNED - TCPOLEN_SACKPERM_ALIGNED This looks confusing as (1) we pack SACKPERM into the leading 2-bytes of the aligned 12-bytes of TS and (2) TCPOLEN_MSS_ALIGNED is not used. Fortunately, the calculated limit is not wrong as TCPOLEN_SACKPERM_ALIGNED and TCPOLEN_MSS_ALIGNED are the same value. However, we should use the proper constant in the formula. MAX_TCP_OPTION_SPACE - TCPOLEN_MSS_ALIGNED - TCPOLEN_TSTAMP_ALIGNED - TCPOLEN_WSCALE_ALIGNED Fixes: 4954f17 ("net/tcp: Introduce TCP_AO setsockopt()s") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Dmitry Safonov <dima@arista.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3423ca2 commit 0a8e987

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/ipv4/tcp_ao.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,8 @@ static int tcp_ao_parse_crypto(struct tcp_ao_add *cmd, struct tcp_ao_key *key)
13151315
key->maclen = cmd->maclen ?: 12; /* 12 is the default in RFC5925 */
13161316

13171317
/* Check: maclen + tcp-ao header <= (MAX_TCP_OPTION_SPACE - mss
1318-
* - tstamp - wscale - sackperm),
1318+
* - tstamp (including sackperm)
1319+
* - wscale),
13191320
* see tcp_syn_options(), tcp_synack_options(), commit 33ad798c924b.
13201321
*
13211322
* In order to allow D-SACK with TCP-AO, the header size should be:
@@ -1342,9 +1343,9 @@ static int tcp_ao_parse_crypto(struct tcp_ao_add *cmd, struct tcp_ao_key *key)
13421343
* large to leave sufficient option space.
13431344
*/
13441345
syn_tcp_option_space = MAX_TCP_OPTION_SPACE;
1346+
syn_tcp_option_space -= TCPOLEN_MSS_ALIGNED;
13451347
syn_tcp_option_space -= TCPOLEN_TSTAMP_ALIGNED;
13461348
syn_tcp_option_space -= TCPOLEN_WSCALE_ALIGNED;
1347-
syn_tcp_option_space -= TCPOLEN_SACKPERM_ALIGNED;
13481349
if (tcp_ao_len(key) > syn_tcp_option_space) {
13491350
err = -EMSGSIZE;
13501351
goto err_kfree;

0 commit comments

Comments
 (0)