Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net/tcp-md5: Fix MAC comparison to be constant-time

To prevent timing attacks, MACs need to be compared in constant
time. Use the appropriate helper function for this.

Fixes: cfb6eeb4c860 ("[TCP]: MD5 Signature Option (RFC2385) support.")
Fixes: 658ddaaf6694 ("tcp: md5: RST: getting md5 key from listener")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20260302203409.13388-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Biggers and committed by
Jakub Kicinski
46d0d6f5 7f5d8e63

+7 -3
+1
net/ipv4/Kconfig
··· 762 762 config TCP_MD5SIG 763 763 bool "TCP: MD5 Signature Option support (RFC2385)" 764 764 select CRYPTO_LIB_MD5 765 + select CRYPTO_LIB_UTILS 765 766 help 766 767 RFC2385 specifies a method of giving MD5 protection to TCP sessions. 767 768 Its main (only?) use is to protect BGP sessions between core routers
+2 -1
net/ipv4/tcp.c
··· 244 244 #define pr_fmt(fmt) "TCP: " fmt 245 245 246 246 #include <crypto/md5.h> 247 + #include <crypto/utils.h> 247 248 #include <linux/kernel.h> 248 249 #include <linux/module.h> 249 250 #include <linux/types.h> ··· 4971 4970 tcp_v4_md5_hash_skb(newhash, key, NULL, skb); 4972 4971 else 4973 4972 tp->af_specific->calc_md5_hash(newhash, key, NULL, skb); 4974 - if (memcmp(hash_location, newhash, 16) != 0) { 4973 + if (crypto_memneq(hash_location, newhash, 16)) { 4975 4974 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); 4976 4975 trace_tcp_hash_md5_mismatch(sk, skb); 4977 4976 return SKB_DROP_REASON_TCP_MD5FAILURE;
+2 -1
net/ipv4/tcp_ipv4.c
··· 88 88 #include <linux/skbuff_ref.h> 89 89 90 90 #include <crypto/md5.h> 91 + #include <crypto/utils.h> 91 92 92 93 #include <trace/events/tcp.h> 93 94 ··· 840 839 goto out; 841 840 842 841 tcp_v4_md5_hash_skb(newhash, key, NULL, skb); 843 - if (memcmp(md5_hash_location, newhash, 16) != 0) 842 + if (crypto_memneq(md5_hash_location, newhash, 16)) 844 843 goto out; 845 844 } 846 845
+2 -1
net/ipv6/tcp_ipv6.c
··· 68 68 #include <linux/seq_file.h> 69 69 70 70 #include <crypto/md5.h> 71 + #include <crypto/utils.h> 71 72 72 73 #include <trace/events/tcp.h> 73 74 ··· 1049 1048 key.type = TCP_KEY_MD5; 1050 1049 1051 1050 tcp_v6_md5_hash_skb(newhash, key.md5_key, NULL, skb); 1052 - if (memcmp(md5_hash_location, newhash, 16) != 0) 1051 + if (crypto_memneq(md5_hash_location, newhash, 16)) 1053 1052 goto out; 1054 1053 } 1055 1054 #endif