aboutsummaryrefslogtreecommitdiffstats
path: root/net/hsr
diff options
context:
space:
mode:
authorHangbin Liu <liuhangbin@gmail.com>2025-09-05 09:15:33 +0000
committerPaolo Abeni <pabeni@redhat.com>2025-09-11 11:49:19 +0200
commit847748fc66d08a89135a74e29362a66ba4e3ab15 (patch)
tree7ea317895bccd7085aea1b15fbc5aea0aa9fac97 /net/hsr
parent393c841fe4333cdd856d0ca37b066d72746cfaa6 (diff)
downloadtip-847748fc66d08a89135a74e29362a66ba4e3ab15.tar.gz
hsr: hold rcu and dev lock for hsr_get_port_ndev
hsr_get_port_ndev calls hsr_for_each_port, which need to hold rcu lock. On the other hand, before return the port device, we need to hold the device reference to avoid UaF in the caller function. Suggested-by: Paolo Abeni <pabeni@redhat.com> Fixes: 9c10dd8eed74 ("net: hsr: Create and export hsr_get_port_ndev()") Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250905091533.377443-4-liuhangbin@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'net/hsr')
-rw-r--r--net/hsr/hsr_device.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index 702da1f9aaa90e..fbbc3ccf9df64b 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -675,9 +675,14 @@ struct net_device *hsr_get_port_ndev(struct net_device *ndev,
struct hsr_priv *hsr = netdev_priv(ndev);
struct hsr_port *port;
+ rcu_read_lock();
hsr_for_each_port(hsr, port)
- if (port->type == pt)
+ if (port->type == pt) {
+ dev_hold(port->dev);
+ rcu_read_unlock();
return port->dev;
+ }
+ rcu_read_unlock();
return NULL;
}
EXPORT_SYMBOL(hsr_get_port_ndev);