Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

octeon_ep: Validate the VF ID

Add a helper to validate the VF ID and use it in the VF ndo ops to
prevent accessing out-of-range entries.

Without this check, users can run commands such as:

# ip link show dev enp135s0
2: enp135s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:00:00:01:01:00 brd ff:ff:ff:ff:ff:ff
vf 0 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 1 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
# ip link set dev enp135s0 vf 4 mac 00:00:00:00:00:14
# echo $?
0

even though VF 4 does not exist, which results in silent success instead
of returning an error.

Fixes: 8a241ef9b9b8 ("octeon_ep: add ndo ops for VFs in PF driver")
Signed-off-by: Kamal Heib <kheib@redhat.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250911223610.1803144-1-kheib@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kamal Heib and committed by
Jakub Kicinski
af82e857 2429a197

+16
+16
drivers/net/ethernet/marvell/octeon_ep/octep_main.c
··· 1124 1124 return err; 1125 1125 } 1126 1126 1127 + static bool octep_is_vf_valid(struct octep_device *oct, int vf) 1128 + { 1129 + if (vf >= CFG_GET_ACTIVE_VFS(oct->conf)) { 1130 + netdev_err(oct->netdev, "Invalid VF ID %d\n", vf); 1131 + return false; 1132 + } 1133 + 1134 + return true; 1135 + } 1136 + 1127 1137 static int octep_get_vf_config(struct net_device *dev, int vf, 1128 1138 struct ifla_vf_info *ivi) 1129 1139 { 1130 1140 struct octep_device *oct = netdev_priv(dev); 1141 + 1142 + if (!octep_is_vf_valid(oct, vf)) 1143 + return -EINVAL; 1131 1144 1132 1145 ivi->vf = vf; 1133 1146 ether_addr_copy(ivi->mac, oct->vf_info[vf].mac_addr); ··· 1155 1142 { 1156 1143 struct octep_device *oct = netdev_priv(dev); 1157 1144 int err; 1145 + 1146 + if (!octep_is_vf_valid(oct, vf)) 1147 + return -EINVAL; 1158 1148 1159 1149 if (!is_valid_ether_addr(mac)) { 1160 1150 dev_err(&oct->pdev->dev, "Invalid MAC Address %pM\n", mac);