]> git.baikalelectronics.ru Git - kernel.git/commit
net: Fix incorrect address comparison when searching for a bind2 bucket
authorMartin KaFai Lau <martin.lau@kernel.org>
Tue, 27 Sep 2022 00:25:44 +0000 (17:25 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 29 Sep 2022 01:52:17 +0000 (18:52 -0700)
commitf474b957bdbd36b6ee3f3530fc667022d2b0b96a
tree1b07dcfaea11506deecb68b160b48758077aa56e
parentf0b3ce12a1e51732af119eb92e642f650e91baf0
net: Fix incorrect address comparison when searching for a bind2 bucket

The v6_rcv_saddr and rcv_saddr are inside a union in the
'struct inet_bind2_bucket'.  When searching a bucket by following the
bhash2 hashtable chain, eg. inet_bind2_bucket_match, it is only using
the sk->sk_family and there is no way to check if the inet_bind2_bucket
has a v6 or v4 address in the union.  This leads to an uninit-value
KMSAN report in [0] and also potentially incorrect matches.

This patch fixes it by adding a family member to the inet_bind2_bucket
and then tests 'sk->sk_family != tb->family' before matching
the sk's address to the tb's address.

Cc: Joanne Koong <joannelkoong@gmail.com>
Fixes: e230e943f612 ("net: Add a bhash2 table hashed by port and address")
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Tested-by: Alexander Potapenko <glider@google.com>
Link: https://lore.kernel.org/r/20220927002544.3381205-1-kafai@fb.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/inet_hashtables.h
net/ipv4/inet_hashtables.c