Skip to content

Commit

Permalink
NFS: Extend NFS xattr handlers to accept the security namespace
Browse files Browse the repository at this point in the history
The existing NFSv4 xattr handlers do not accept xattr calls to the security
namespace. This patch extends these handlers to accept xattrs from the security
namespace in addition to the default NFSv4 ACL namespace.

Acked-by: James Morris <[email protected]>
Signed-off-by: Matthew N. Dodd <[email protected]>
Signed-off-by: Miguel Rodel Felipe <[email protected]>
Signed-off-by: Phua Eu Gene <[email protected]>
Signed-off-by: Khin Mi Mi Aung <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
  • Loading branch information
dpquigl authored and Trond Myklebust committed Jun 8, 2013
1 parent aa9c266 commit c9bccef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5640,6 +5640,53 @@ static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
return len;
}

#ifdef CONFIG_NFS_V4_SECURITY_LABEL
static inline int nfs4_server_supports_labels(struct nfs_server *server)
{
return server->caps & NFS_CAP_SECURITY_LABEL;
}

static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key,
const void *buf, size_t buflen,
int flags, int type)
{
if (security_ismaclabel(key))
return nfs4_set_security_label(dentry, buf, buflen);

return -EOPNOTSUPP;
}

static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key,
void *buf, size_t buflen, int type)
{
if (security_ismaclabel(key))
return nfs4_get_security_label(dentry->d_inode, buf, buflen);
return -EOPNOTSUPP;
}

static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list,
size_t list_len, const char *name,
size_t name_len, int type)
{
size_t len = 0;

if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) {
len = security_inode_listsecurity(dentry->d_inode, NULL, 0);
if (list && len <= list_len)
security_inode_listsecurity(dentry->d_inode, list, len);
}
return len;
}

static const struct xattr_handler nfs4_xattr_nfs4_label_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.list = nfs4_xattr_list_nfs4_label,
.get = nfs4_xattr_get_nfs4_label,
.set = nfs4_xattr_set_nfs4_label,
};
#endif


/*
* nfs_fhget will use either the mounted_on_fileid or the fileid
*/
Expand Down Expand Up @@ -7468,6 +7515,9 @@ static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {

const struct xattr_handler *nfs4_xattr_handlers[] = {
&nfs4_xattr_nfs4_acl_handler,
#ifdef CONFIG_NFS_V4_SECURITY_LABEL
&nfs4_xattr_nfs4_label_handler,
#endif
NULL
};

Expand Down
1 change: 1 addition & 0 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer
return 0;
return security_ops->inode_listsecurity(inode, buffer, buffer_size);
}
EXPORT_SYMBOL(security_inode_listsecurity);

void security_inode_getsecid(const struct inode *inode, u32 *secid)
{
Expand Down

0 comments on commit c9bccef

Please sign in to comment.