Skip to content

Commit fdc0396

Browse files
stephensmalleyAnna Schumaker
authored andcommitted
nfs: unify security_inode_listsecurity() calls
commit 243fea1 ("NFSv4.2: fix listxattr to return selinux security label") introduced a direct call to security_inode_listsecurity() in nfs4_listxattr(). However, nfs4_listxattr() already indirectly called security_inode_listsecurity() via nfs4_listxattr_nfs4_label() if CONFIG_NFS_V4_SECURITY_LABEL is enabled and the server has the NFS_CAP_SECURITY_LABEL capability enabled. This duplication was fixed by commit 9acb237 ("NFSv4.2: another fix for listxattr") by making the second call conditional on NFS_CAP_SECURITY_LABEL not being set by the server. However, the combination of the two changes effectively makes one call to security_inode_listsecurity() in every case - which is the desired behavior since getxattr() always returns a security xattr even if it has to synthesize one. Further, the two different calls produce different xattr name ordering between security.* and user.* xattr names. Unify the two separate calls into a single call and get rid of nfs4_listxattr_nfs4_label() altogether. Link: https://lore.kernel.org/selinux/CAEjxPJ6e8z__=MP5NfdUxkOMQ=EnUFSjWFofP4YPwHqK=Ki5nw@mail.gmail.com/ Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
1 parent 42e7c87 commit fdc0396

1 file changed

Lines changed: 3 additions & 35 deletions

File tree

fs/nfs/nfs4proc.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7888,33 +7888,12 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
78887888
return -EOPNOTSUPP;
78897889
}
78907890

7891-
static ssize_t
7892-
nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
7893-
{
7894-
int len = 0;
7895-
7896-
if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
7897-
len = security_inode_listsecurity(inode, list, list_len);
7898-
if (len >= 0 && list_len && len > list_len)
7899-
return -ERANGE;
7900-
}
7901-
return len;
7902-
}
7903-
79047891
static const struct xattr_handler nfs4_xattr_nfs4_label_handler = {
79057892
.prefix = XATTR_SECURITY_PREFIX,
79067893
.get = nfs4_xattr_get_nfs4_label,
79077894
.set = nfs4_xattr_set_nfs4_label,
79087895
};
79097896

7910-
#else
7911-
7912-
static ssize_t
7913-
nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
7914-
{
7915-
return 0;
7916-
}
7917-
79187897
#endif
79197898

79207899
#ifdef CONFIG_NFS_V4_2
@@ -10553,7 +10532,7 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
1055310532

1055410533
static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
1055510534
{
10556-
ssize_t error, error2, error3, error4 = 0;
10535+
ssize_t error, error2, error3;
1055710536
size_t left = size;
1055810537

1055910538
error = generic_listxattr(dentry, list, left);
@@ -10564,10 +10543,9 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
1056410543
left -= error;
1056510544
}
1056610545

10567-
error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, left);
10546+
error2 = security_inode_listsecurity(d_inode(dentry), list, left);
1056810547
if (error2 < 0)
1056910548
return error2;
10570-
1057110549
if (list) {
1057210550
list += error2;
1057310551
left -= error2;
@@ -10576,18 +10554,8 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
1057610554
error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
1057710555
if (error3 < 0)
1057810556
return error3;
10579-
if (list) {
10580-
list += error3;
10581-
left -= error3;
10582-
}
10583-
10584-
if (!nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) {
10585-
error4 = security_inode_listsecurity(d_inode(dentry), list, left);
10586-
if (error4 < 0)
10587-
return error4;
10588-
}
1058910557

10590-
error += error2 + error3 + error4;
10558+
error += error2 + error3;
1059110559
if (size && error > size)
1059210560
return -ERANGE;
1059310561
return error;

0 commit comments

Comments
 (0)