diff mbox series

[NET-PREV,02/51] net: Add nlaattr check to rtnl_link_get_net_capable()

Message ID 174265428803.356712.5393035417908731217.stgit@pro.pro (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Kill rtnl_lock using fine-grained nd_lock | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Kirill Tkhai March 22, 2025, 2:38 p.m. UTC
The patch is preparation in rtnetlink code for using nd_lock.
This is a step to move dereference of tb[IFLA_MASTER] up
to where main dev is dereferenced by ifi_index.

Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
---
 net/core/rtnetlink.c |    4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index b33a7e86c534..34e35b81cfa6 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2363,6 +2363,9 @@  static struct net *rtnl_link_get_net_capable(const struct sk_buff *skb,
 {
 	struct net *net;
 
+	if (!tb[IFLA_NET_NS_PID] && !tb[IFLA_NET_NS_FD] && !tb[IFLA_TARGET_NETNSID])
+		return NULL;
+
 	net = rtnl_link_get_net_by_nlattr(src_net, tb);
 	if (IS_ERR(net))
 		return net;
@@ -3480,6 +3483,7 @@  static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm,
 	dest_net = rtnl_link_get_net_capable(skb, net, tb, CAP_NET_ADMIN);
 	if (IS_ERR(dest_net))
 		return PTR_ERR(dest_net);
+	dest_net = dest_net ? : get_net(net);
 
 	if (tb[IFLA_LINK_NETNSID]) {
 		int id = nla_get_s32(tb[IFLA_LINK_NETNSID]);