bridge: make sure objects belong to container's owner
authorTyler Hicks <tyhicks@canonical.com>
Fri, 20 Jul 2018 21:56:54 +0000 (21:56 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 21 Jul 2018 06:44:36 +0000 (23:44 -0700)
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>
net/bridge/br_if.c
net/bridge/br_private.h
net/bridge/br_sysfs_if.c

index 05e42d86882d69de07cdb79ec9d00e0f214e69cd..e7c8d55212aaf7c61af4524bc2ea3d061baf2892 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"
 
@@ -204,11 +205,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 5216a524b53701d3930a550a26e01fbafc920b6b..cf0005d2a4d07db08025915311192af218ceaa80 100644 (file)
@@ -283,6 +283,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 f99c5bf5c906270e00c1e96177970ac15fdcbc71..ab4c7f8adf6836600b3888505d0b76863d29e1c9 100644 (file)
@@ -249,13 +249,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;
@@ -268,7 +267,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;