]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFSv4.2: fix listxattr to return selinux security label
authorOlga Kornievskaia <okorniev@redhat.com>
Fri, 25 Apr 2025 18:09:21 +0000 (14:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 6 Jul 2025 08:57:54 +0000 (10:57 +0200)
[ Upstream commit 243fea134633ba3d64aceb4c16129c59541ea2c6 ]

Currently, when NFS is queried for all the labels present on the
file via a command example "getfattr -d -m . /mnt/testfile", it
does not return the security label. Yet when asked specifically for
the label (getfattr -n security.selinux) it will be returned.
Include the security label when all attributes are queried.

Signed-off-by: Olga Kornievskaia <okorniev@redhat.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/nfs4proc.c

index 0f28607c57473a11739bef8aa930565b1ec5cc2e..2d94d1d7b0c629fb27b518e7e37346f4f49c36f6 100644 (file)
@@ -10630,7 +10630,7 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
-       ssize_t error, error2, error3;
+       ssize_t error, error2, error3, error4;
        size_t left = size;
 
        error = generic_listxattr(dentry, list, left);
@@ -10653,8 +10653,16 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
        error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
        if (error3 < 0)
                return error3;
+       if (list) {
+               list += error3;
+               left -= error3;
+       }
+
+       error4 = security_inode_listsecurity(d_inode(dentry), list, left);
+       if (error4 < 0)
+               return error4;
 
-       error += error2 + error3;
+       error += error2 + error3 + error4;
        if (size && error > size)
                return -ERANGE;
        return error;