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

From: Dmitry Safonov
Date: Tue May 09 2023 - 18:16:42 EST


To mirror RST paranoid checks and tcp_inbound_md5_hash().

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

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
--
2.40.0