Skip to contentSkip to conversation

net: ethtool: Fix suspicious rcu_dereference usage

PATCH Applied Kory Maincent 3 participants 3 messages Dec 20, 2024 – Dec 23, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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]
Fixes b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")

---

I did not manage to reproduce the issue even with the c repro file from syzbot. The c repro run well on my board. Maybe I missed CONFIG being enabled other than PROVE_LOCKING and PROVE_RCU.
I assume this will fix it only by looking at the code.

Changes in v2:
- Add rcu_read_lock()

---
 net/ethtool/common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ethtool/common.c +4 -1
index 02f941f667dd..2607aea1fbfb 100644
@@ -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);
 }
 
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Kory Maincent

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.

Quoted 8 lines

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

Reported-by [email protected]
Fixes b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")

---

#2 lore raw
In reply to Kory Maincent
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 20 Dec 2024 09:37:40 +0100 you wrote:

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.

[...]

Here is the summary with links:
- [net-next,v2] net: ethtool: Fix suspicious rcu_dereference usage

    https://git.kernel.org/netdev/net-next/c/4c61d809cf60

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html