diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2018-07-20 17:56:47 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-07-21 02:44:35 -0400 |
commit | 488dee96bb62f0b3d9e678cf42574034d5b033a5 (patch) | |
tree | 2969d47ffb0ffeaf15d20ffb0eda78a2bb694a40 /fs/sysfs | |
parent | 7c4ec749a3bd89237d7195ccd621bf5d4124d6b5 (diff) |
kernfs: allow creating kernfs objects with arbitrary uid/gid
This change allows creating kernfs files and directories with arbitrary
uid/gid instead of always using GLOBAL_ROOT_UID/GID by extending
kernfs_create_dir_ns() and kernfs_create_file_ns() with uid/gid arguments.
The "simple" kernfs_create_file() and kernfs_create_dir() are left alone
and always create objects belonging to the global root.
When creating symlinks ownership (uid/gid) is taken from the target kernfs
object.
Co-Developed-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/dir.c | 4 | ||||
-rw-r--r-- | fs/sysfs/file.c | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 58eba92a0e41..e39b884f0867 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -52,7 +52,9 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) | |||
52 | return -ENOENT; | 52 | return -ENOENT; |
53 | 53 | ||
54 | kn = kernfs_create_dir_ns(parent, kobject_name(kobj), | 54 | kn = kernfs_create_dir_ns(parent, kobject_name(kobj), |
55 | S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns); | 55 | S_IRWXU | S_IRUGO | S_IXUGO, |
56 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, | ||
57 | kobj, ns); | ||
56 | if (IS_ERR(kn)) { | 58 | if (IS_ERR(kn)) { |
57 | if (PTR_ERR(kn) == -EEXIST) | 59 | if (PTR_ERR(kn) == -EEXIST) |
58 | sysfs_warn_dup(parent, kobject_name(kobj)); | 60 | sysfs_warn_dup(parent, kobject_name(kobj)); |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 5c13f29bfcdb..513fa691ecbd 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -302,8 +302,9 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, | |||
302 | if (!attr->ignore_lockdep) | 302 | if (!attr->ignore_lockdep) |
303 | key = attr->key ?: (struct lock_class_key *)&attr->skey; | 303 | key = attr->key ?: (struct lock_class_key *)&attr->skey; |
304 | #endif | 304 | #endif |
305 | kn = __kernfs_create_file(parent, attr->name, mode & 0777, size, ops, | 305 | kn = __kernfs_create_file(parent, attr->name, |
306 | (void *)attr, ns, key); | 306 | mode & 0777, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, |
307 | size, ops, (void *)attr, ns, key); | ||
307 | if (IS_ERR(kn)) { | 308 | if (IS_ERR(kn)) { |
308 | if (PTR_ERR(kn) == -EEXIST) | 309 | if (PTR_ERR(kn) == -EEXIST) |
309 | sysfs_warn_dup(parent, attr->name); | 310 | sysfs_warn_dup(parent, attr->name); |