Commit 5b2fad6f authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Kelsey Skunberg

nfs: Move call to security_inode_listsecurity into nfs_listxattr

BugLink: https://bugs.launchpad.net/bugs/1892822

[ Upstream commit c4803c49 ]

Add a nfs_listxattr operation.  Move the call to security_inode_listsecurity
from list operation of the "security.*" xattr handler to nfs_listxattr.
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Cc: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: Anna Schumaker <anna.schumaker@netapp.com>
Cc: linux-nfs@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent 3d0e0594
......@@ -6296,10 +6296,6 @@ static size_t nfs4_xattr_list_nfs4_acl(const struct xattr_handler *handler,
}
#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(const struct xattr_handler *handler,
struct dentry *dentry, const char *key,
......@@ -6321,29 +6317,34 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
return -EOPNOTSUPP;
}
static size_t nfs4_xattr_list_nfs4_label(const struct xattr_handler *handler,
struct dentry *dentry, char *list,
size_t list_len, const char *name,
size_t name_len)
static ssize_t
nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
{
size_t len = 0;
int len = 0;
if (nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) {
len = security_inode_listsecurity(d_inode(dentry), NULL, 0);
if (list && len <= list_len)
security_inode_listsecurity(d_inode(dentry), list, len);
if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
len = security_inode_listsecurity(inode, list, list_len);
if (list_len && len > list_len)
return -ERANGE;
}
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
#else
static ssize_t
nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
{
return 0;
}
#endif
/*
* nfs_fhget will use either the mounted_on_fileid or the fileid
......@@ -8773,6 +8774,24 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
#endif
};
ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
{
ssize_t error, error2;
error = generic_listxattr(dentry, list, size);
if (error < 0)
return error;
if (list) {
list += error;
size -= error;
}
error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size);
if (error2 < 0)
return error2;
return error + error2;
}
static const struct inode_operations nfs4_dir_inode_operations = {
.create = nfs_create,
.lookup = nfs_lookup,
......@@ -8789,7 +8808,7 @@ static const struct inode_operations nfs4_dir_inode_operations = {
.setattr = nfs_setattr,
.getxattr = generic_getxattr,
.setxattr = generic_setxattr,
.listxattr = generic_listxattr,
.listxattr = nfs4_listxattr,
.removexattr = generic_removexattr,
};
......@@ -8799,7 +8818,7 @@ static const struct inode_operations nfs4_file_inode_operations = {
.setattr = nfs_setattr,
.getxattr = generic_getxattr,
.setxattr = generic_setxattr,
.listxattr = generic_listxattr,
.listxattr = nfs4_listxattr,
.removexattr = generic_removexattr,
};
......
......@@ -749,6 +749,8 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
if (!buffer) {
for_each_xattr_handler(handlers, handler) {
if (!handler->list)
continue;
size += handler->list(handler, dentry, NULL, 0,
NULL, 0);
}
......@@ -756,6 +758,8 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
char *buf = buffer;
for_each_xattr_handler(handlers, handler) {
if (!handler->list)
continue;
size = handler->list(handler, dentry, buf, buffer_size,
NULL, 0);
if (size > buffer_size)
......
......@@ -1536,8 +1536,6 @@ static int smack_inode_getsecurity(const struct inode *inode,
* @inode: the object
* @buffer: where they go
* @buffer_size: size of buffer
*
* Returns 0 on success, -EINVAL otherwise
*/
static int smack_inode_listsecurity(struct inode *inode, char *buffer,
size_t buffer_size)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment