Skip to content

Commit

Permalink
[vpsAdminOS] userns trusted xattr
Browse files Browse the repository at this point in the history
  • Loading branch information
snajpa committed Oct 4, 2019
1 parent e472c16 commit f9ad799
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/os/linux/kernel/linux/xattr_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define _ZFS_XATTR_H

#include <linux/posix_acl_xattr.h>
#include <linux/user_namespace.h>

/*
* 2.6.35 API change,
Expand Down
18 changes: 15 additions & 3 deletions module/os/linux/zfs/zpl_xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,23 @@ xattr_handler_t zpl_xattr_user_handler =
* the kernel) which keep information in extended attributes to which
* ordinary processes should not have access." - xattr(7)
*/
bool __xattr_trusted(void)
{
struct user_namespace *ns = current_user_ns();
if (((ns == &init_user_ns) || (ns->parent == &init_user_ns)) &&
ns_capable(ns, CAP_SYS_ADMIN))
return true;
printk(KERN_INFO "ZFS: __xattr_trusted() failed for pid %d\n",
current->pid);
return false;
}


static int
__zpl_xattr_trusted_list(struct inode *ip, char *list, size_t list_size,
const char *name, size_t name_len)
{
return (capable(CAP_SYS_ADMIN));
return __xattr_trusted();
}
ZPL_XATTR_LIST_WRAPPER(zpl_xattr_trusted_list);

Expand All @@ -767,7 +779,7 @@ __zpl_xattr_trusted_get(struct inode *ip, const char *name,
char *xattr_name;
int error;

if (!capable(CAP_SYS_ADMIN))
if (!__xattr_trusted())
return (-EACCES);
/* xattr_resolve_name will do this for us if this is defined */
#ifndef HAVE_XATTR_HANDLER_NAME
Expand All @@ -789,7 +801,7 @@ __zpl_xattr_trusted_set(struct inode *ip, const char *name,
char *xattr_name;
int error;

if (!capable(CAP_SYS_ADMIN))
if (!__xattr_trusted())
return (-EACCES);
/* xattr_resolve_name will do this for us if this is defined */
#ifndef HAVE_XATTR_HANDLER_NAME
Expand Down

0 comments on commit f9ad799

Please sign in to comment.