public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] file capabilities: get_file_caps cleanups
@ 2007-06-28  0:20 Serge E. Hallyn
  2007-06-28  6:10 ` Andrew Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Serge E. Hallyn @ 2007-06-28  0:20 UTC (permalink / raw)
  To: Andrew Morgan, Chris Wright, Andrew Morgan, casey, Andrew Morton,
	Stephen Smalley, KaiGai Kohei, James Morris,
	linux-security-module, lkml

>From 588755d9498c87c4e963527ba0f49c11107de354 Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue@us.ibm.com>
Date: Wed, 27 Jun 2007 19:55:27 -0400
Subject: [PATCH 1/1] file capabilities: get_file_caps cleanups

Two cleanups relating to set_file caps.

Rename set_file_caps to get_file_caps, since we are getting
the file capabilities, and setting the bprm caps to them.

Move the clearing of bprm caps into get_file_caps, and do it
only when we don't copy them from the capability xattr.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
 security/commoncap.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/security/commoncap.c b/security/commoncap.c
index 24de4fa..3e3d88c 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -135,21 +135,20 @@ static inline int cap_from_disk(struct vfs_cap_data_disk *dcap,
 }
 
 /* Locate any VFS capabilities: */
-static int set_file_caps(struct linux_binprm *bprm)
+static int get_file_caps(struct linux_binprm *bprm)
 {
 	struct dentry *dentry;
-	int rc;
+	int rc = 0;
 	struct vfs_cap_data_disk_v1 v1caps;
 	struct vfs_cap_data_disk *dcaps;
 	struct inode *inode;
 
 	dcaps = (struct vfs_cap_data_disk *)&v1caps;
 	if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
-		return 0;
+		goto clear_caps;
 
 	dentry = dget(bprm->file->f_dentry);
 	inode = dentry->d_inode;
-	rc = 0;
 	if (!inode->i_op || !inode->i_op->getxattr)
 		goto out;
 
@@ -187,12 +186,21 @@ out:
 	dput(dentry);
 	if ((void *)dcaps != (void *)&v1caps)
 		kfree(dcaps);
+clear_caps:
+	if (rc) {
+		cap_clear (bprm->cap_inheritable);
+		cap_clear (bprm->cap_permitted);
+		cap_clear (bprm->cap_effective);
+	}
 	return rc;
 }
 
 #else
-static inline int set_file_caps(struct linux_binprm *bprm)
+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);
 	return 0;
 }
 #endif
@@ -201,13 +209,7 @@ int cap_bprm_set_security (struct linux_binprm *bprm)
 {
 	int ret;
 
-	/* Copied from fs/exec.c:prepare_binprm. */
-
-	cap_clear (bprm->cap_inheritable);
-	cap_clear (bprm->cap_permitted);
-	cap_clear (bprm->cap_effective);
-
-	ret = set_file_caps(bprm);
+	ret = get_file_caps(bprm);
 
 	/*  To support inheritance of root-permissions and suid-root
 	 *  executables under compatibility mode, we raise all three
-- 
1.5.1.1.GIT


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] file capabilities: get_file_caps cleanups
  2007-06-28  0:20 [PATCH 1/1] file capabilities: get_file_caps cleanups Serge E. Hallyn
@ 2007-06-28  6:10 ` Andrew Morgan
  2007-06-28 13:47   ` Serge E. Hallyn
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morgan @ 2007-06-28  6:10 UTC (permalink / raw)
  To: Serge E. Hallyn
  Cc: Chris Wright, Andrew Morgan, casey, Andrew Morton,
	Stephen Smalley, KaiGai Kohei, James Morris,
	linux-security-module, lkml

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

This contains a typo:

Serge E. Hallyn wrote:
>>From 588755d9498c87c4e963527ba0f49c11107de354 Mon Sep 17 00:00:00 2001
> From: Serge E. Hallyn <serue@us.ibm.com>
> Date: Wed, 27 Jun 2007 19:55:27 -0400
> Subject: [PATCH 1/1] file capabilities: get_file_caps cleanups
> 
> Two cleanups relating to set_file caps.
[...]
> @@ -187,12 +186,21 @@ out:
>  	dput(dentry);
>  	if ((void *)dcaps != (void *)&v1caps)
>  		kfree(dcaps);
Move this two lines down (rc defaults to 0 in goto above):
from here-->
> +clear_caps:
> +	if (rc) {
to here-->
> +		cap_clear (bprm->cap_inheritable);
> +		cap_clear (bprm->cap_permitted);
> +		cap_clear (bprm->cap_effective);
> +	}
>  	return rc;

Cheers

Andrew

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFGg1DNQheEq9QabfIRApNqAJ99rNMF4VU/FPOolDLHlXbbQ2MRMwCeO3Fy
8ze7XhlBuBKdHElbZmWFJ5Y=
=gAEK
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] file capabilities: get_file_caps cleanups
  2007-06-28  6:10 ` Andrew Morgan
@ 2007-06-28 13:47   ` Serge E. Hallyn
  2007-06-28 16:27     ` Andrew Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Serge E. Hallyn @ 2007-06-28 13:47 UTC (permalink / raw)
  To: Andrew Morgan
  Cc: Serge E. Hallyn, Chris Wright, Andrew Morgan, casey,
	Andrew Morton, Stephen Smalley, KaiGai Kohei, James Morris,
	linux-security-module, lkml

Quoting Andrew Morgan (morgan@kernel.org):
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> This contains a typo:
> 
> Serge E. Hallyn wrote:
> >>From 588755d9498c87c4e963527ba0f49c11107de354 Mon Sep 17 00:00:00 2001
> > From: Serge E. Hallyn <serue@us.ibm.com>
> > Date: Wed, 27 Jun 2007 19:55:27 -0400
> > Subject: [PATCH 1/1] file capabilities: get_file_caps cleanups
> > 
> > Two cleanups relating to set_file caps.
> [...]
> > @@ -187,12 +186,21 @@ out:
> >  	dput(dentry);
> >  	if ((void *)dcaps != (void *)&v1caps)
> >  		kfree(dcaps);
> Move this two lines down (rc defaults to 0 in goto above):
> from here-->
> > +clear_caps:
> > +	if (rc) {
> to here-->

Hmm?  But if we succeeded we still want to free dcaps if we
kmalloc()'d it.

If we didn't kmalloc it, dcaps==v1caps and it won't be freed.

thanks,
-serge

> > +		cap_clear (bprm->cap_inheritable);
> > +		cap_clear (bprm->cap_permitted);
> > +		cap_clear (bprm->cap_effective);
> > +	}
> >  	return rc;
> 
> Cheers
> 
> Andrew
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.6 (GNU/Linux)
> 
> iD8DBQFGg1DNQheEq9QabfIRApNqAJ99rNMF4VU/FPOolDLHlXbbQ2MRMwCeO3Fy
> 8ze7XhlBuBKdHElbZmWFJ5Y=
> =gAEK
> -----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] file capabilities: get_file_caps cleanups
  2007-06-28 13:47   ` Serge E. Hallyn
@ 2007-06-28 16:27     ` Andrew Morgan
  2007-06-28 16:49       ` Serge E. Hallyn
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morgan @ 2007-06-28 16:27 UTC (permalink / raw)
  To: Serge E. Hallyn
  Cc: Chris Wright, Andrew Morgan, casey, Andrew Morton,
	Stephen Smalley, KaiGai Kohei, James Morris,
	linux-security-module, lkml

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

Serge E. Hallyn wrote:
>>>>  		kfree(dcaps);
> Move this two lines down (rc defaults to 0 in goto above):
> from here-->
>>>> +clear_caps:
>>>> +	if (rc) {
> to here-->
> 
>> Hmm?  But if we succeeded we still want to free dcaps if we
>> kmalloc()'d it.

I wasn't clear enough... Let me try again with different words.

If you look at your patch, you will see that the only use of the label
'clear_caps:' is as a jump target from a location in which rc=0. As
such, you will *not* clear the bprm->cap_* sets... This is the reverse
of what you intended to do.

You need to put the jump target 'inside' the 'if (rc) { <-here ... }'.

Cheers

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

iD8DBQFGg+F6+bHCR3gb8jsRAm2AAJ9v0fz/S/+HvGWOhU6UBPbB4iY+MACggZqA
+yCrxg2UVKdDKOh6kPfh0QI=
=Qksf
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] file capabilities: get_file_caps cleanups
  2007-06-28 16:27     ` Andrew Morgan
@ 2007-06-28 16:49       ` Serge E. Hallyn
  0 siblings, 0 replies; 5+ messages in thread
From: Serge E. Hallyn @ 2007-06-28 16:49 UTC (permalink / raw)
  To: Andrew Morgan
  Cc: Serge E. Hallyn, Chris Wright, Andrew Morgan, casey,
	Andrew Morton, Stephen Smalley, KaiGai Kohei, James Morris,
	linux-security-module, lkml

Quoting Andrew Morgan (morgan@kernel.org):
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Serge E. Hallyn wrote:
> >>>>  		kfree(dcaps);
> > Move this two lines down (rc defaults to 0 in goto above):
> > from here-->
> >>>> +clear_caps:
> >>>> +	if (rc) {
> > to here-->
> > 
> >> Hmm?  But if we succeeded we still want to free dcaps if we
> >> kmalloc()'d it.
> 
> I wasn't clear enough... Let me try again with different words.
> 
> If you look at your patch, you will see that the only use of the label
> 'clear_caps:' is as a jump target from a location in which rc=0. As
> such, you will *not* clear the bprm->cap_* sets... This is the reverse
> of what you intended to do.
> 
> You need to put the jump target 'inside' the 'if (rc) { <-here ... }'.

Oops!  Good catch, thanks.  New patch follows:

>From 9e8d4dd0486c85e269a062a4637a8b6296fcb80b Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue@us.ibm.com>
Date: Wed, 27 Jun 2007 19:55:27 -0400
Subject: [PATCH 1/1] file capabilities: get_file_caps cleanups

Two cleanups relating to set_file caps.

Rename set_file_caps to get_file_caps, since we are getting
the file capabilities, and setting the bprm caps to them.

Move the clearing of bprm caps into get_file_caps, and do it
only when we don't copy them from the capability xattr.

Changelog:
	Fix location of 'clear_caps' label.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
 security/commoncap.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/security/commoncap.c b/security/commoncap.c
index 24de4fa..cc50a61 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -135,21 +135,20 @@ static inline int cap_from_disk(struct vfs_cap_data_disk *dcap,
 }
 
 /* Locate any VFS capabilities: */
-static int set_file_caps(struct linux_binprm *bprm)
+static int get_file_caps(struct linux_binprm *bprm)
 {
 	struct dentry *dentry;
-	int rc;
+	int rc = 0;
 	struct vfs_cap_data_disk_v1 v1caps;
 	struct vfs_cap_data_disk *dcaps;
 	struct inode *inode;
 
 	dcaps = (struct vfs_cap_data_disk *)&v1caps;
 	if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
-		return 0;
+		goto clear_caps;
 
 	dentry = dget(bprm->file->f_dentry);
 	inode = dentry->d_inode;
-	rc = 0;
 	if (!inode->i_op || !inode->i_op->getxattr)
 		goto out;
 
@@ -187,12 +186,21 @@ 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);
+	}
 	return rc;
 }
 
 #else
-static inline int set_file_caps(struct linux_binprm *bprm)
+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);
 	return 0;
 }
 #endif
@@ -201,13 +209,7 @@ int cap_bprm_set_security (struct linux_binprm *bprm)
 {
 	int ret;
 
-	/* Copied from fs/exec.c:prepare_binprm. */
-
-	cap_clear (bprm->cap_inheritable);
-	cap_clear (bprm->cap_permitted);
-	cap_clear (bprm->cap_effective);
-
-	ret = set_file_caps(bprm);
+	ret = get_file_caps(bprm);
 
 	/*  To support inheritance of root-permissions and suid-root
 	 *  executables under compatibility mode, we raise all three
-- 
1.5.1.1.GIT


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-06-28 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-28  0:20 [PATCH 1/1] file capabilities: get_file_caps cleanups Serge E. Hallyn
2007-06-28  6:10 ` Andrew Morgan
2007-06-28 13:47   ` Serge E. Hallyn
2007-06-28 16:27     ` Andrew Morgan
2007-06-28 16:49       ` Serge E. Hallyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox