Skip to contentSkip to conversation

file capabilities: clear caps cleanup

PATCH In review Serge E. Hallyn 4 participants 4 messages Jul 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 file capabilities: clear caps cleanup

Quoted 1 line

From 88115394044e697ac852f7fb9f30483e87f4f598 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Wed, 11 Jul 2007 10:01:01 -0400
Subject: [PATCH 1/1] file capabilities: clear caps cleanup

As suggested by Steve Beattie, rather than jump into a conditional block in certain cases, define and use a static inline bprm_clear_caps().

---
 security/commoncap.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)
security/commoncap.c +15 -11
index cc50a61..b08d250 100644
@@ -109,6 +109,13 @@ void cap_capset_set (struct task_struct *target, kernel_cap_t *effective,
 	target->cap_permitted = *permitted;
 }
 
+static inline void bprm_clear_caps(struct linux_binprm *bprm)
+{
+	cap_clear (bprm->cap_inheritable);
+	cap_clear (bprm->cap_permitted);
+	cap_clear (bprm->cap_effective);
+}
+
 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
 
 static inline int cap_from_disk(struct vfs_cap_data_disk *dcap,
@@ -144,8 +151,10 @@ static int get_file_caps(struct linux_binprm *bprm)
 	struct inode *inode;
 
 	dcaps = (struct vfs_cap_data_disk *)&v1caps;
-	if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
-		goto clear_caps;
+	if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) {
+		bprm_clear_caps(bprm);
+		return 0;
+	}
 
 	dentry = dget(bprm->file->f_dentry);
 	inode = dentry->d_inode;
@@ -186,21 +195,16 @@ out:
 	dput(dentry);
 	if ((void *)dcaps != (void *)&v1caps)
 		kfree(dcaps);
-	if (rc) {
-clear_caps:
-		cap_clear (bprm->cap_inheritable);
-		cap_clear (bprm->cap_permitted);
-		cap_clear (bprm->cap_effective);
-	}
+	if (rc)
+		bprm_clear_caps(bprm);
+
 	return rc;
 }
 
 #else
 static inline int get_file_caps(struct linux_binprm *bprm)
 {
-	cap_clear (bprm->cap_inheritable);
-	cap_clear (bprm->cap_permitted);
-	cap_clear (bprm->cap_effective);
+	bprm_clear_caps(bprm);
 	return 0;
 }
 #endif
Signature · 1 line
1.5.1.1.GIT
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Serge E. Hallyn
Quoted 1 line

From 88115394044e697ac852f7fb9f30483e87f4f598 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Wed, 11 Jul 2007 10:01:01 -0400
Subject: [PATCH 1/1] file capabilities: clear caps cleanup

As suggested by Steve Beattie, rather than jump into a conditional block in certain cases, define and use a static inline bprm_clear_caps().

Good idea.

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
In reply to Serge E. Hallyn

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fine with me.

Cheers

Andrew

Quoted 8 lines · Serge E. Hallyn
Quoted 1 line

From 88115394044e697ac852f7fb9f30483e87f4f598 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Wed, 11 Jul 2007 10:01:01 -0400
Subject: [PATCH 1/1] file capabilities: clear caps cleanup

As suggested by Steve Beattie, rather than jump into a conditional block in certain cases, define and use a static inline bprm_clear_caps().

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGlQF6+bHCR3gb8jsRArmZAJ9Je0Da0SDtg78tx5ks7gvY/E5x/wCfYikC bkD1uf7L3cdKzBMEvdjqB/c=
=/z3n
-----END PGP SIGNATURE-----

#3 lore raw
In reply to Serge E. Hallyn

security/commoncap.c void cap_capset_set (struct task_struct *target, kernel_cap_t *effective, · line 116

Quoted 5 lines
security/commoncap.c +5 -0
+static inline void bprm_clear_caps(struct linux_binprm *bprm)
+{
+	cap_clear (bprm->cap_inheritable);
+	cap_clear (bprm->cap_permitted);
+	cap_clear (bprm->cap_effective);

While there, can you clean that bit up a touch?

	cap_clear(bprm->cap_inheritable);
	cap_clear(bprm->cap_permitted);
	cap_clear(bprm->cap_effective);

thanks,
-chris