[RFC,5/5] net/tcp-md5: Don't send ACK if key (dis)appears

Message ID 20230509221608.2569333-6-dima@arista.com
State New
Headers
Series net/tcp-md5: Verify segments on TIME_WAIT sockets |

Commit Message

Dmitry Safonov May 9, 2023, 10:16 p.m. UTC
  To mirror RST paranoid checks and tcp_inbound_md5_hash().

Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 net/ipv4/tcp_ipv4.c | 2 ++
 net/ipv6/tcp_ipv6.c | 2 ++
 2 files changed, 4 insertions(+)
  

Patch

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index d94cd5e70d58..0c8893240f70 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -918,6 +918,8 @@  static void tcp_v4_send_ack(const struct sock *sk,
 	rep.th.window  = htons(win);
 
 #ifdef CONFIG_TCP_MD5SIG
+	if (unlikely(!!key != !!tcp_parse_md5sig_option(th)))
+		return;
 	if (key) {
 		int offset = (tsecr) ? 3 : 0;
 
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 498dfa194b8b..4131ada9fabf 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -863,6 +863,8 @@  static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
 	if (tsecr)
 		tot_len += TCPOLEN_TSTAMP_ALIGNED;
 #ifdef CONFIG_TCP_MD5SIG
+	if (!rst && unlikely(!!key != !!tcp_parse_md5sig_option(th)))
+		return;
 	if (key)
 		tot_len += TCPOLEN_MD5SIG_ALIGNED;
 #endif