From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Ido Schimmel <idosch@nvidia.com>, Wang Hai <wanghai38@huawei.com>,
"David S . Miller" <davem@davemloft.net>,
Sasha Levin <sashal@kernel.org>,
kuba@kernel.org, pabeni@redhat.com, yoshfuji@linux-ipv6.org,
dsahern@kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 48/98] ipv4: Invalidate neighbour for broadcast address upon address addition
Date: Fri, 1 Apr 2022 10:36:52 -0400 [thread overview]
Message-ID: <20220401143742.1952163-48-sashal@kernel.org> (raw)
In-Reply-To: <20220401143742.1952163-1-sashal@kernel.org>
From: Ido Schimmel <idosch@nvidia.com>
[ Upstream commit 0c51e12e218f20b7d976158fdc18019627326f7a ]
In case user space sends a packet destined to a broadcast address when a
matching broadcast route is not configured, the kernel will create a
unicast neighbour entry that will never be resolved [1].
When the broadcast route is configured, the unicast neighbour entry will
not be invalidated and continue to linger, resulting in packets being
dropped.
Solve this by invalidating unresolved neighbour entries for broadcast
addresses after routes for these addresses are internally configured by
the kernel. This allows the kernel to create a broadcast neighbour entry
following the next route lookup.
Another possible solution that is more generic but also more complex is
to have the ARP code register a listener to the FIB notification chain
and invalidate matching neighbour entries upon the addition of broadcast
routes.
It is also possible to wave off the issue as a user space problem, but
it seems a bit excessive to expect user space to be that intimately
familiar with the inner workings of the FIB/neighbour kernel code.
[1] https://lore.kernel.org/netdev/55a04a8f-56f3-f73c-2aea-2195923f09d1@huawei.com/
Reported-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/net/arp.h | 1 +
net/ipv4/arp.c | 9 +++++++--
net/ipv4/fib_frontend.c | 5 ++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/net/arp.h b/include/net/arp.h
index 4950191f6b2b..4a23a97195f3 100644
--- a/include/net/arp.h
+++ b/include/net/arp.h
@@ -71,6 +71,7 @@ void arp_send(int type, int ptype, __be32 dest_ip,
const unsigned char *src_hw, const unsigned char *th);
int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
void arp_ifdown(struct net_device *dev);
+int arp_invalidate(struct net_device *dev, __be32 ip, bool force);
struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
struct net_device *dev, __be32 src_ip,
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 922dd73e5740..83a47998c4b1 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1116,13 +1116,18 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
return err;
}
-static int arp_invalidate(struct net_device *dev, __be32 ip)
+int arp_invalidate(struct net_device *dev, __be32 ip, bool force)
{
struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
int err = -ENXIO;
struct neigh_table *tbl = &arp_tbl;
if (neigh) {
+ if ((neigh->nud_state & NUD_VALID) && !force) {
+ neigh_release(neigh);
+ return 0;
+ }
+
if (neigh->nud_state & ~NUD_NOARP)
err = neigh_update(neigh, NULL, NUD_FAILED,
NEIGH_UPDATE_F_OVERRIDE|
@@ -1169,7 +1174,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
if (!dev)
return -EINVAL;
}
- return arp_invalidate(dev, ip);
+ return arp_invalidate(dev, ip, true);
}
/*
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 4d61ddd8a0ec..1eb7795edb9d 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1112,9 +1112,11 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
return;
/* Add broadcast address, if it is explicitly assigned. */
- if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
+ if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF)) {
fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32,
prim, 0);
+ arp_invalidate(dev, ifa->ifa_broadcast, false);
+ }
if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
(prefix != addr || ifa->ifa_prefixlen < 32)) {
@@ -1128,6 +1130,7 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
if (ifa->ifa_prefixlen < 31) {
fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask,
32, prim, 0);
+ arp_invalidate(dev, prefix | ~mask, false);
}
}
}
--
2.34.1
next prev parent reply other threads:[~2022-04-01 14:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220401143742.1952163-1-sashal@kernel.org>
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 02/98] ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 10/98] ptp: replace snprintf with sysfs_emit Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 13/98] ath11k: fix kernel panic during unload/load ath11k modules Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 14/98] ath11k: pci: fix crash on suspend if board file is not found Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 15/98] ath11k: mhi: use mhi_sync_power_up() Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 16/98] net/smc: Send directly when TCP_CORK is cleared Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 18/98] bpf: Make dst_port field in struct bpf_sock 16-bit wide Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 23/98] mt76: mt7921: fix crash when startup fails Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 24/98] mt76: dma: initialize skip_unmap in mt76_dma_rx_fill Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 25/98] cfg80211: don't add non transmitted BSS to 6GHz scanned channels Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 26/98] libbpf: Fix build issue with llvm-readelf Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 27/98] ipv6: make mc_forwarding atomic Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 28/98] net: initialize init_net earlier Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 36/98] tcp: Don't acquire inet_listen_hashbucket::lock with disabled BH Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 42/98] net/mlx5e: Disable TX queues before registering the netdev Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 44/98] iwlwifi: mvm: Correctly set fragmented EBS Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 45/98] iwlwifi: mvm: Passively scan non PSC channels only when requested so Sasha Levin
2022-04-01 14:36 ` [PATCH AUTOSEL 5.15 46/98] iwlwifi: mvm: move only to an enabled channel Sasha Levin
2022-04-01 14:36 ` Sasha Levin [this message]
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 58/98] mt76: mt7915: fix injected MPDU transmission to not use HW A-MSDU Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 61/98] mt76: mt7615: Fix assigning negative values to unsigned variable Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 65/98] net/smc: correct settings of RMB window update limit Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 67/98] macvtap: advertise link netns via netlink Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 68/98] tuntap: add sanity checks about msg_controllen in sendmsg Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 70/98] Bluetooth: Fix not checking for valid hdev on bt_dev_{info,warn,err,dbg} Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 71/98] Bluetooth: use memset avoid memory leaks Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 72/98] bnxt_en: Eliminate unintended link toggle during FW reset Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 76/98] powerpc/64e: Tie PPC_BOOK3E_64 to PPC_FSL_BOOK3E Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 79/98] can: isotp: set default value for N_As to 50 micro seconds Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 80/98] can: etas_es58x: es58x_fd_rx_event_msg(): initialize rx_event_msg before calling es58x_check_msg_len() Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 82/98] net: account alternate interface name memory Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 83/98] net: limit altnames to 64k total Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 84/98] net/mlx5e: Remove overzealous validations in netlink EEPROM query Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 86/98] net: sfp: add 2500base-X quirk for Lantech SFP module Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 88/98] mt76: fix monitor mode crash with sdio driver Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 91/98] Bluetooth: Fix use after free in hci_send_acl Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 92/98] netfilter: conntrack: revisit gc autotuning Sasha Levin
2022-04-01 14:37 ` [PATCH AUTOSEL 5.15 93/98] netlabel: fix out-of-bounds memory accesses Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220401143742.1952163-48-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=wanghai38@huawei.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).