public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: ethtool: Fix suspicious rcu_dereference usage
@ 2024-12-20  8:37 Kory Maincent
  2024-12-20 16:33 ` Eric Dumazet
  2024-12-23 18:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Kory Maincent @ 2024-12-20  8:37 UTC (permalink / raw)
  To: David S. Miller, Kory Maincent, netdev, linux-kernel
  Cc: syzbot+a344326c05c98ba19682, thomas.petazzoni, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman

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 <kory.maincent@bootlin.com>
---

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(-)

diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 02f941f667dd..2607aea1fbfb 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);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-23 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-20  8:37 [PATCH net-next v2] net: ethtool: Fix suspicious rcu_dereference usage Kory Maincent
2024-12-20 16:33 ` Eric Dumazet
2024-12-23 18:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox