Skip to contentSkip to conversation

NFSv4.2: fix listxattr to return selinux security label

PATCH New Olga Kornievskaia 1 participant 1 message Apr 25, 2025

Subsystems (2)
lore
Share & tools
lore

Olga Kornievskaia

author reviewer
#0 lore raw

PATCH 1/1 NFSv4.2: fix listxattr to return selinux security label

Currently, when NFS is quired 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.

---
 fs/nfs/nfs4proc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +10 -2
index 1f7cc260b007..5f7f5fed6f0e 100644
@@ -10845,7 +10845,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);
@@ -10868,8 +10868,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;
Signature · 1 line
2.47.1