Skip to content

Commit 4c61d80

Browse files
kmaincentkuba-moo
authored andcommitted
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: b9e3f7d ("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]>
1 parent 3f8f2e9 commit 4c61d80

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/ethtool/common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ int __ethtool_get_ts_info(struct net_device *dev,
870870
{
871871
struct hwtstamp_provider *hwprov;
872872

873-
hwprov = rtnl_dereference(dev->hwprov);
873+
rcu_read_lock();
874+
hwprov = rcu_dereference(dev->hwprov);
874875
/* No provider specified, use default behavior */
875876
if (!hwprov) {
876877
const struct ethtool_ops *ops = dev->ethtool_ops;
@@ -887,9 +888,11 @@ int __ethtool_get_ts_info(struct net_device *dev,
887888
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
888889
SOF_TIMESTAMPING_SOFTWARE;
889890

891+
rcu_read_unlock();
890892
return err;
891893
}
892894

895+
rcu_read_unlock();
893896
return ethtool_get_ts_info_by_phc(dev, info, &hwprov->desc);
894897
}
895898

0 commit comments

Comments
 (0)