tcp: Fix SYN option room calculation for TCP-AO.
authorKuniyuki Iwashima <kuniyu@amazon.com>
Thu, 2 Nov 2023 21:05:48 +0000 (14:05 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 6 Nov 2023 08:59:54 +0000 (08:59 +0000)
commit0a8e987dcc13244b5a5bc90cb1b184f813104d87
tree013e6e5ce99877c4f5d47011ea1e84c738098ce8
parent3423ca23e08bf285a324237abe88e7e7d9becfe6
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: 4954f17ddefc ("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>
net/ipv4/tcp_ao.c