Skip to content

Commit

Permalink
Merge tag 'for-linus-4.8-ofs1' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/hubcap/linux

Pull orangefs updates from Mike Mashall:
 "Orangefs cleanups and enablement of O_DIRECT in open.

  Cleanups:

   - remove some unused defines, and also some obfuscatory ones.

   - remove a redundant xattr handler.

   - Remove useless xattr prefix arguments.

   - Be more picky about uid and gid handling WRT namespaces.

     Our use of current_user_ns() instead of init_user_ns left open the
     possibility that users could spoof their uids or gids when the
     server was running in a different namespace in "default security"
     mode.

   - Allow open(2) to succeed with O_DIRECT"

* tag 'for-linus-4.8-ofs1' of git://git.kernel.org/pub/scm/linux/kernel/git/hubcap/linux:
  orangefs: fix namespace handling
  Orangefs: allow O_DIRECT in open
  orangefs: Remove useless xattr prefix arguments
  orangefs: Remove redundant "trusted." xattr handler
  orangefs: Remove useless defines
  • Loading branch information
Linus Torvalds committed Jul 27, 2016
2 parents 396d109 + 78fee0b commit d31dcd9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 146 deletions.
17 changes: 7 additions & 10 deletions fs/orangefs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ struct posix_acl *orangefs_get_acl(struct inode *inode, int type)

switch (type) {
case ACL_TYPE_ACCESS:
key = ORANGEFS_XATTR_NAME_ACL_ACCESS;
key = XATTR_NAME_POSIX_ACL_ACCESS;
break;
case ACL_TYPE_DEFAULT:
key = ORANGEFS_XATTR_NAME_ACL_DEFAULT;
key = XATTR_NAME_POSIX_ACL_DEFAULT;
break;
default:
gossip_err("orangefs_get_acl: bogus value of type %d\n", type);
Expand All @@ -43,11 +43,8 @@ struct posix_acl *orangefs_get_acl(struct inode *inode, int type)
get_khandle_from_ino(inode),
key,
type);
ret = orangefs_inode_getxattr(inode,
"",
key,
value,
ORANGEFS_MAX_XATTR_VALUELEN);
ret = orangefs_inode_getxattr(inode, key, value,
ORANGEFS_MAX_XATTR_VALUELEN);
/* if the key exists, convert it to an in-memory rep */
if (ret > 0) {
acl = posix_acl_from_xattr(&init_user_ns, value, ret);
Expand All @@ -74,7 +71,7 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)

switch (type) {
case ACL_TYPE_ACCESS:
name = ORANGEFS_XATTR_NAME_ACL_ACCESS;
name = XATTR_NAME_POSIX_ACL_ACCESS;
if (acl) {
umode_t mode = inode->i_mode;
/*
Expand All @@ -98,7 +95,7 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
}
break;
case ACL_TYPE_DEFAULT:
name = ORANGEFS_XATTR_NAME_ACL_DEFAULT;
name = XATTR_NAME_POSIX_ACL_DEFAULT;
break;
default:
gossip_err("%s: invalid type %d!\n", __func__, type);
Expand Down Expand Up @@ -131,7 +128,7 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
* will xlate to a removexattr. However, we don't want removexattr
* complain if attributes does not exist.
*/
error = orangefs_inode_setxattr(inode, "", name, value, size, 0);
error = orangefs_inode_setxattr(inode, name, value, size, 0);

out:
kfree(value);
Expand Down
7 changes: 7 additions & 0 deletions fs/orangefs/devorangefs-req.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
2 changes: 0 additions & 2 deletions fs/orangefs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar
if (cmd == FS_IOC_GETFLAGS) {
val = 0;
ret = orangefs_inode_getxattr(file_inode(file),
ORANGEFS_XATTR_NAME_DEFAULT_PREFIX,
"user.pvfs2.meta_hint",
&val, sizeof(val));
if (ret < 0 && ret != -ENODATA)
Expand Down Expand Up @@ -549,7 +548,6 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar
"orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n",
(unsigned long long)val);
ret = orangefs_inode_setxattr(file_inode(file),
ORANGEFS_XATTR_NAME_DEFAULT_PREFIX,
"user.pvfs2.meta_hint",
&val, sizeof(val), 0);
}
Expand Down
25 changes: 11 additions & 14 deletions fs/orangefs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,16 @@ static int orangefs_releasepage(struct page *page, gfp_t foo)
* will need to be able to use O_DIRECT on open in order to support
* AIO. Modeled after NFS, they do this too.
*/
/*
* static ssize_t orangefs_direct_IO(int rw,
* struct kiocb *iocb,
* struct iov_iter *iter,
* loff_t offset)
*{
* gossip_debug(GOSSIP_INODE_DEBUG,
* "orangefs_direct_IO: %s\n",
* iocb->ki_filp->f_path.dentry->d_name.name);
*
* return -EINVAL;
*}
*/

static ssize_t orangefs_direct_IO(struct kiocb *iocb,
struct iov_iter *iter)
{
gossip_debug(GOSSIP_INODE_DEBUG,
"orangefs_direct_IO: %s\n",
iocb->ki_filp->f_path.dentry->d_name.name);

return -EINVAL;
}

struct backing_dev_info orangefs_backing_dev_info = {
.name = "orangefs",
Expand All @@ -150,7 +147,7 @@ const struct address_space_operations orangefs_address_operations = {
.readpages = orangefs_readpages,
.invalidatepage = orangefs_invalidatepage,
.releasepage = orangefs_releasepage,
/* .direct_IO = orangefs_direct_IO */
.direct_IO = orangefs_direct_IO,
};

static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
Expand Down
4 changes: 2 additions & 2 deletions fs/orangefs/orangefs-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 2 additions & 15 deletions fs/orangefs/orangefs-kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ struct client_debug_mask {
#define ORANGEFS_CACHE_CREATE_FLAGS 0
#endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */

/* orangefs xattr and acl related defines */
#define ORANGEFS_XATTR_INDEX_POSIX_ACL_ACCESS 1
#define ORANGEFS_XATTR_INDEX_POSIX_ACL_DEFAULT 2
#define ORANGEFS_XATTR_INDEX_TRUSTED 3
#define ORANGEFS_XATTR_INDEX_DEFAULT 4

#define ORANGEFS_XATTR_NAME_ACL_ACCESS XATTR_NAME_POSIX_ACL_ACCESS
#define ORANGEFS_XATTR_NAME_ACL_DEFAULT XATTR_NAME_POSIX_ACL_DEFAULT
#define ORANGEFS_XATTR_NAME_TRUSTED_PREFIX "trusted."
#define ORANGEFS_XATTR_NAME_DEFAULT_PREFIX ""

/* these functions are defined in orangefs-utils.c */
int orangefs_prepare_cdm_array(char *debug_array_string);
int orangefs_prepare_debugfs_help_string(int);
Expand Down Expand Up @@ -528,13 +517,11 @@ __s32 fsid_of_op(struct orangefs_kernel_op_s *op);
int orangefs_flush_inode(struct inode *inode);

ssize_t orangefs_inode_getxattr(struct inode *inode,
const char *prefix,
const char *name,
void *buffer,
size_t size);

int orangefs_inode_setxattr(struct inode *inode,
const char *prefix,
const char *name,
const void *value,
size_t size,
Expand Down Expand Up @@ -600,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; \
Expand Down
4 changes: 2 additions & 2 deletions fs/orangefs/orangefs-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit d31dcd9

Please sign in to comment.