net: ethtool: Fix suspicious rcu_dereference usage

The __ethtool_get_ts_info function can be called with or without the
rtnl lock held. When the rtnl lock is not held, using rtnl_dereference()
triggers a warning due to the lack of lock context.

Add an rcu_read_lock() to ensure the lock is acquired and to maintain
synchronization.

Reported-by: [email protected]
Closes: https://lore.kernel.org/netdev/[email protected]/
Fixes: b9e3f7dc9e ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Signed-off-by: Kory Maincent <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
This commit is contained in:
Kory Maincent
2024-12-23 10:38:46 -08:00
committed by Jakub Kicinski
parent 3f8f2e93cd
commit 4c61d809cf
+4 -1
View File
@@ -870,7 +870,8 @@ int __ethtool_get_ts_info(struct net_device *dev,
{
struct hwtstamp_provider *hwprov;
hwprov = rtnl_dereference(dev->hwprov);
rcu_read_lock();
hwprov = rcu_dereference(dev->hwprov);
/* No provider specified, use default behavior */
if (!hwprov) {
const struct ethtool_ops *ops = dev->ethtool_ops;
@@ -887,9 +888,11 @@ int __ethtool_get_ts_info(struct net_device *dev,
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
rcu_read_unlock();
return err;
}
rcu_read_unlock();
return ethtool_get_ts_info_by_phc(dev, info, &hwprov->desc);
}