mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
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>
This commit is contained in:
committed by
David S. Miller
parent
7c4ec749a3
commit
488dee96bb
@@ -15,6 +15,7 @@
|
||||
#include <linux/lockdep.h>
|
||||
#include <linux/rbtree.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uidgid.h>
|
||||
#include <linux/wait.h>
|
||||
|
||||
struct file;
|
||||
@@ -325,12 +326,14 @@ void kernfs_destroy_root(struct kernfs_root *root);
|
||||
|
||||
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
|
||||
const char *name, umode_t mode,
|
||||
kuid_t uid, kgid_t gid,
|
||||
void *priv, const void *ns);
|
||||
struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
|
||||
const char *name);
|
||||
struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
|
||||
const char *name,
|
||||
umode_t mode, loff_t size,
|
||||
const char *name, umode_t mode,
|
||||
kuid_t uid, kgid_t gid,
|
||||
loff_t size,
|
||||
const struct kernfs_ops *ops,
|
||||
void *priv, const void *ns,
|
||||
struct lock_class_key *key);
|
||||
@@ -415,12 +418,14 @@ static inline void kernfs_destroy_root(struct kernfs_root *root) { }
|
||||
|
||||
static inline struct kernfs_node *
|
||||
kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
|
||||
umode_t mode, void *priv, const void *ns)
|
||||
umode_t mode, kuid_t uid, kgid_t gid,
|
||||
void *priv, const void *ns)
|
||||
{ return ERR_PTR(-ENOSYS); }
|
||||
|
||||
static inline struct kernfs_node *
|
||||
__kernfs_create_file(struct kernfs_node *parent, const char *name,
|
||||
umode_t mode, loff_t size, const struct kernfs_ops *ops,
|
||||
umode_t mode, kuid_t uid, kgid_t gid,
|
||||
loff_t size, const struct kernfs_ops *ops,
|
||||
void *priv, const void *ns, struct lock_class_key *key)
|
||||
{ return ERR_PTR(-ENOSYS); }
|
||||
|
||||
@@ -498,12 +503,15 @@ static inline struct kernfs_node *
|
||||
kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
|
||||
void *priv)
|
||||
{
|
||||
return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
|
||||
return kernfs_create_dir_ns(parent, name, mode,
|
||||
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
|
||||
priv, NULL);
|
||||
}
|
||||
|
||||
static inline struct kernfs_node *
|
||||
kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
|
||||
umode_t mode, loff_t size, const struct kernfs_ops *ops,
|
||||
umode_t mode, kuid_t uid, kgid_t gid,
|
||||
loff_t size, const struct kernfs_ops *ops,
|
||||
void *priv, const void *ns)
|
||||
{
|
||||
struct lock_class_key *key = NULL;
|
||||
@@ -511,15 +519,17 @@ kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
|
||||
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
||||
key = (struct lock_class_key *)&ops->lockdep_key;
|
||||
#endif
|
||||
return __kernfs_create_file(parent, name, mode, size, ops, priv, ns,
|
||||
key);
|
||||
return __kernfs_create_file(parent, name, mode, uid, gid,
|
||||
size, ops, priv, ns, key);
|
||||
}
|
||||
|
||||
static inline struct kernfs_node *
|
||||
kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode,
|
||||
loff_t size, const struct kernfs_ops *ops, void *priv)
|
||||
{
|
||||
return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
|
||||
return kernfs_create_file_ns(parent, name, mode,
|
||||
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
|
||||
size, ops, priv, NULL);
|
||||
}
|
||||
|
||||
static inline int kernfs_remove_by_name(struct kernfs_node *parent,
|
||||
|
Reference in New Issue
Block a user