diff options
author | Eric Dumazet <edumazet@google.com> | 2024-02-13 07:32:38 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2024-02-14 12:20:13 +0100 |
commit | c7d52737e7ebd31cc5fef46380d94b58becf9479 (patch) | |
tree | 4bd56292d5714b0bea521695b95ae8c445c6fd13 /net/core/net-sysfs.c | |
parent | net-sysfs: convert netdev_show() to RCU (diff) | |
download | linux-c7d52737e7ebd31cc5fef46380d94b58becf9479.tar.xz linux-c7d52737e7ebd31cc5fef46380d94b58becf9479.zip |
net-sysfs: use dev_addr_sem to remove races in address_show()
Using dev_base_lock is not preventing from reading garbage.
Use dev_addr_sem instead.
v4: place dev_addr_sem extern in net/core/dev.h (Jakub Kicinski)
Link: https://lore.kernel.org/netdev/20240212175845.10f6680a@kernel.org/
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/net-sysfs.c')
-rw-r--r-- | net/core/net-sysfs.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 678e4be69082..23ef2df549c3 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -142,17 +142,21 @@ static ssize_t name_assign_type_show(struct device *dev, } static DEVICE_ATTR_RO(name_assign_type); -/* use same locking rules as GIFHWADDR ioctl's */ +/* use same locking rules as GIFHWADDR ioctl's (dev_get_mac_address()) */ static ssize_t address_show(struct device *dev, struct device_attribute *attr, char *buf) { struct net_device *ndev = to_net_dev(dev); ssize_t ret = -EINVAL; - read_lock(&dev_base_lock); + down_read(&dev_addr_sem); + + rcu_read_lock(); if (dev_isalive(ndev)) ret = sysfs_format_mac(buf, ndev->dev_addr, ndev->addr_len); - read_unlock(&dev_base_lock); + rcu_read_unlock(); + + up_read(&dev_addr_sem); return ret; } static DEVICE_ATTR_RO(address); |