Skip to contentSkip to conversation

selinux,smack: remove the capability checks in the removexattr hooks

PATCH In review Paul Moore 2 participants 6 messages Jul 3, 2024 – Jul 5, 2024

Subsystems (3)
lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 selinux,smack: remove the capability checks in the removexattr hooks

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")
---
 security/selinux/hooks.c   | 10 ++--------
 security/smack/smack_lsm.c |  3 +--
 2 files changed, 3 insertions(+), 10 deletions(-)
security/selinux/hooks.c +2 -8
index 2daa0961b7f1..c41bf07d4b06 100644
@@ -3356,15 +3356,9 @@ static int selinux_inode_listxattr(struct dentry *dentry)
 static int selinux_inode_removexattr(struct mnt_idmap *idmap,
 				     struct dentry *dentry, const char *name)
 {
-	if (strcmp(name, XATTR_NAME_SELINUX)) {
-		int rc = cap_inode_removexattr(idmap, dentry, name);
-		if (rc)
-			return rc;
-
-		/* Not an attribute we recognize, so just check the
-		   ordinary setattr permission. */
+	/* if not a selinux xattr, only check the ordinary setattr perm */
+	if (strcmp(name, XATTR_NAME_SELINUX))
 		return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
-	}
 
 	if (!selinux_initialized())
 		return 0;
security/smack/smack_lsm.c +1 -2
index a19a94f27766..9f8a8ffb5dde 100644
@@ -1461,8 +1461,7 @@ static int smack_inode_removexattr(struct mnt_idmap *idmap,
 	    strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
 		if (!smack_privileged(CAP_MAC_ADMIN))
 			rc = -EPERM;
-	} else
-		rc = cap_inode_removexattr(idmap, dentry, name);
+	}
 
 	if (rc != 0)
 		return rc;
Signature · 1 line
2.45.2
author maintainer
#1 lore raw
Quoted 10 lines · Paul Moore

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

Quoted 8 lines

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")
---
 security/selinux/hooks.c   | 10 ++--------
 security/smack/smack_lsm.c |  3 +--
 2 files changed, 3 insertions(+), 10 deletions(-)

FYI, this is still untested as my test kernel is compiling now, but I wanted to get this out onto the list before the holiday in the US for folks (/me looks at Casey for the Smack bits) to look at and potentially review.

Signature · 1 line
paul-moore.com
maintainer
#2 lore raw
Quoted 18 lines · Paul Moore
Quoted 9 lines · Paul Moore

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

Quoted 8 lines

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")
---
 security/selinux/hooks.c   | 10 ++--------
 security/smack/smack_lsm.c |  3 +--
 2 files changed, 3 insertions(+), 10 deletions(-)
Quoted 3 lines

FYI, this is still untested as my test kernel is compiling now, but I wanted to get this out onto the list before the holiday in the US for folks (/me looks at Casey for the Smack bits)

Let me know how your test goes, and then I'll have a closer look.

Quoted 3 lines

to look at and
potentially review.

author maintainer
#3 lore raw
Quoted 19 lines · Casey Schaufler
Quoted 18 lines · Paul Moore
Quoted 17 lines · Paul Moore

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")
---
 security/selinux/hooks.c   | 10 ++--------
 security/smack/smack_lsm.c |  3 +--
 2 files changed, 3 insertions(+), 10 deletions(-)
Quoted 5 lines
Quoted 3 lines

FYI, this is still untested as my test kernel is compiling now, but I wanted to get this out onto the list before the holiday in the US for folks (/me looks at Casey for the Smack bits)

Let me know how your test goes, and then I'll have a closer look.

It looks good - my SELinux test system booted up, appears to be running normally, and all of the selinux-testsuite tests pass.

Signature · 1 line
paul-moore.com
maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Paul Moore
Quoted 9 lines · Paul Moore

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

Quoted 4 lines

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")
Quoted 41 lines
---
 security/selinux/hooks.c   | 10 ++--------
 security/smack/smack_lsm.c |  3 +--
 2 files changed, 3 insertions(+), 10 deletions(-)
security/selinux/hooks.c +2 -8
index 2daa0961b7f1..c41bf07d4b06 100644
@@ -3356,15 +3356,9 @@ static int selinux_inode_listxattr(struct dentry *dentry)
 static int selinux_inode_removexattr(struct mnt_idmap *idmap,
 				     struct dentry *dentry, const char *name)
 {
-	if (strcmp(name, XATTR_NAME_SELINUX)) {
-		int rc = cap_inode_removexattr(idmap, dentry, name);
-		if (rc)
-			return rc;
-
-		/* Not an attribute we recognize, so just check the
-		   ordinary setattr permission. */
+	/* if not a selinux xattr, only check the ordinary setattr perm */
+	if (strcmp(name, XATTR_NAME_SELINUX))
 		return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
-	}
 
 	if (!selinux_initialized())
 		return 0;
security/smack/smack_lsm.c +1 -2
index a19a94f27766..9f8a8ffb5dde 100644
@@ -1461,8 +1461,7 @@ static int smack_inode_removexattr(struct mnt_idmap *idmap,
 	    strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
 		if (!smack_privileged(CAP_MAC_ADMIN))
 			rc = -EPERM;
-	} else
-		rc = cap_inode_removexattr(idmap, dentry, name);
+	}
 
 	if (rc != 0)
 		return rc;
author maintainer
#5 lore raw
Quoted 10 lines · Casey Schaufler
Quoted 9 lines · Paul Moore

Commit 61df7b828204 ("lsm: fixup the inode xattr capability handling") moved the responsibility of doing the inode xattr capability checking out of the individual LSMs and into the LSM framework itself. Unfortunately, while the original commit added the capability checks to both the setxattr and removexattr code in the LSM framework, it only removed the setxattr capability checks from the individual LSMs, leaving duplicated removexattr capability checks in both the SELinux and Smack code.

Quoted 6 lines
Quoted 4 lines

This patch removes the duplicated code from SELinux and Smack.

Fixes 61df7b828204 ("lsm: fixup the inode xattr capability handling")

Thanks Casey. As this is a pretty minor fix, I'm going to go ahead and merge it into lsm/dev so it will go up to Linus during the next merge window; if anyone has any objections to that please let me know soon.

Signature · 1 line
paul-moore.com