]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
driver core: set up ownership of class devices in sysfs
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 31 Oct 2018 00:55:20 +0000 (00:55 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fri, 9 Nov 2018 18:59:51 +0000 (16:59 -0200)
BugLink: https://launchpad.net/bugs/1784501
Plumb in get_ownership() callback for devices belonging to a class so that
they can be created with uid/gid different from global root. This will
allow network devices in a container to belong to container's root and not
global root.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 9944e894c1266dc8515c82d1ff752d681215526b)
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>
drivers/base/core.c
include/linux/device.h

index 6835736daf2d81dc3907b8babcf6564807df00e9..3e63e0f443fbb789af2b3f078038884ff5bfa53c 100644 (file)
@@ -833,10 +833,19 @@ static const void *device_namespace(struct kobject *kobj)
        return ns;
 }
 
+static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+       struct device *dev = kobj_to_dev(kobj);
+
+       if (dev->class && dev->class->get_ownership)
+               dev->class->get_ownership(dev, uid, gid);
+}
+
 static struct kobj_type device_ktype = {
        .release        = device_release,
        .sysfs_ops      = &dev_sysfs_ops,
        .namespace      = device_namespace,
+       .get_ownership  = device_get_ownership,
 };
 
 
index 7d537ae1fee45d319c4c57de0287c3683f527707..b67683738812ea11458294a0be5a95f5cc0bb12e 100644 (file)
@@ -377,6 +377,9 @@ int subsys_virtual_register(struct bus_type *subsys,
  * @shutdown_pre: Called at shut-down time before driver shutdown.
  * @ns_type:   Callbacks so sysfs can detemine namespaces.
  * @namespace: Namespace of the device belongs to this class.
+ * @get_ownership: Allows class to specify uid/gid of the sysfs directories
+ *             for the devices belonging to the class. Usually tied to
+ *             device's namespace.
  * @pm:                The default device power management operations of this class.
  * @p:         The private data of the driver core, no one other than the
  *             driver core can touch this.
@@ -406,6 +409,8 @@ struct class {
        const struct kobj_ns_type_operations *ns_type;
        const void *(*namespace)(struct device *dev);
 
+       void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
+
        const struct dev_pm_ops *pm;
 
        struct subsys_private *p;