Skip to content

Commit 1619726

Browse files
keesPaolo Abeni
authored andcommitted
net: core: Switch netif_set_mac_address() to struct sockaddr_storage
In order to avoid passing around struct sockaddr that has a size the compiler cannot reason about (nor track at runtime), convert netif_set_mac_address() to take struct sockaddr_storage. This is just a cast conversion, so there is are no binary changes. Following patches will make actual allocation changes. Acked-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent ed449dd commit 1619726

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4212,7 +4212,7 @@ int netif_set_mtu(struct net_device *dev, int new_mtu);
42124212
int dev_set_mtu(struct net_device *, int);
42134213
int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
42144214
struct netlink_ext_ack *extack);
4215-
int netif_set_mac_address(struct net_device *dev, struct sockaddr *sa,
4215+
int netif_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
42164216
struct netlink_ext_ack *extack);
42174217
int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
42184218
struct netlink_ext_ack *extack);

net/core/dev.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9669,23 +9669,23 @@ int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
96699669
}
96709670
EXPORT_SYMBOL(dev_pre_changeaddr_notify);
96719671

9672-
int netif_set_mac_address(struct net_device *dev, struct sockaddr *sa,
9672+
int netif_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
96739673
struct netlink_ext_ack *extack)
96749674
{
96759675
const struct net_device_ops *ops = dev->netdev_ops;
96769676
int err;
96779677

96789678
if (!ops->ndo_set_mac_address)
96799679
return -EOPNOTSUPP;
9680-
if (sa->sa_family != dev->type)
9680+
if (ss->ss_family != dev->type)
96819681
return -EINVAL;
96829682
if (!netif_device_present(dev))
96839683
return -ENODEV;
9684-
err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);
9684+
err = dev_pre_changeaddr_notify(dev, ss->__data, extack);
96859685
if (err)
96869686
return err;
9687-
if (memcmp(dev->dev_addr, sa->sa_data, dev->addr_len)) {
9688-
err = ops->ndo_set_mac_address(dev, sa);
9687+
if (memcmp(dev->dev_addr, ss->__data, dev->addr_len)) {
9688+
err = ops->ndo_set_mac_address(dev, ss);
96899689
if (err)
96909690
return err;
96919691
}

net/core/dev_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int dev_set_mac_address_user(struct net_device *dev, struct sockaddr *sa,
9191

9292
down_write(&dev_addr_sem);
9393
netdev_lock_ops(dev);
94-
ret = netif_set_mac_address(dev, sa, extack);
94+
ret = netif_set_mac_address(dev, (struct sockaddr_storage *)sa, extack);
9595
netdev_unlock_ops(dev);
9696
up_write(&dev_addr_sem);
9797

@@ -332,7 +332,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
332332
int ret;
333333

334334
netdev_lock_ops(dev);
335-
ret = netif_set_mac_address(dev, sa, extack);
335+
ret = netif_set_mac_address(dev, (struct sockaddr_storage *)sa, extack);
336336
netdev_unlock_ops(dev);
337337

338338
return ret;

net/core/rtnetlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3100,7 +3100,7 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev,
31003100

31013101
memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
31023102
dev->addr_len);
3103-
err = netif_set_mac_address(dev, sa, extack);
3103+
err = netif_set_mac_address(dev, (struct sockaddr_storage *)sa, extack);
31043104
kfree(sa);
31053105
if (err) {
31063106
up_write(&dev_addr_sem);

0 commit comments

Comments
 (0)