提交 4e4098a3 编写于 作者: G Greg Kroah-Hartman

driver core: handle user namespaces properly with the uid/gid devtmpfs change

Now that devtmpfs is caring about uid/gid, we need to use the correct
internal types so users who have USER_NS enabled will have things work
properly for them.

Thanks to Eric for pointing this out, and the patch review.
Reported-by: NEric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Cc: Ming Lei <ming.lei@canonical.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 d81c8d19
...@@ -1112,7 +1112,7 @@ struct class block_class = { ...@@ -1112,7 +1112,7 @@ struct class block_class = {
}; };
static char *block_devnode(struct device *dev, umode_t *mode, static char *block_devnode(struct device *dev, umode_t *mode,
uid_t *uid, gid_t *gid) kuid_t *uid, kgid_t *gid)
{ {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
......
...@@ -283,8 +283,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, ...@@ -283,8 +283,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
const char *tmp; const char *tmp;
const char *name; const char *name;
umode_t mode = 0; umode_t mode = 0;
uid_t uid = 0; kuid_t uid = GLOBAL_ROOT_UID;
gid_t gid = 0; kgid_t gid = GLOBAL_ROOT_GID;
add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt)); add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt));
add_uevent_var(env, "MINOR=%u", MINOR(dev->devt)); add_uevent_var(env, "MINOR=%u", MINOR(dev->devt));
...@@ -293,10 +293,10 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, ...@@ -293,10 +293,10 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
add_uevent_var(env, "DEVNAME=%s", name); add_uevent_var(env, "DEVNAME=%s", name);
if (mode) if (mode)
add_uevent_var(env, "DEVMODE=%#o", mode & 0777); add_uevent_var(env, "DEVMODE=%#o", mode & 0777);
if (uid) if (!uid_eq(uid, GLOBAL_ROOT_UID))
add_uevent_var(env, "DEVUID=%u", uid); add_uevent_var(env, "DEVUID=%u", from_kuid(&init_user_ns, uid));
if (gid) if (!gid_eq(gid, GLOBAL_ROOT_GID))
add_uevent_var(env, "DEVGID=%u", gid); add_uevent_var(env, "DEVGID=%u", from_kgid(&init_user_ns, gid));
kfree(tmp); kfree(tmp);
} }
} }
...@@ -1297,7 +1297,7 @@ static struct device *next_device(struct klist_iter *i) ...@@ -1297,7 +1297,7 @@ static struct device *next_device(struct klist_iter *i)
* freed by the caller. * freed by the caller.
*/ */
const char *device_get_devnode(struct device *dev, const char *device_get_devnode(struct device *dev,
umode_t *mode, uid_t *uid, gid_t *gid, umode_t *mode, kuid_t *uid, kgid_t *gid,
const char **tmp) const char **tmp)
{ {
char *s; char *s;
......
...@@ -42,8 +42,8 @@ static struct req { ...@@ -42,8 +42,8 @@ static struct req {
int err; int err;
const char *name; const char *name;
umode_t mode; /* 0 => delete */ umode_t mode; /* 0 => delete */
uid_t uid; kuid_t uid;
gid_t gid; kgid_t gid;
struct device *dev; struct device *dev;
} *requests; } *requests;
...@@ -88,8 +88,8 @@ int devtmpfs_create_node(struct device *dev) ...@@ -88,8 +88,8 @@ int devtmpfs_create_node(struct device *dev)
return 0; return 0;
req.mode = 0; req.mode = 0;
req.uid = 0; req.uid = GLOBAL_ROOT_UID;
req.gid = 0; req.gid = GLOBAL_ROOT_GID;
req.name = device_get_devnode(dev, &req.mode, &req.uid, &req.gid, &tmp); req.name = device_get_devnode(dev, &req.mode, &req.uid, &req.gid, &tmp);
if (!req.name) if (!req.name)
return -ENOMEM; return -ENOMEM;
...@@ -192,8 +192,8 @@ static int create_path(const char *nodepath) ...@@ -192,8 +192,8 @@ static int create_path(const char *nodepath)
return err; return err;
} }
static int handle_create(const char *nodename, umode_t mode, uid_t uid, static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
gid_t gid, struct device *dev) kgid_t gid, struct device *dev)
{ {
struct dentry *dentry; struct dentry *dentry;
struct path path; struct path path;
...@@ -212,8 +212,8 @@ static int handle_create(const char *nodename, umode_t mode, uid_t uid, ...@@ -212,8 +212,8 @@ static int handle_create(const char *nodename, umode_t mode, uid_t uid,
struct iattr newattrs; struct iattr newattrs;
newattrs.ia_mode = mode; newattrs.ia_mode = mode;
newattrs.ia_uid = KUIDT_INIT(uid); newattrs.ia_uid = uid;
newattrs.ia_gid = KGIDT_INIT(gid); newattrs.ia_gid = gid;
newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID; newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
mutex_lock(&dentry->d_inode->i_mutex); mutex_lock(&dentry->d_inode->i_mutex);
notify_change(dentry, &newattrs); notify_change(dentry, &newattrs);
...@@ -364,7 +364,7 @@ int devtmpfs_mount(const char *mntdir) ...@@ -364,7 +364,7 @@ int devtmpfs_mount(const char *mntdir)
static DECLARE_COMPLETION(setup_done); static DECLARE_COMPLETION(setup_done);
static int handle(const char *name, umode_t mode, uid_t uid, gid_t gid, static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
struct device *dev) struct device *dev)
{ {
if (mode) if (mode)
......
...@@ -318,7 +318,7 @@ static const struct dev_pm_ops usb_device_pm_ops = { ...@@ -318,7 +318,7 @@ static const struct dev_pm_ops usb_device_pm_ops = {
static char *usb_devnode(struct device *dev, static char *usb_devnode(struct device *dev,
umode_t *mode, uid_t *uid, gid_t *gid) umode_t *mode, kuid_t *uid, kgid_t *gid)
{ {
struct usb_device *usb_dev; struct usb_device *usb_dev;
......
...@@ -467,7 +467,7 @@ struct device_type { ...@@ -467,7 +467,7 @@ struct device_type {
const struct attribute_group **groups; const struct attribute_group **groups;
int (*uevent)(struct device *dev, struct kobj_uevent_env *env); int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
char *(*devnode)(struct device *dev, umode_t *mode, char *(*devnode)(struct device *dev, umode_t *mode,
uid_t *uid, gid_t *gid); kuid_t *uid, kgid_t *gid);
void (*release)(struct device *dev); void (*release)(struct device *dev);
const struct dev_pm_ops *pm; const struct dev_pm_ops *pm;
...@@ -845,7 +845,7 @@ extern int device_rename(struct device *dev, const char *new_name); ...@@ -845,7 +845,7 @@ extern int device_rename(struct device *dev, const char *new_name);
extern int device_move(struct device *dev, struct device *new_parent, extern int device_move(struct device *dev, struct device *new_parent,
enum dpm_order dpm_order); enum dpm_order dpm_order);
extern const char *device_get_devnode(struct device *dev, extern const char *device_get_devnode(struct device *dev,
umode_t *mode, uid_t *uid, gid_t *gid, umode_t *mode, kuid_t *uid, kgid_t *gid,
const char **tmp); const char **tmp);
extern void *dev_get_drvdata(const struct device *dev); extern void *dev_get_drvdata(const struct device *dev);
extern int dev_set_drvdata(struct device *dev, void *data); extern int dev_set_drvdata(struct device *dev, void *data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册