Skip to contentSkip to conversation

vxlan: Make vxlan_fdb_find_uc() more robust against NPDs

PATCH Applied Ido Schimmel 4 participants 4 messages Sep 8, 2025 – Sep 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vxlan: Make vxlan_fdb_find_uc() more robust against NPDs

first_remote_rcu() can return NULL if the FDB entry points to an FDB nexthop group instead of a remote destination. However, unlike other users of first_remote_rcu(), NPD cannot currently happen in vxlan_fdb_find_uc() as it is only invoked by one driver which vetoes the creation of FDB nexthops.

Make the function more robust by making sure the remote destination is only dereferenced if it is not NULL.

---
 drivers/net/vxlan/vxlan_core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -3
index dab864bc733c..a5c55e7e4d79 100644
@@ -446,7 +446,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
 {
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	u8 eth_addr[ETH_ALEN + 2] = { 0 };
-	struct vxlan_rdst *rdst;
+	struct vxlan_rdst *rdst = NULL;
 	struct vxlan_fdb *f;
 	int rc = 0;
 
@@ -459,12 +459,13 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
 	rcu_read_lock();
 
 	f = vxlan_find_mac_rcu(vxlan, eth_addr, vni);
-	if (!f) {
+	if (f)
+		rdst = first_remote_rcu(f);
+	if (!rdst) {
 		rc = -ENOENT;
 		goto out;
 	}
 
-	rdst = first_remote_rcu(f);
 	vxlan_fdb_switchdev_notifier_info(vxlan, f, rdst, NULL, fdb_info);
 
 out:
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Ido Schimmel

first_remote_rcu() can return NULL if the FDB entry points to an FDB nexthop group instead of a remote destination. However, unlike other users of first_remote_rcu(), NPD cannot currently happen in vxlan_fdb_find_uc() as it is only invoked by one driver which vetoes the creation of FDB nexthops.

Make the function more robust by making sure the remote destination is only dereferenced if it is not NULL.

---
  drivers/net/vxlan/vxlan_core.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -2
index dab864bc733c..a5c55e7e4d79 100644
@@ -446,7 +446,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  {
  	struct vxlan_dev *vxlan = netdev_priv(dev);
  	u8 eth_addr[ETH_ALEN + 2] = { 0 };
-	struct vxlan_rdst *rdst;
+	struct vxlan_rdst *rdst = NULL;
  	struct vxlan_fdb *f;
  	int rc = 0;
 
@@ -459,12 +459,13 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  	rcu_read_lock();
 
  	f = vxlan_find_mac_rcu(vxlan, eth_addr, vni);
-	if (!f) {
+	if (f)

drivers/net/vxlan/vxlan_core.c int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, · line 471

Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +2 -1
+		rdst = first_remote_rcu(f);
+	if (!rdst) {
  		rc = -ENOENT;
  		goto out;
  	}
 
-	rdst = first_remote_rcu(f);
  	vxlan_fdb_switchdev_notifier_info(vxlan, f, rdst, NULL, fdb_info);
 
  out:
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ido Schimmel
Quoted 34 lines · Ido Schimmel

first_remote_rcu() can return NULL if the FDB entry points to an FDB nexthop group instead of a remote destination. However, unlike other users of first_remote_rcu(), NPD cannot currently happen in vxlan_fdb_find_uc() as it is only invoked by one driver which vetoes the creation of FDB nexthops.

Make the function more robust by making sure the remote destination is only dereferenced if it is not NULL.

---
  drivers/net/vxlan/vxlan_core.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -2
index dab864bc733c..a5c55e7e4d79 100644
@@ -446,7 +446,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  {
  	struct vxlan_dev *vxlan = netdev_priv(dev);
  	u8 eth_addr[ETH_ALEN + 2] = { 0 };
-	struct vxlan_rdst *rdst;
+	struct vxlan_rdst *rdst = NULL;
  	struct vxlan_fdb *f;
  	int rc = 0;
 
@@ -459,12 +459,13 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  	rcu_read_lock();
 
  	f = vxlan_find_mac_rcu(vxlan, eth_addr, vni);
-	if (!f) {
+	if (f)

drivers/net/vxlan/vxlan_core.c int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, · line 471

Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +2 -1
+		rdst = first_remote_rcu(f);
+	if (!rdst) {
  		rc = -ENOENT;
  		goto out;
  	}
 
-	rdst = first_remote_rcu(f);
  	vxlan_fdb_switchdev_notifier_info(vxlan, f, rdst, NULL, fdb_info);
 
  out:
#3 lore raw
In reply to Ido Schimmel
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 8 Sep 2025 10:51:41 +0300 you wrote:

first_remote_rcu() can return NULL if the FDB entry points to an FDB nexthop group instead of a remote destination. However, unlike other users of first_remote_rcu(), NPD cannot currently happen in vxlan_fdb_find_uc() as it is only invoked by one driver which vetoes the creation of FDB nexthops.

Make the function more robust by making sure the remote destination is only dereferenced if it is not NULL.

[...]

Here is the summary with links:
- [net-next] vxlan: Make vxlan_fdb_find_uc() more robust against NPDs

    https://git.kernel.org/netdev/net-next/c/ce6adea19ad9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html