From: Darrel Goeddel <dgoeddel@TrustedCS.com>
To: Stephen Smalley <sds@epoch.ncsc.mil>
Cc: "selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>,
Chad Hanson <chanson@tcs-sec.com>
Subject: Re: dynamic context transitions
Date: Mon, 29 Nov 2004 08:54:51 -0600 [thread overview]
Message-ID: <41AB383B.3020006@trustedcs.com> (raw)
In-Reply-To: <1101310307.22014.148.camel@moss-spartans.epoch.ncsc.mil>
[-- Attachment #1: Type: text/plain, Size: 614 bytes --]
Stephen Smalley wrote:
> Yes, please make that change and confirm via testing that it properly
> blocks attempts by multi-threaded processes to set their current
> context.
>
The new patch is attached. I also made a change to the general_domain_access
macro to not grant setcurrent to self - a separate can_setcon macro has been
added to grant this. Dynamic transitions are denied for a multi-threaded
process (with more than one "kernel thread"). A process can switch its context
before spawning other threads and after all other threads have exited, but not
while any other threads exist.
--
Darrel
[-- Attachment #2: setcurrentcon_new.patch --]
[-- Type: text/plain, Size: 9032 bytes --]
Index: linux-2.6/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/linux-2.6/security/selinux/hooks.c,v
retrieving revision 1.23
diff -u -r1.23 hooks.c
--- linux-2.6/security/selinux/hooks.c 23 Nov 2004 17:42:43 -0000 1.23
+++ linux-2.6/security/selinux/hooks.c 27 Nov 2004 18:45:21 -0000
@@ -4107,10 +4107,9 @@
u32 sid = 0;
int error;
- if (current != p || !strcmp(name, "current")) {
+ if (current != p) {
/* SELinux only allows a process to change its own
- security attributes, and it only allows the process
- current SID to change via exec. */
+ security attributes. */
return -EACCES;
}
@@ -4123,6 +4122,8 @@
error = task_has_perm(current, p, PROCESS__SETEXEC);
else if (!strcmp(name, "fscreate"))
error = task_has_perm(current, p, PROCESS__SETFSCREATE);
+ else if (!strcmp(name, "current"))
+ error = task_has_perm(current, p, PROCESS__SETCURRENT);
else
error = -EINVAL;
if (error)
@@ -4147,6 +4148,22 @@
tsec->exec_sid = sid;
else if (!strcmp(name, "fscreate"))
tsec->create_sid = sid;
+ else if (!strcmp(name, "current")) {
+ if (sid == 0)
+ return -EINVAL;
+
+ /* Only allow single threaded processes to change context */
+ if (!thread_group_empty(p))
+ return -EPERM;
+
+ /* Check permissions for the transition. */
+ error = avc_has_perm(tsec->sid, sid, SECCLASS_PROCESS,
+ PROCESS__DYNTRANSITION, NULL);
+ if (error)
+ return error;
+
+ tsec->sid = sid;
+ }
else
return -EINVAL;
Index: linux-2.6/security/selinux/ss/services.c
===================================================================
RCS file: /cvsroot/selinux/nsa/linux-2.6/security/selinux/ss/services.c,v
retrieving revision 1.12
diff -u -r1.12 services.c
--- linux-2.6/security/selinux/ss/services.c 23 Nov 2004 17:42:45 -0000 1.12
+++ linux-2.6/security/selinux/ss/services.c 27 Nov 2004 18:45:22 -0000
@@ -275,7 +275,7 @@
* pair.
*/
if (tclass == SECCLASS_PROCESS &&
- (avd->allowed & PROCESS__TRANSITION) &&
+ (avd->allowed & (PROCESS__TRANSITION | PROCESS__DYNTRANSITION)) &&
scontext->role != tcontext->role) {
for (ra = policydb.role_allow; ra; ra = ra->next) {
if (scontext->role == ra->role &&
@@ -283,7 +283,8 @@
break;
}
if (!ra)
- avd->allowed = (avd->allowed) & ~(PROCESS__TRANSITION);
+ avd->allowed = (avd->allowed) & ~(PROCESS__TRANSITION |
+ PROCESS__DYNTRANSITION);
}
return 0;
Index: selinux-usr/policy/assert.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/assert.te,v
retrieving revision 1.15
diff -u -r1.15 assert.te
--- selinux-usr/policy/assert.te 19 Nov 2004 19:25:12 -0000 1.15
+++ selinux-usr/policy/assert.te 27 Nov 2004 18:45:22 -0000
@@ -24,7 +24,7 @@
# Verify that every type that can be entered by
# a domain is also tagged as a domain.
#
-neverallow domain ~domain:process transition;
+neverallow domain ~domain:process { transition dyntransition };
#
# Verify that only the insmod_t and kernel_t domains
Index: selinux-usr/policy/constraints
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/constraints,v
retrieving revision 1.7
diff -u -r1.7 constraints
--- selinux-usr/policy/constraints 8 Jul 2004 13:59:01 -0000 1.7
+++ selinux-usr/policy/constraints 27 Nov 2004 18:45:23 -0000
@@ -53,6 +53,9 @@
or (t1 == priv_system_role and r2 == system_r )
);
+constrain process dyntransition
+ ( u1 == u2 and r1 == r2);
+
#
# Restrict the ability to label objects with other
# user identities to a few privileged types.
Index: selinux-usr/policy/flask/access_vectors
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/flask/access_vectors,v
retrieving revision 1.12
diff -u -r1.12 access_vectors
--- selinux-usr/policy/flask/access_vectors 9 Sep 2004 12:14:39 -0000 1.12
+++ selinux-usr/policy/flask/access_vectors 27 Nov 2004 18:45:23 -0000
@@ -240,6 +240,8 @@
siginh
setrlimit
rlimitinh
+ dyntransition
+ setcurrent
}
Index: selinux-usr/policy/macros/core_macros.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/macros/core_macros.te,v
retrieving revision 1.23
diff -u -r1.23 core_macros.te
--- selinux-usr/policy/macros/core_macros.te 23 Nov 2004 20:56:07 -0000 1.23
+++ selinux-usr/policy/macros/core_macros.te 27 Nov 2004 18:45:24 -0000
@@ -627,9 +627,9 @@
#
define(`general_domain_access',`
# Access other processes in the same domain.
-# Omits ptrace, setexec, and setfscreate. These must be granted
+# Omits ptrace, setcurrent, setexec, and setfscreate. These must be granted
# separately if desired.
-allow $1 self:process ~{ptrace setexec setfscreate setrlimit};
+allow $1 self:process ~{ptrace setcurrent setexec setfscreate setrlimit};
# Access /proc/PID files for processes in the same domain.
allow $1 self:dir r_dir_perms;
Index: selinux-usr/policy/macros/global_macros.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/macros/global_macros.te,v
retrieving revision 1.48
diff -u -r1.48 global_macros.te
--- selinux-usr/policy/macros/global_macros.te 24 Nov 2004 19:44:37 -0000 1.48
+++ selinux-usr/policy/macros/global_macros.te 27 Nov 2004 18:45:25 -0000
@@ -42,6 +42,21 @@
')
##################################
+#
+# can_setcon(domain)
+#
+# Authorize a domain to set its current context
+# (via /proc/pid/attr/current).
+#
+define(`can_setcon',`
+allow $1 self:process setcurrent;
+allow $1 proc_t:dir search;
+allow $1 proc_t:{ file lnk_file } read;
+allow $1 self:dir search;
+allow $1 self:file { getattr read write };
+')
+
+##################################
# read_sysctl(domain)
#
# Permissions for reading sysctl variables.
@@ -525,7 +540,7 @@
allow $1 domain:fifo_file rw_file_perms;
# Act upon any other process.
-allow $1 domain:process ~transition;
+allow $1 domain:process ~{ transition dyntransition };
# Transition to myself, to make get_ordered_context_list happy.
allow $1 self:process transition;
Index: selinux-usr/policy/targeted/assert.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/targeted/assert.te,v
retrieving revision 1.1
diff -u -r1.1 assert.te
--- selinux-usr/policy/targeted/assert.te 12 May 2004 12:56:51 -0000 1.1
+++ selinux-usr/policy/targeted/assert.te 27 Nov 2004 18:45:25 -0000
@@ -31,7 +31,7 @@
# Verify that every type that can be entered by
# a domain is also tagged as a domain.
#
-neverallow domain ~domain:process transition;
+neverallow domain ~domain:process { transition dyntransition};
# for gross mistakes in policy
neverallow domain domain:dir ~r_dir_perms;
Index: selinux-usr/policy/targeted/constraints
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/targeted/constraints,v
retrieving revision 1.1
diff -u -r1.1 constraints
--- selinux-usr/policy/targeted/constraints 12 May 2004 12:56:51 -0000 1.1
+++ selinux-usr/policy/targeted/constraints 27 Nov 2004 18:45:25 -0000
@@ -39,6 +39,9 @@
constrain process transition
( r1 == r2 or t1 == privrole );
+constrain process dyntransition
+ ( u1 == u2 and r1 == r2);
+
#
# Restrict the ability to label objects with other
# user identities to a few privileged types.
Index: selinux-usr/libselinux/include/selinux/selinux.h
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/libselinux/include/selinux/selinux.h,v
retrieving revision 1.20
diff -u -r1.20 selinux.h
--- selinux-usr/libselinux/include/selinux/selinux.h 14 Oct 2004 20:04:05 -0000 1.20
+++ selinux-usr/libselinux/include/selinux/selinux.h 27 Nov 2004 18:45:26 -0000
@@ -23,6 +23,9 @@
Caller must free via freecon. */
extern int getcon(security_context_t *con);
+/* Set current security context */
+extern int setcon(security_context_t con);
+
/* Get context of process identified by pid, and
set *con to refer to it. Caller must free via freecon. */
extern int getpidcon(pid_t pid, security_context_t *con);
--- /dev/null 2003-09-15 08:40:47.000000000 -0500
+++ selinux-usr/libselinux/src/setcon.c 2004-10-28 10:48:14.000000000 -0500
@@ -0,0 +1,27 @@
+/*
+ * Author: Trusted Computer Solutions, Inc. <chanson@trustedcs.com>
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <selinux/selinux.h>
+
+int setcon(security_context_t context)
+{
+ int fd;
+ ssize_t ret;
+
+ fd = open("/proc/self/attr/current", O_RDWR);
+ if (fd < 0)
+ return -1;
+ if (context)
+ ret = write(fd, context, strlen(context)+1);
+ else
+ ret = -1; /* we can not clear this one */
+ close(fd);
+ if (ret < 0)
+ return -1;
+ else
+ return 0;
+}
next prev parent reply other threads:[~2004-11-29 14:54 UTC|newest]
Thread overview: 138+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-29 19:10 dynamic context transitions Darrel Goeddel
2004-10-29 21:18 ` Luke Kenneth Casson Leighton
2004-10-30 9:06 ` Luke Kenneth Casson Leighton
2004-11-01 13:20 ` Stephen Smalley
2004-11-01 14:10 ` Luke Kenneth Casson Leighton
2004-11-01 16:23 ` Darrel Goeddel
2004-11-01 16:39 ` Stephen Smalley
2004-11-01 18:45 ` Luke Kenneth Casson Leighton
2004-11-01 20:10 ` James Morris
2004-11-01 20:35 ` Luke Kenneth Casson Leighton
2004-11-01 20:25 ` Stephen Smalley
2004-11-01 21:00 ` Luke Kenneth Casson Leighton
2004-11-01 20:50 ` Stephen Smalley
2004-11-01 22:21 ` Luke Kenneth Casson Leighton
2004-11-08 14:42 ` Russell Coker
[not found] ` <1100395104.13794.12.camel@piglett.bartlett.house>
2004-11-14 11:15 ` Luke Kenneth Casson Leighton
[not found] ` <1100431351.13794.510.camel@piglett.bartlett.house>
[not found] ` <20041114162453.GN5031@lkcl.net>
[not found] ` <1100449615.30740.14.camel@localhost.localdomain>
2004-11-14 21:54 ` Luke Kenneth Casson Leighton
[not found] ` <20041201231224.GD5862@Favog.ubiqx.mn.org>
2004-12-02 1:46 ` Russell Coker
2004-11-08 14:39 ` Russell Coker
[not found] ` <20041203211212.GA5243@lkcl.net>
[not found] ` <16817.7759.874421.597181@samba.org>
2004-12-04 11:39 ` Russell Coker
2004-11-01 21:27 ` Karl MacMillan
2004-11-01 22:33 ` Luke Kenneth Casson Leighton
2004-11-02 0:25 ` Karl MacMillan
2004-11-02 13:43 ` Stephen Smalley
2004-11-02 14:16 ` Karl MacMillan
2004-11-02 14:19 ` Stephen Smalley
2004-11-03 20:21 ` Colin Walters
2004-11-25 19:48 ` Russell Coker
2004-11-25 21:35 ` Luke Kenneth Casson Leighton
2004-11-26 3:28 ` Russell Coker
2004-11-26 19:23 ` Valdis.Kletnieks
2004-11-26 18:58 ` Valdis.Kletnieks
2004-11-02 2:18 ` Colin Walters
2004-11-02 9:08 ` Luke Kenneth Casson Leighton
2004-11-02 13:59 ` Stephen Smalley
2004-11-02 14:59 ` Colin Walters
2004-11-01 16:45 ` Colin Walters
2004-11-01 18:23 ` Luke Kenneth Casson Leighton
2004-10-30 2:41 ` James Morris
2004-10-31 22:47 ` Frank Mayer
2004-11-01 13:37 ` Stephen Smalley
2004-11-02 1:03 ` Karl MacMillan
2004-11-02 15:33 ` Stephen Smalley
2004-11-02 17:39 ` Karl MacMillan
2004-11-02 18:02 ` Stephen Smalley
2004-11-02 21:33 ` Karl MacMillan
2004-11-03 13:53 ` Stephen Smalley
2004-11-03 15:08 ` Karl MacMillan
2004-11-25 20:12 ` Russell Coker
2004-11-03 17:53 ` Luke Kenneth Casson Leighton
2004-11-03 18:27 ` Luke Kenneth Casson Leighton
2004-11-01 15:51 ` Stephen Smalley
2004-11-01 16:56 ` Stephen Smalley
2004-11-01 21:44 ` Karl MacMillan
2004-11-12 18:42 ` Amy L Herzog
2004-11-15 14:07 ` Stephen Smalley
2004-11-19 13:48 ` Joshua D. Guttman
2004-11-19 14:33 ` Stephen Smalley
2004-11-19 16:29 ` Darrel Goeddel
2004-11-19 17:17 ` Stephen Smalley
2004-11-24 15:30 ` Darrel Goeddel
2004-11-24 15:31 ` Stephen Smalley
2004-11-29 14:54 ` Darrel Goeddel [this message]
2004-11-29 21:24 ` Stephen Smalley
2004-11-29 23:41 ` Darrel Goeddel
2004-11-30 12:58 ` Stephen Smalley
2004-11-30 15:14 ` Darrel Goeddel
2004-11-30 16:02 ` Stephen Smalley
2004-11-30 18:27 ` Stephen Smalley
2004-11-30 21:00 ` Stephen Smalley
2004-11-12 18:24 ` Stephen Smalley
2004-11-12 20:58 ` Valdis.Kletnieks
-- strict thread matches above, loose matches on Subject: below --
2004-11-01 14:11 Chad Hanson
2004-11-01 17:14 Chad Hanson
2004-11-01 20:04 ` Frank Mayer
2004-11-01 20:28 ` Stephen Smalley
2004-11-01 18:28 Chad Hanson
2004-11-01 20:47 ` Luke Kenneth Casson Leighton
2004-11-01 20:55 ` Stephen Smalley
2004-11-01 22:58 ` Luke Kenneth Casson Leighton
2004-11-02 13:47 ` Stephen Smalley
2004-11-02 14:06 ` Frank Mayer
2004-11-02 14:22 ` Stephen Smalley
2004-11-02 14:36 ` Frank Mayer
2004-11-03 18:47 ` Luke Kenneth Casson Leighton
2004-11-02 14:13 ` Frank Mayer
2004-11-03 15:38 ` Luke Kenneth Casson Leighton
2004-11-02 19:30 ` Valdis.Kletnieks
2004-11-03 15:55 ` Luke Kenneth Casson Leighton
2004-11-03 16:03 ` Stephen Smalley
2004-11-01 21:33 Chad Hanson
2004-11-02 13:31 ` Frank Mayer
2004-11-23 5:53 ` Russell Coker
2004-11-01 21:45 Chad Hanson
2004-11-02 15:25 Chad Hanson
2004-11-02 18:49 Chad Hanson
2004-11-02 21:34 ` Stephen Smalley
2004-11-02 22:06 ` Karl MacMillan
2004-11-03 15:36 Chad Hanson
2004-11-03 15:46 ` Karl MacMillan
2004-11-03 17:26 ` Luke Kenneth Casson Leighton
2004-11-04 16:50 ` Stephen Smalley
2004-11-04 17:25 ` Luke Kenneth Casson Leighton
2004-11-04 19:46 ` James Morris
2004-11-05 5:31 ` Colin Walters
2004-11-05 12:49 ` Stephen Smalley
2004-11-05 13:01 ` Frank Mayer
2004-11-05 13:13 ` Stephen Smalley
2004-11-05 15:55 ` Frank Mayer
2004-11-05 16:33 ` Luke Kenneth Casson Leighton
2004-11-05 16:41 ` Stephen Smalley
2004-11-05 17:07 ` Frank Mayer
2004-11-05 17:48 ` Stephen Smalley
2004-11-05 16:01 ` Colin Walters
2004-11-05 12:52 ` Frank Mayer
2004-11-05 13:11 ` Stephen Smalley
2004-11-05 15:04 ` Darrel Goeddel
2004-11-05 15:20 ` Stephen Smalley
2004-11-05 15:33 ` Karl MacMillan
2004-11-05 15:35 ` Stephen Smalley
2004-11-05 15:34 ` Darrel Goeddel
2004-11-05 16:01 ` Frank Mayer
2004-11-05 16:29 ` Luke Kenneth Casson Leighton
2004-11-05 16:44 ` Stephen Smalley
2004-11-03 18:00 Chad Hanson
2004-11-14 20:23 Luke Kenneth Casson Leighton
2004-11-15 13:25 ` Stephen Smalley
2004-11-15 14:34 ` Luke Kenneth Casson Leighton
2004-11-15 14:52 ` Stephen Smalley
2004-11-15 1:57 Luke Kenneth Casson Leighton
2004-11-15 13:29 ` Stephen Smalley
2005-02-15 21:34 Luke Kenneth Casson Leighton
2005-02-15 22:21 ` Darrel Goeddel
2005-02-15 22:56 ` Luke Kenneth Casson Leighton
2005-02-16 13:05 ` Stephen Smalley
2005-02-16 14:08 ` Luke Kenneth Casson Leighton
2005-02-16 14:00 ` Stephen Smalley
2005-02-16 15:19 ` Luke Kenneth Casson Leighton
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=41AB383B.3020006@trustedcs.com \
--to=dgoeddel@trustedcs.com \
--cc=chanson@tcs-sec.com \
--cc=sds@epoch.ncsc.mil \
--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.