From: Kory Maincent Date: Fri, 20 Dec 2024 08:37:40 +0000 (+0100) Subject: net: ethtool: Fix suspicious rcu_dereference usage X-Git-Tag: v6.14-rc1~162^2~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c61d809cf608842112c77880f50810a564cd9cb;p=thirdparty%2Flinux.git 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: syzbot+a344326c05c98ba19682@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/676147f8.050a0220.37aaf.0154.GAE@google.com/ Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology") Signed-off-by: Kory Maincent Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241220083741.175329-1-kory.maincent@bootlin.com Signed-off-by: Jakub Kicinski --- diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 02f941f667dd5..2607aea1fbfb2 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -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); }