]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
bridge: make sure objects belong to container's owner
authorTyler Hicks <tyhicks@canonical.com>
Wed, 31 Oct 2018 00:55:24 +0000 (00:55 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fri, 9 Nov 2018 18:59:54 +0000 (16:59 -0200)
BugLink: https://launchpad.net/bugs/1784501
When creating various bridge objects in /sys/class/net/... make sure
that they belong to the container's owner instead of global root (if
they belong to a container/namespace).

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 705e0dea4d52ef420a7d37fd9cc6725092e5e1ff)
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Kleber Souza <kleber.souza@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
net/bridge/br_if.c
net/bridge/br_private.h
net/bridge/br_sysfs_if.c

index 4be5335407c5184a1001122f2701a807fad1b39c..20629d142bd0e2f25ad4908f841ea25dad07f22f 100644 (file)
@@ -26,6 +26,7 @@
 #include <net/sock.h>
 #include <linux/if_vlan.h>
 #include <net/switchdev.h>
+#include <net/net_namespace.h>
 
 #include "br_private.h"
 
@@ -199,11 +200,19 @@ static void release_nbp(struct kobject *kobj)
        kfree(p);
 }
 
+static void brport_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+       struct net_bridge_port *p = kobj_to_brport(kobj);
+
+       net_ns_get_ownership(dev_net(p->dev), uid, gid);
+}
+
 static struct kobj_type brport_ktype = {
 #ifdef CONFIG_SYSFS
        .sysfs_ops = &brport_sysfs_ops,
 #endif
        .release = release_nbp,
+       .get_ownership = brport_get_ownership,
 };
 
 static void destroy_nbp(struct net_bridge_port *p)
index 1312b8d20ec3d1c4b90c1c57b94b16c49ebb1d3a..14224384e4d539d907597bf32c46e3e876ac2b61 100644 (file)
@@ -278,6 +278,8 @@ struct net_bridge_port {
        u16                             group_fwd_mask;
 };
 
+#define kobj_to_brport(obj)    container_of(obj, struct net_bridge_port, kobj)
+
 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
 #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
 
index 126a8ea73c9681dc2772423715f4717e2d1ec409..4cfad3735d354007a0b8a477ad89f93add9d8a44 100644 (file)
@@ -247,13 +247,12 @@ static const struct brport_attribute *brport_attrs[] = {
 };
 
 #define to_brport_attr(_at) container_of(_at, struct brport_attribute, attr)
-#define to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
 
 static ssize_t brport_show(struct kobject *kobj,
                           struct attribute *attr, char *buf)
 {
        struct brport_attribute *brport_attr = to_brport_attr(attr);
-       struct net_bridge_port *p = to_brport(kobj);
+       struct net_bridge_port *p = kobj_to_brport(kobj);
 
        if (!brport_attr->show)
                return -EINVAL;
@@ -266,7 +265,7 @@ static ssize_t brport_store(struct kobject *kobj,
                            const char *buf, size_t count)
 {
        struct brport_attribute *brport_attr = to_brport_attr(attr);
-       struct net_bridge_port *p = to_brport(kobj);
+       struct net_bridge_port *p = kobj_to_brport(kobj);
        ssize_t ret = -EINVAL;
        char *endp;
        unsigned long val;