From: Paul Moore <paul.moore@hp.com>
To: selinux@tycho.nsa.gov
Subject: [PATCH 3/6] selinux: Consolidate sockcreate_sid logic
Date: Sat, 29 May 2010 17:53:37 -0400 [thread overview]
Message-ID: <20100529215337.4042.66498.stgit@flek.lan> (raw)
In-Reply-To: <20100529214628.4042.88276.stgit@flek.lan>
Consolidate the basic sockcreate_sid logic into a single helper function
which allows us to do some cleanups in the related code.
Signed-off-by: Paul Moore <paul.moore@hp.com>
---
security/selinux/hooks.c | 32 ++++++++++++--------------------
1 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index ead0984..a4a0660 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3712,6 +3712,12 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid)
}
/* socket security operations */
+
+static u32 socket_sockcreate_sid(const struct task_security_struct *tsec)
+{
+ return tsec->sockcreate_sid ? : tsec->sid;
+}
+
static int socket_has_perm(struct task_struct *task, struct socket *sock,
u32 perms)
{
@@ -3739,21 +3745,15 @@ static int selinux_socket_create(int family, int type,
{
const struct cred *cred = current_cred();
const struct task_security_struct *tsec = cred->security;
- u32 sid, newsid;
+ u32 newsid;
u16 secclass;
- int err = 0;
if (kern)
- goto out;
-
- sid = tsec->sid;
- newsid = tsec->sockcreate_sid ?: sid;
+ return 0;
+ newsid = socket_sockcreate_sid(tsec);
secclass = socket_type_to_security_class(family, type, protocol);
- err = avc_has_perm(sid, newsid, secclass, SOCKET__CREATE, NULL);
-
-out:
- return err;
+ return avc_has_perm(tsec->sid, newsid, secclass, SOCKET__CREATE, NULL);
}
static int selinux_socket_post_create(struct socket *sock, int family,
@@ -3761,22 +3761,14 @@ static int selinux_socket_post_create(struct socket *sock, int family,
{
const struct cred *cred = current_cred();
const struct task_security_struct *tsec = cred->security;
- struct inode_security_struct *isec;
+ struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
struct sk_security_struct *sksec;
- u32 sid, newsid;
int err = 0;
- sid = tsec->sid;
- newsid = tsec->sockcreate_sid;
-
- isec = SOCK_INODE(sock)->i_security;
-
if (kern)
isec->sid = SECINITSID_KERNEL;
- else if (newsid)
- isec->sid = newsid;
else
- isec->sid = sid;
+ isec->sid = socket_sockcreate_sid(tsec);
isec->sclass = socket_type_to_security_class(family, type, protocol);
isec->initialized = 1;
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2010-05-29 21:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-29 21:53 [PATCH 0/6] SELinux UNIX domain socket fixes/cleanup Paul Moore
2010-05-29 21:53 ` [PATCH 1/6] selinux: Update socket's label alongside inode's label Paul Moore
2010-05-29 21:53 ` [PATCH 2/6] selinux: Set the peer label correctly on connected UNIX domain sockets Paul Moore
2010-05-29 21:53 ` Paul Moore [this message]
2010-05-29 21:53 ` [PATCH 4/6] selinux: Shuffle the sk_security_struct alloc and free routines Paul Moore
2010-05-29 21:53 ` [PATCH 5/6] selinux: Convert socket related access controls to use socket labels Paul Moore
2010-05-29 21:53 ` [PATCH 6/6] selinux: Use current_security() when possible Paul Moore
2010-06-03 20:52 ` [PATCH 0/6] SELinux UNIX domain socket fixes/cleanup Paul Moore
2010-06-03 21:12 ` Eric Paris
2010-06-03 21:44 ` Paul Moore
2010-06-09 21:39 ` Paul Moore
2010-06-21 18:32 ` Paul Moore
2010-06-21 19:13 ` Paul Moore
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=20100529215337.4042.66498.stgit@flek.lan \
--to=paul.moore@hp.com \
--cc=selinux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.