From: Eric Dumazet Date: Mon, 25 May 2026 08:35:41 +0000 (+0000) Subject: rtnetlink: do not assume RTNL is held in link_master_filtered() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6768c7c3d70f0d6f9cb6fad2b33357ec7379d952;p=thirdparty%2Flinux.git rtnetlink: do not assume RTNL is held in link_master_filtered() RTNL might be no longer held by the caller in the following patch. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260525083542.1565964-5-edumazet@google.com Signed-off-by: Jakub Kicinski --- diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 6041e008b22d..0a59036d5f93 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2371,22 +2371,24 @@ static struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla, static bool link_master_filtered(struct net_device *dev, int master_idx) { struct net_device *master; + bool res = false; if (!master_idx) return false; - master = netdev_master_upper_dev_get(dev); + rcu_read_lock(); + master = netdev_master_upper_dev_get_rcu(dev); /* 0 is already used to denote IFLA_MASTER wasn't passed, therefore need * another invalid value for ifindex to denote "no master". */ if (master_idx == -1) - return !!master; - - if (!master || master->ifindex != master_idx) - return true; + res = !!master; + else if (!master || master->ifindex != master_idx) + res = true; + rcu_read_unlock(); - return false; + return res; } static bool link_kind_filtered(const struct net_device *dev,