]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/sysfs/dir.c
sysfs, kobject: allow creating kobject belonging to arbitrary users
[mirror_ubuntu-bionic-kernel.git] / fs / sysfs / dir.c
index 2b67bda2021b9e2955ae66ba03e536dfdcefec2a..639d182836b341817d1d802272ac249153625fd1 100644 (file)
@@ -41,6 +41,8 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
 {
        struct kernfs_node *parent, *kn;
+       kuid_t uid;
+       kgid_t gid;
 
        BUG_ON(!kobj);
 
@@ -52,8 +54,11 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
        if (!parent)
                return -ENOENT;
 
+       kobject_get_ownership(kobj, &uid, &gid);
+
        kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
-                                 S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
+                                 S_IRWXU | S_IRUGO | S_IXUGO, uid, gid,
+                                 kobj, ns);
        if (IS_ERR(kn)) {
                if (PTR_ERR(kn) == -EEXIST)
                        sysfs_warn_dup(parent, kobject_name(kobj));