]> git.baikalelectronics.ru Git - kernel.git/commit
ipv4: ping: fix bind address validity check
authorRiccardo Paolo Bestetti <pbl@bestov.io>
Fri, 17 Jun 2022 08:54:35 +0000 (10:54 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 Jun 2022 10:41:34 +0000 (11:41 +0100)
commit9e0535b38d7fe256f0d35bcd08f7605b7cd023ee
tree52dcd1febe816f60868811d29e412509f8a60a8c
parent313c1b67894610343ce3153a861a23be80a7ed34
ipv4: ping: fix bind address validity check

Commit 0b32c5f3f0c7 ("ipv4/raw: support binding to nonlocal addresses")
introduced a helper function to fold duplicated validity checks of bind
addresses into inet_addr_valid_or_nonlocal(). However, this caused an
unintended regression in ping_check_bind_addr(), which previously would
reject binding to multicast and broadcast addresses, but now these are
both incorrectly allowed as reported in [1].

This patch restores the original check. A simple reordering is done to
improve readability and make it evident that multicast and broadcast
addresses should not be allowed. Also, add an early exit for INADDR_ANY
which replaces lost behavior added by commit 7d8c260a4573 ("net: Avoid
unnecessary inet_addr_type() call when addr is INADDR_ANY").

Furthermore, this patch introduces regression selftests to catch these
specific cases.

[1] https://lore.kernel.org/netdev/CANP3RGdkAcDyAZoT1h8Gtuu0saq+eOrrTiWbxnOs+5zn+cpyKg@mail.gmail.com/

Fixes: 0b32c5f3f0c7 ("ipv4/raw: support binding to nonlocal addresses")
Cc: Miaohe Lin <linmiaohe@huawei.com>
Reported-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Signed-off-by: Riccardo Paolo Bestetti <pbl@bestov.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ping.c
tools/testing/selftests/net/fcnal-test.sh