Skip to contentSkip to conversation

ibmvnic: fix ibmvnic_set_mac

PATCH Applied Lijun Pan 2 participants 2 messages Oct 27, 2020 – Oct 29, 2020

Subsystems (4)
lore
Share & tools
lore

Lijun Pan

author
#0 lore raw

PATCH v3 1/1 ibmvnic: fix ibmvnic_set_mac

Jakub Kicinski brought up a concern in ibmvnic_set_mac(). ibmvnic_set_mac() does this:

	ether_addr_copy(adapter->mac_addr, addr->sa_data);
	if (adapter->state != VNIC_PROBED)
		rc = __ibmvnic_set_mac(netdev, addr->sa_data);

So if state == VNIC_PROBED, the user can assign an invalid address to adapter->mac_addr, and ibmvnic_set_mac() will still return 0.

The fix is to validate ethernet address at the beginning of ibmvnic_set_mac(), and move the ether_addr_copy to the case of "adapter->state != VNIC_PROBED".

Fixes 62740e97881c ("net/ibmvnic: Update MAC address settings after adapter reset")
Cc Jakub Kicinski <[email protected]>

---
v2: change the subject from v1's

    "ibmvnic: no need to update adapter->mac_addr before it completes"
    handle adapter->state==VNIC_PROBED case in else statement.

v3: take Maciej Fijalkowski's advice.

 drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +6 -2
index 4dd3625a4fbc..660761538c55 100644
@@ -1828,9 +1828,13 @@ static int ibmvnic_set_mac(struct net_device *netdev, void *p)
 	int rc;
 
 	rc = 0;
-	ether_addr_copy(adapter->mac_addr, addr->sa_data);
-	if (adapter->state != VNIC_PROBED)
+	if (!is_valid_ether_addr(addr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	if (adapter->state != VNIC_PROBED) {
+		ether_addr_copy(adapter->mac_addr, addr->sa_data);
 		rc = __ibmvnic_set_mac(netdev, addr->sa_data);
+	}
 
 	return rc;
 }
Signature · 1 line
2.23.0
maintainer Applied
#1 lore raw
Quoted 10 lines · On Tue, 27 Oct 2020 17:04:56 -0500 Lijun Pan wrote:

Jakub Kicinski brought up a concern in ibmvnic_set_mac(). ibmvnic_set_mac() does this:

	ether_addr_copy(adapter->mac_addr, addr->sa_data);
	if (adapter->state != VNIC_PROBED)
		rc = __ibmvnic_set_mac(netdev, addr->sa_data);

So if state == VNIC_PROBED, the user can assign an invalid address to adapter->mac_addr, and ibmvnic_set_mac() will still return 0.

Quoted 7 lines

The fix is to validate ethernet address at the beginning of ibmvnic_set_mac(), and move the ether_addr_copy to the case of "adapter->state != VNIC_PROBED".

Fixes 62740e97881c ("net/ibmvnic: Update MAC address settings after adapter reset")
Cc Jakub Kicinski <[email protected]>

Applied, thanks.