Skip to contentSkip to conversation

net/octep_ep: Validate the VF ID

PATCH In review Kamal Heib 2 participants 2 messages Sep 8, 2025 – Sep 9, 2025

Subsystems (3)
lore
Share & tools
lore

Kamal Heib

author
#0 lore raw

PATCH 1/1 net/octep_ep: Validate the VF ID

Make sure that the VF ID is valid before trying to access the VF.

Fixes 8a241ef9b9b8 ("octeon_ep: add ndo ops for VFs in PF driver")
---
 .../net/ethernet/marvell/octeon_ep/octep_main.c  | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +16 -0
index 24499bb36c00..eaafbc0a55b1 100644
@@ -1124,11 +1124,24 @@ static int octep_set_features(struct net_device *dev, netdev_features_t features
 	return err;
 }
 
+static bool octep_validate_vf(struct octep_device *oct, int vf)
+{
+	if (vf >= CFG_GET_ACTIVE_VFS(oct->conf)) {
+		dev_err(&oct->pdev->dev, "Invalid VF ID %d\n", vf);
+		return false;
+	}
+
+	return true;
+}
+
 static int octep_get_vf_config(struct net_device *dev, int vf,
 			       struct ifla_vf_info *ivi)
 {
 	struct octep_device *oct = netdev_priv(dev);
 
+	if (!octep_validate_vf(oct, vf))
+		return -EINVAL;
+
 	ivi->vf = vf;
 	ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
 	ivi->spoofchk = true;
@@ -1143,6 +1156,9 @@ static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
 	struct octep_device *oct = netdev_priv(dev);
 	int err;
 
+	if (!octep_validate_vf(oct, vf))
+		return -EINVAL;
+
 	if (!is_valid_ether_addr(mac)) {
 		dev_err(&oct->pdev->dev, "Invalid  MAC Address %pM\n", mac);
 		return -EADDRNOTAVAIL;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Kamal Heib

Make sure that the VF ID is valid before trying to access the VF.

Fixes 8a241ef9b9b8 ("octeon_ep: add ndo ops for VFs in PF driver")
---
 .../net/ethernet/marvell/octeon_ep/octep_main.c  | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index 24499bb36c00..eaafbc0a55b1 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_features(struct net_device *dev, netdev_features_t features · line 1127

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
@@ -1124,11 +1124,24 @@ static int octep_set_features(struct net_device *dev, netdev_features_t features
 	return err;
 }
 
+static bool octep_validate_vf(struct octep_device *oct, int vf)

nit, looks like octep_is_vf_valid() fits better here.

Quoted 21 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +12 -0
+{
+	if (vf >= CFG_GET_ACTIVE_VFS(oct->conf)) {
+		dev_err(&oct->pdev->dev, "Invalid VF ID %d\n", vf);
+		return false;
+	}
+
+	return true;
+}
+
 static int octep_get_vf_config(struct net_device *dev, int vf,
 			       struct ifla_vf_info *ivi)
 {
 	struct octep_device *oct = netdev_priv(dev);
 
+	if (!octep_validate_vf(oct, vf))
+		return -EINVAL;
+
 	ivi->vf = vf;
 	ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr);
 	ivi->spoofchk = true;

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac) · line 1164

Quoted 9 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -0
@@ -1143,6 +1156,9 @@ static int octep_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
 	struct octep_device *oct = netdev_priv(dev);
 	int err;
 
+	if (!octep_validate_vf(oct, vf))
+		return -EINVAL;
+
 	if (!is_valid_ether_addr(mac)) {
 		dev_err(&oct->pdev->dev, "Invalid  MAC Address %pM\n", mac);
 		return -EADDRNOTAVAIL;

Make sense, you can add reproduction steps and what happens when the ID is incorrect, but it is up to you.

Quoted 2 lines
Signature · 1 line
2.51.0