]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
rtnetlink: require unique netns identifier
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 7 Feb 2018 12:53:20 +0000 (13:53 +0100)
committerSeth Forshee <seth.forshee@canonical.com>
Wed, 28 Feb 2018 14:46:59 +0000 (08:46 -0600)
BugLink: http://bugs.launchpad.net/bugs/1748232
Since we've added support for IFLA_IF_NETNSID for RTM_{DEL,GET,SET,NEW}LINK
it is possible for userspace to send us requests with three different
properties to identify a target network namespace. This affects at least
RTM_{NEW,SET}LINK. Each of them could potentially refer to a different
network namespace which is confusing. For legacy reasons the kernel will
pick the IFLA_NET_NS_PID property first and then look for the
IFLA_NET_NS_FD property but there is no reason to extend this type of
behavior to network namespace ids. The regression potential is quite
minimal since the rtnetlink requests in question either won't allow
IFLA_IF_NETNSID requests before 4.16 is out (RTM_{NEW,SET}LINK) or don't
support IFLA_NET_NS_{PID,FD} (RTM_{DEL,GET}LINK) in the first place.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 4ff66cae7f10b65b028dc3bdaaad9cc2989ef6ae)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
net/core/rtnetlink.c

index 67f77ef6a27e83d0b9c79467cda1901f26b512b9..fc0d9b7cfb04103c911904d468bc8391833dbb84 100644 (file)
@@ -1858,6 +1858,38 @@ static struct net *rtnl_link_get_net_capable(const struct sk_buff *skb,
        return net;
 }
 
        return net;
 }
 
+/* Verify that rtnetlink requests do not pass additional properties
+ * potentially referring to different network namespaces.
+ */
+static int rtnl_ensure_unique_netns(struct nlattr *tb[],
+                                   struct netlink_ext_ack *extack,
+                                   bool netns_id_only)
+{
+
+       if (netns_id_only) {
+               if (!tb[IFLA_NET_NS_PID] && !tb[IFLA_NET_NS_FD])
+                       return 0;
+
+               NL_SET_ERR_MSG(extack, "specified netns attribute not supported");
+               return -EOPNOTSUPP;
+       }
+
+       if (tb[IFLA_IF_NETNSID] && (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]))
+               goto invalid_attr;
+
+       if (tb[IFLA_NET_NS_PID] && (tb[IFLA_IF_NETNSID] || tb[IFLA_NET_NS_FD]))
+               goto invalid_attr;
+
+       if (tb[IFLA_NET_NS_FD] && (tb[IFLA_IF_NETNSID] || tb[IFLA_NET_NS_PID]))
+               goto invalid_attr;
+
+       return 0;
+
+invalid_attr:
+       NL_SET_ERR_MSG(extack, "multiple netns identifying attributes specified");
+       return -EINVAL;
+}
+
 static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
 {
        if (dev) {
 static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
 {
        if (dev) {
@@ -2440,6 +2472,10 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (err < 0)
                goto errout;
 
        if (err < 0)
                goto errout;
 
+       err = rtnl_ensure_unique_netns(tb, extack, false);
+       if (err < 0)
+               goto errout;
+
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
        else
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
        else
@@ -2536,6 +2572,10 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (err < 0)
                return err;
 
        if (err < 0)
                return err;
 
+       err = rtnl_ensure_unique_netns(tb, extack, true);
+       if (err < 0)
+               return err;
+
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
 
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
 
@@ -2685,6 +2725,10 @@ replay:
        if (err < 0)
                return err;
 
        if (err < 0)
                return err;
 
+       err = rtnl_ensure_unique_netns(tb, extack, false);
+       if (err < 0)
+               return err;
+
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
        else
        if (tb[IFLA_IFNAME])
                nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
        else
@@ -2928,6 +2972,10 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (err < 0)
                return err;
 
        if (err < 0)
                return err;
 
+       err = rtnl_ensure_unique_netns(tb, extack, true);
+       if (err < 0)
+               return err;
+
        if (tb[IFLA_IF_NETNSID]) {
                netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
                tgt_net = get_target_net(NETLINK_CB(skb).sk, netnsid);
        if (tb[IFLA_IF_NETNSID]) {
                netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
                tgt_net = get_target_net(NETLINK_CB(skb).sk, netnsid);