Skip to contentSkip to conversation

security: commoncap: clarify CAP_FS_SET comment in cap_task_fix_setuid()

PATCH Superseded Adriano Cordova 3 participants 3 messages Sep 19 – Sep 20

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: commoncap: clarify CAP_FS_SET comment in cap_task_fix_setuid()

CAP_FS_SET is defined as exactly the capabilities an fsuid of 0 historically granted (see CAP_FS_MASK in include/linux/capability.h), so dropping it when fsuid leaves 0 is correct by construction, not "too harsh". Replace the stale FIXME with this explanation.

---
 security/commoncap.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
security/commoncap.c +6 -4
index 3399535808fe..e0a2f386c556 100644
@@ -1169,11 +1169,13 @@ int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
 		break;
 
 	case LSM_SETID_FS:
-		/* juggle the capabilities to follow FSUID changes, unless
-		 * otherwise suppressed
+		/* Juggle the capabilities to follow FSUID changes, unless
+		 * otherwise suppressed.
 		 *
-		 * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
-		 *          if not, we might be a bit too harsh here.
+		 * CAP_FS_SET is exactly the set of capabilities that an
+		 * fsuid of 0 historically granted (see CAP_FS_MASK in
+		 * <linux/capability.h>), so dropping that set when fsuid
+		 * leaves 0 is intentional rather than too harsh.
 		 */
 		if (!issecure(SECURE_NO_SETUID_FIXUP)) {
 			kuid_t root_uid = make_kuid(old->user_ns, 0);
Signature · 1 line
2.51.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

CAP_FS_SET is defined as exactly the capabilities an fsuid of 0 historically granted (see CAP_FS_MASK in include/linux/capability.h), so dropping it when fsuid leaves 0 is correct by construction, not "too harsh". Replace the stale FIXME with this explanation.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Adriano Cordova
Quoted 6 lines · Adriano Cordova

CAP_FS_SET is defined as exactly the capabilities an fsuid of 0 historically granted (see CAP_FS_MASK in include/linux/capability.h), so dropping it when fsuid leaves 0 is correct by construction, not "too harsh". Replace the stale FIXME with this explanation.

Thanks, but,

Quoted 13 lines
---
 security/commoncap.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
security/commoncap.c +0 -1
index 3399535808fe..e0a2f386c556 100644
@@ -1169,11 +1169,13 @@ int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
 		break;
 
 	case LSM_SETID_FS:
-		/* juggle the capabilities to follow FSUID changes, unless

security/commoncap.c int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags) · line 1178

Quoted 10 lines
security/commoncap.c +6 -3
-		 * otherwise suppressed
+		/* Juggle the capabilities to follow FSUID changes, unless
+		 * otherwise suppressed.
 		 *
-		 * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
-		 *          if not, we might be a bit too harsh here.
+		 * CAP_FS_SET is exactly the set of capabilities that an
+		 * fsuid of 0 historically granted (see CAP_FS_MASK in
+		 * <linux/capability.h>), so dropping that set when fsuid
+		 * leaves 0 is intentional rather than too harsh.

"rather than too harsh" seems like arguing against the past comment. Just make it something like:

+ * CAP_FS_SET is exactly the set of capabilities that an
+ * fsuid of 0 historically granted (see CAP_FS_MASK in
+ * <linux/capability.h>), so we drop that set when fsuid
+ * leaves 0.

or

+ /* Juggle the capabilities to follow FSUID changes, unless
+ * otherwise suppressed. We drop the CAP_FS_SET when uid leaves
+ * 0, since that is the set of capabilities that an fsuid of 0
+ * historically granted.

or even shorter.

Quoted 5 lines
security/commoncap.c +0 -0
 		 */
 		if (!issecure(SECURE_NO_SETUID_FIXUP)) {
 			kuid_t root_uid = make_kuid(old->user_ns, 0);
Signature · 1 line
2.51.0