mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Andrew Morgan <morgan@kernel.org>,
	Chris Wright <chrisw@sous-sol.org>,
	Andrew Morgan <agm@google.com>,
	casey@schaufler-ca.com, Andrew Morton <akpm@google.com>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	KaiGai Kohei <kaigai@kaigai.gr.jp>,
	James Morris <jmorris@namei.org>,
	linux-security-module@vger.kernel.org,
	lkml <linux-kernel@vger.kernel.org>
Cc: Steve Beattie <sbeattie@suse.de>
Subject: [PATCH 1/1] file capabilities: clear caps cleanup
Date: Wed, 11 Jul 2007 09:18:50 -0500	[thread overview]
Message-ID: <20070711141850.GA6690@sergelap.austin.ibm.com> (raw)

>From 88115394044e697ac852f7fb9f30483e87f4f598 Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue@us.ibm.com>
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().

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

diff --git a/security/commoncap.c b/security/commoncap.c
index cc50a61..b08d250 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -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
-- 
1.5.1.1.GIT


             reply	other threads:[~2007-07-11 14:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-11 14:18 Serge E. Hallyn [this message]
2007-07-11 14:39 ` James Morris
2007-07-11 16:12 ` Andrew Morgan
2007-07-11 21:46 ` Chris Wright

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070711141850.GA6690@sergelap.austin.ibm.com \
    --to=serue@us.ibm.com \
    --cc=agm@google.com \
    --cc=akpm@google.com \
    --cc=casey@schaufler-ca.com \
    --cc=chrisw@sous-sol.org \
    --cc=jmorris@namei.org \
    --cc=kaigai@kaigai.gr.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=morgan@kernel.org \
    --cc=sbeattie@suse.de \
    --cc=sds@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®