All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darrel Goeddel <dgoeddel@TrustedCS.com>
To: "selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>
Cc: Stephen Smalley <sds@epoch.ncsc.mil>,
	Chad Hanson <chanson@TrustedCS.com>
Subject: dynamic context transitions
Date: Fri, 29 Oct 2004 14:10:19 -0500	[thread overview]
Message-ID: <4182959B.4080503@trustedcs.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 4435 bytes --]

Hello all,

	We would like to propose adding support for a trusted process to
alter its security context dynamically in order to support privilege
bracketing within an application.  We are aware that this idea has been
discussed in the past on the list and entirely understand the concerns
about non-tranquility, but we feel that this feature, and its
implementation, have considerable merit and can be provided with
appropriate controls to mitigate the risks.

       The motivator behind this proposal is to provide a mechanism for a
trusted application (one written to leverage the security policy) to be
able to remove unnecessary privileges when they are no longer needed, as
well as temporarily raise the privilege level to perform certain
operations and then return to a less privileged level.  By privilege
level, we are referring to access to other types/domains and access to
security classes such as system, passwd, and capability.  The former
provides enhanced security for applications/daemons which need access to
many things to initialize, but can then run with much less access to the
system.  The latter method of privilege bracketing helps code audits of
large applications by identifying critical regions of code that require
more privileges to run.

	A goal of SELinux and trusted application programming is to
create smaller programs which can be secured and audited. However, there
are and will continue to be applications which don't fall into this
framework. For these applications, a privilege bracketing approach
provides a more granular security framework than what currently exists
from SELinux today at process level.

	The MLS model is another reason for this functionality. We have
chosen to create MLS policy overrides using a new SELinux MLS capability
class. Trusted MLS applications may require a specific capability to
satisfy or "temporarily" override a policy to change the MLS label of an
object after it has passed "official procedures". A process may also
jump between multiple MLS labels and perform actions at each. This
functionality requires the need for dynamic domain transitions.

      The implementation is fairly straightforward.  You will be allowed
to write  to /proc/PID/attr/current.  This will require the new
permission of "allow XXX_t  self:process setcurrent".  A second check
will then be done to ensure that the  current context is allowed to
dynamically transition to the new context by  requiring the new
permission of "allow XXX_t YYY_t:process dyntransition".  Role allow
rules are checked in the kernel just like exec-based transitions.  There
are also constraints which will not allow a user change or a role
change.  We have also examined the the issues of state inheritance and
have concluded that extra checks along those lines would have no real
security benefit. One note on this topic is that file descriptor access is
re-validated on use. This will prevent lower privileged domains from using
file descriptors, of a type which the more privileged domain only has
access to, that may be open after a dynamic transition.

      Since the ability to perform dynamic transitions is controlled by
separate permission from exec-based transitions (process setcurrent),
policy writers have the ability to not use the new feature.  The chain
of allowable dynamic  transitions is also controlled on a context-pair
basis.  This allows a "dynamic  transition group" to be treated as an
equivalence class for policy analysis.

      In closing, this feature will greatly aid the adoption of Linux
(and SELinux of course) by current developers and users of trusted
operating systems because it provides them with a transition tool to
migrate their current generation applications which use privilege
bracketing.  Without this migration path, applications which are
currently on trusted operating systems today, will probably never make it
to the Linux community.  This would also lead to a greater application
developer base for SELinux now, and the next generation of those
applications can then be designed to be more modular and use more
exec-based transitions.

NOTE: the patch does not include the auto-generated flask .h files.

Thanks.

-- 

Darrel Goeddel
Senior Secure Systems Engineer

Trusted Computer Solutions             E: dgoeddel@trustedcs.com
121 West Goose Alley                   V: 217.384.0028 x19
Urbana, IL  61801                      F: 217.384.0288

[-- Attachment #2: setcurrentcon.patch --]
[-- Type: text/plain, Size: 7696 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.21
diff -u -u -r1.21 hooks.c
--- linux-2.6/security/selinux/hooks.c	21 Oct 2004 12:59:02 -0000	1.21
+++ linux-2.6/security/selinux/hooks.c	28 Oct 2004 17:47:14 -0000
@@ -4114,10 +4114,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;
 	}
 
@@ -4130,6 +4129,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)
@@ -4154,6 +4155,18 @@
 		tsec->exec_sid = sid;
 	else if (!strcmp(name, "fscreate"))
 		tsec->create_sid = sid;
+	else if (!strcmp(name, "current")) {
+		if (sid == 0)
+			return -EINVAL;
+
+		/* Check permissions for the transition. */
+		error = avc_has_perm(tsec->sid, sid, SECCLASS_PROCESS,
+		                     PROCESS__DYNTRANSITION, NULL, 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.11
diff -u -u -r1.11 services.c
--- linux-2.6/security/selinux/ss/services.c	19 Aug 2004 15:23:55 -0000	1.11
+++ linux-2.6/security/selinux/ss/services.c	28 Oct 2004 17:47:15 -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.12
diff -u -u -r1.12 assert.te
--- selinux-usr/policy/assert.te	24 Aug 2004 19:35:23 -0000	1.12
+++ selinux-usr/policy/assert.te	28 Oct 2004 17:47:15 -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 -u -r1.7 constraints
--- selinux-usr/policy/constraints	8 Jul 2004 13:59:01 -0000	1.7
+++ selinux-usr/policy/constraints	28 Oct 2004 17:47:15 -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 -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	28 Oct 2004 17:47:15 -0000
@@ -240,6 +240,8 @@
 	siginh
 	setrlimit
 	rlimitinh
+	dyntransition
+	setcurrent
 }
 
 
Index: selinux-usr/policy/macros/global_macros.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/policy/macros/global_macros.te,v
retrieving revision 1.43
diff -u -u -r1.43 global_macros.te
--- selinux-usr/policy/macros/global_macros.te	13 Oct 2004 20:14:04 -0000	1.43
+++ selinux-usr/policy/macros/global_macros.te	28 Oct 2004 17:47:15 -0000
@@ -580,9 +580,9 @@
 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;
+allow $1 self:process { transition dyntransition };
 
 # Create/access any System V IPC objects.
 allow $1 domain:{ sem msgq shm } *;
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 -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	28 Oct 2004 17:47:15 -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 -u -r1.1 constraints
--- selinux-usr/policy/targeted/constraints	12 May 2004 12:56:51 -0000	1.1
+++ selinux-usr/policy/targeted/constraints	28 Oct 2004 17:47:15 -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 -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	28 Oct 2004 17:47:15 -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,28 @@
+/*
+ * 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;
+}
+

             reply	other threads:[~2004-10-29 19:10 UTC|newest]

Thread overview: 138+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-29 19:10 Darrel Goeddel [this message]
2004-10-29 21:18 ` dynamic context transitions 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
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=4182959B.4080503@trustedcs.com \
    --to=dgoeddel@trustedcs.com \
    --cc=chanson@TrustedCS.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.