mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink
A tunnel changelink() operates on at most two netns, dev_net(dev) and the tunnel link netns t->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in t->net can rewrite a tunnel that lives in t->net. Add rtnl_dev_link_net_capable() next to rtnl_get_net_ns_capable() in net/core/rtnetlink.c. It requires CAP_NET_ADMIN in the link netns and is skipped when the link netns is dev_net(dev), where the rtnl path already checked it. The other patches in this series use the same helper. Gate ipgre_changelink() and erspan_changelink() with it, at the top of the op before any attribute is parsed, because the parsers update live tunnel fields first. ipgre_netlink_parms() sets t->collect_md before ip_tunnel_changelink() runs. Commit8b484efd5c("ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().") added the same check on the ioctl path. This adds it on RTM_NEWLINK. Reported-by: Xiao Liang <shaw.leon@gmail.com> Closes: https://lore.kernel.org/netdev/CABAhCOSzP1vaThGV35_VnsRCb=87_CPjPVsTHbq905k8A+BuUg@mail.gmail.com/ Fixes:b57708add3("gre: add x-netns support") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20260612085941.3158249-2-maoyixie.tju@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
e586644d0a
commit
8165f7ff57
@@ -256,6 +256,8 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm,
|
||||
int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer,
|
||||
struct netlink_ext_ack *exterr);
|
||||
struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
|
||||
bool rtnl_dev_link_net_capable(const struct net_device *dev,
|
||||
const struct net *link_net);
|
||||
|
||||
#define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
|
||||
|
||||
|
||||
@@ -2438,6 +2438,14 @@ struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rtnl_get_net_ns_capable);
|
||||
|
||||
bool rtnl_dev_link_net_capable(const struct net_device *dev,
|
||||
const struct net *link_net)
|
||||
{
|
||||
return net_eq(link_net, dev_net(dev)) ||
|
||||
ns_capable(link_net->user_ns, CAP_NET_ADMIN);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rtnl_dev_link_net_capable);
|
||||
|
||||
static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh,
|
||||
bool strict_check, struct nlattr **tb,
|
||||
struct netlink_ext_ack *extack)
|
||||
|
||||
@@ -1457,6 +1457,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],
|
||||
__u32 fwmark = t->fwmark;
|
||||
int err;
|
||||
|
||||
if (!rtnl_dev_link_net_capable(dev, t->net))
|
||||
return -EPERM;
|
||||
|
||||
err = ipgre_newlink_encap_setup(dev, data);
|
||||
if (err)
|
||||
return err;
|
||||
@@ -1486,6 +1489,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],
|
||||
__u32 fwmark = t->fwmark;
|
||||
int err;
|
||||
|
||||
if (!rtnl_dev_link_net_capable(dev, t->net))
|
||||
return -EPERM;
|
||||
|
||||
err = ipgre_newlink_encap_setup(dev, data);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user