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. + */ + +#include +#include +#include +#include + +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; +} +