]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
orangefs: fix namespace handling
authorJann Horn <jannh@google.com>
Fri, 24 Jun 2016 23:51:52 +0000 (01:51 +0200)
committerMike Marshall <hubcap@omnibond.com>
Tue, 5 Jul 2016 19:47:43 +0000 (15:47 -0400)
In orangefs_inode_getxattr(), an fsuid is written to dmesg. The kuid is
converted to a userspace uid via from_kuid(current_user_ns(), [...]), but
since dmesg is global, init_user_ns should be used here instead.

In copy_attributes_from_inode(), op_alloc() and fill_default_sys_attrs(),
upcall structures are populated with uids/gids that have been mapped into
the caller's namespace. However, those upcall structures are read by
another process (the userspace filesystem driver), and that process might
be running in another namespace. This effectively lets any user spoof its
uid and gid as seen by the userspace filesystem driver.

To fix the second issue, I just construct the opcall structures with
init_user_ns uids/gids and require the filesystem server to run in the
init namespace. Since orangefs is full of global state anyway (as the error
message in DUMP_DEVICE_ERROR explains, there can only be one userspace
orangefs filesystem driver at once), that shouldn't be a problem.

[
Why does orangefs even exist in the kernel if everything does upcalls into
userspace? What does orangefs do that couldn't be done with the FUSE
interface? If there is no good answer to those questions, I'd prefer to see
orangefs kicked out of the kernel. Can that be done for something that
shipped in a release?

According to commit f7ab093f74bf ("Orangefs: kernel client part 1"), they
even already have a FUSE daemon, and the only rational reason (apart from
"but most of our users report preferring to use our kernel module instead")
given for not wanting to use FUSE is one "in-the-works" feature that could
probably be integated into FUSE instead.
]

This patch has been compile-tested.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
fs/orangefs/devorangefs-req.c
fs/orangefs/orangefs-cache.c
fs/orangefs/orangefs-kernel.h
fs/orangefs/orangefs-utils.c
fs/orangefs/xattr.c

index db170beba7974c3d5d4491df452f0d75ca15ea13..a287a66d94e35189c2f7e226570e76d6e24f5925 100644 (file)
@@ -116,6 +116,13 @@ static int orangefs_devreq_open(struct inode *inode, struct file *file)
 {
        int ret = -EINVAL;
 
+       /* in order to ensure that the filesystem driver sees correct UIDs */
+       if (file->f_cred->user_ns != &init_user_ns) {
+               gossip_err("%s: device cannot be opened outside init_user_ns\n",
+                          __func__);
+               goto out;
+       }
+
        if (!(file->f_flags & O_NONBLOCK)) {
                gossip_err("%s: device cannot be opened in blocking mode\n",
                           __func__);
index 900a2e38e11bc9e7ac82f386ce678bdad0756c65..b6edbe9fb309eae431194a13d887f2fa934981c0 100644 (file)
@@ -136,10 +136,10 @@ struct orangefs_kernel_op_s *op_alloc(__s32 type)
                             llu(new_op->tag),
                             get_opname_string(new_op));
 
-               new_op->upcall.uid = from_kuid(current_user_ns(),
+               new_op->upcall.uid = from_kuid(&init_user_ns,
                                               current_fsuid());
 
-               new_op->upcall.gid = from_kgid(current_user_ns(),
+               new_op->upcall.gid = from_kgid(&init_user_ns,
                                               current_fsgid());
        } else {
                gossip_err("op_alloc: kmem_cache_zalloc failed!\n");
index 7b542f168d442fc7bd14ebd202a0b2c6187d3715..c1181e5529afa83015155b9025b3985c35d4db4f 100644 (file)
@@ -587,8 +587,8 @@ int service_operation(struct orangefs_kernel_op_s *op,
 
 #define fill_default_sys_attrs(sys_attr, type, mode)                   \
 do {                                                                   \
-       sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
-       sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
+       sys_attr.owner = from_kuid(&init_user_ns, current_fsuid()); \
+       sys_attr.group = from_kgid(&init_user_ns, current_fsgid()); \
        sys_attr.perms = ORANGEFS_util_translate_mode(mode);            \
        sys_attr.mtime = 0;                                             \
        sys_attr.atime = 0;                                             \
index 2d129b5886eeb7a61d067502900dca75cf525d08..c5fbc62357c6e2dc37d4cebf05289715def98b98 100644 (file)
@@ -153,12 +153,12 @@ static inline int copy_attributes_from_inode(struct inode *inode,
         */
        attrs->mask = 0;
        if (iattr->ia_valid & ATTR_UID) {
-               attrs->owner = from_kuid(current_user_ns(), iattr->ia_uid);
+               attrs->owner = from_kuid(&init_user_ns, iattr->ia_uid);
                attrs->mask |= ORANGEFS_ATTR_SYS_UID;
                gossip_debug(GOSSIP_UTILS_DEBUG, "(UID) %d\n", attrs->owner);
        }
        if (iattr->ia_valid & ATTR_GID) {
-               attrs->group = from_kgid(current_user_ns(), iattr->ia_gid);
+               attrs->group = from_kgid(&init_user_ns, iattr->ia_gid);
                attrs->mask |= ORANGEFS_ATTR_SYS_GID;
                gossip_debug(GOSSIP_UTILS_DEBUG, "(GID) %d\n", attrs->group);
        }
index 73a0c3411d4b907d03875f881393cf0439da4b3d..2a9f07f06d100f18ef5369aae096594de876c0da 100644 (file)
@@ -79,8 +79,8 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
                return -EINVAL;
        }
 
-       fsuid = from_kuid(current_user_ns(), current_fsuid());
-       fsgid = from_kgid(current_user_ns(), current_fsgid());
+       fsuid = from_kuid(&init_user_ns, current_fsuid());
+       fsgid = from_kgid(&init_user_ns, current_fsgid());
 
        gossip_debug(GOSSIP_XATTR_DEBUG,
                     "getxattr on inode %pU, name %s "