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.

tcp: Remove unnecessary null check in tcp_inbound_md5_hash()

The 'if (!key && hash_location)' check in tcp_inbound_md5_hash() implies
that hash_location might be null. However, later code in the function
dereferences hash_location anyway, without checking for null first.
Fortunately, there is no real bug, since tcp_inbound_md5_hash() is
called only with non-null values of hash_location.

Therefore, remove the unnecessary and misleading null check of
hash_location. This silences a Smatch static checker warning
(https://lore.kernel.org/netdev/aPi4b6aWBbBR52P1@stanley.mountain/)

Also fix the related comment at the beginning of the function.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20251022221209.19716-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Biggers and committed by
Jakub Kicinski
05774d7e 9ff86092

+4 -6
+4 -6
net/ipv4/tcp.c
··· 4886 4886 int family, int l3index, const __u8 *hash_location) 4887 4887 { 4888 4888 /* This gets called for each TCP segment that has TCP-MD5 option. 4889 - * We have 3 drop cases: 4890 - * o No MD5 hash and one expected. 4891 - * o MD5 hash and we're not expecting one. 4892 - * o MD5 hash and its wrong. 4889 + * We have 2 drop cases: 4890 + * o An MD5 signature is present, but we're not expecting one. 4891 + * o The MD5 signature is wrong. 4893 4892 */ 4894 4893 const struct tcp_sock *tp = tcp_sk(sk); 4895 4894 struct tcp_md5sig_key *key; 4896 4895 u8 newhash[16]; 4897 4896 4898 4897 key = tcp_md5_do_lookup(sk, l3index, saddr, family); 4899 - 4900 - if (!key && hash_location) { 4898 + if (!key) { 4901 4899 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); 4902 4900 trace_tcp_hash_md5_unexpected(sk, skb); 4903 4901 return SKB_DROP_REASON_TCP_MD5UNEXPECTED;