selinux: Permit transitions under NO_NEW_PRIVS or NOSUID under certain, circumstances.
PATCH 1/1 selinux: Permit transitions under NO_NEW_PRIVS or NOSUID under certain, circumstances.
Quoted 1 line
From
731c593d0813128eb6d3a62658038681b6e1cf9aMon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] Permit transitions under NO_NEW_PRIVS or NOSUID under certain
circumstances.
If the caller SID is bounded by the callee SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
--- security/selinux/hooks.c | 54 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-)
security/selinux/hooks.c +42 -12
@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc; + +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ + +/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ; +} +static int selinux_bprm_set_creds (struct linux_binprm *bprm) {const struct task_security_struct *old_tsec;
@@ -2122,14 +2152,10 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)/* Reset exec SID on execve. */ new_tsec->exec_sid =0 ; -/* -* Minimize confusion: if no_new_privs or nosuid and a -* transition is explicitly requested, then fail the exec. -*/ -if (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ) -return -EPERM ; -if (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ) -return -EACCES ; +/* Fail on NNP or nosuid if not an allowed transition. */ + rc =check_nnp_nosuid (bprm, old_tsec, new_tsec); +if (rc) +return rc; }else {/* Check for a default transition on this program. */ rc = security_transition_sid(old_tsec->sid, isec->sid,
@@ -2137,15 +2163,19 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) &new_tsec->sid);if (rc)return rc; + +/* +* Fallback to old SID on NNP or nosuid if not an allowed +* transition. +*/ + rc =check_nnp_nosuid (bprm, old_tsec, new_tsec); +if (rc) + new_tsec->sid = old_tsec->sid; } ad.type =LSM_AUDIT_DATA_PATH ; ad.u.path = bprm->file->f_path; -if ((bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ) || - (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS )) - new_tsec->sid = old_tsec->sid; -if (new_tsec->sid == old_tsec->sid) { rc =avc_has_perm (old_tsec->sid, isec->sid,SECCLASS_FILE ,FILE__EXECUTE_NO_TRANS , &ad);
Signature · 1 line
1.9.3
Quoted 1 line · Stephen Smalley
One more minor nit:
"If the caller SID is bounded by the callee SID"
Is that backwards? I think the code is correct, but I'm less convinced by the changelog.
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
PATCH v2 1/1 selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
v2 - fix patch description to match the code.
Quoted 1 line
From
c1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions under NO_NEW_PRIVS or
NOSUID under certain circumstances.
If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
--- security/selinux/hooks.c | 54 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-)
security/selinux/hooks.c +42 -12
@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc; + +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ + +/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ; +} +static int selinux_bprm_set_creds (struct linux_binprm *bprm) {const struct task_security_struct *old_tsec;
@@ -2122,14 +2152,10 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)/* Reset exec SID on execve. */ new_tsec->exec_sid =0 ; -/* -* Minimize confusion: if no_new_privs or nosuid and a -* transition is explicitly requested, then fail the exec. -*/ -if (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ) -return -EPERM ; -if (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ) -return -EACCES ; +/* Fail on NNP or nosuid if not an allowed transition. */ + rc =check_nnp_nosuid (bprm, old_tsec, new_tsec); +if (rc) +return rc; }else {/* Check for a default transition on this program. */ rc = security_transition_sid(old_tsec->sid, isec->sid,
@@ -2137,15 +2163,19 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) &new_tsec->sid);if (rc)return rc; + +/* +* Fallback to old SID on NNP or nosuid if not an allowed +* transition. +*/ + rc =check_nnp_nosuid (bprm, old_tsec, new_tsec); +if (rc) + new_tsec->sid = old_tsec->sid; } ad.type =LSM_AUDIT_DATA_PATH ; ad.u.path = bprm->file->f_path; -if ((bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ) || - (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS )) - new_tsec->sid = old_tsec->sid; -if (new_tsec->sid == old_tsec->sid) { rc =avc_has_perm (old_tsec->sid, isec->sid,SECCLASS_FILE ,FILE__EXECUTE_NO_TRANS , &ad);
Signature · 1 line
1.8.3.1
PATCH 1/1 selinux-testsuite: Add tests for exec transitions under NO_NEW_PRIVS
Tests 1-4 will fail on existing kernels without the patch entitled "selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.". Tests 5-6 should always pass.
We shouldn't apply it to the selinux-testsuite until after the kernel change is merged, and then we should make it dependent on the first kernel version that will include the change.
Quoted 1 line
From
66e8681c88a4cb0e3d84ed92f59e9812ba4a3003Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Fri, 13 Jun 2014 12:40:16 -0400
Subject: [PATCH] Add tests for exec transitions under NO_NEW_PRIVS.
--- policy/Makefile | 2 +- policy/test_nnp.te | 48 +++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 2 +- tests/nnp/Makefile | 7 +++++++ tests/nnp/checkcon.c | 40 +++++++++++++++++++++++++++++++++++++++ tests/nnp/execnnp.c | 25 +++++++++++++++++++++++++ tests/nnp/test | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 policy/test_nnp.te create mode 100644 tests/nnp/Makefile create mode 100644 tests/nnp/checkcon.c create mode 100644 tests/nnp/execnnp.c create mode 100755 tests/nnp/test
policy/Makefile +1 -1
@@ -14,7 +14,7 @@ TARGETS = \ test_entrypoint.te test_execshare.te test_exectrace.te \ test_execute_no_trans.te test_fdreceive.te test_file.te \ test_inherit.te test_ioctl.te test_ipc.te test_link.te test_mkdir.te \ - test_open.te test_ptrace.te test_readlink.te \ + test_nnp.te test_open.te test_ptrace.te test_readlink.te \ test_relabel.te test_rename.te test_rxdir.te test_setattr.te \ test_setnice.te test_sigkill.te test_stat.te test_sysctl.te \ test_task_create.te test_task_getpgid.te test_task_getsched.te \
policy/test_nnp.te new file +48 -0
48 lines not on this page · raw message
tests/Makefile +1 -1
@@ -1,6 +1,6 @@ REDHAT_RELEASE=$(shell rpm -q redhat-release) -SUBDIRS=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys dyntrans dyntrace bounds +SUBDIRS=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg nnp open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys dyntrans dyntrace bounds #SUBDIRS=socket unix_socket unix_secure ifeq (redhat-release-4, $(findstring redhat-release-4, $(REDHAT_RELEASE)))
tests/nnp/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +TARGETS=execnnp checkcon + +LDLIBS += -lselinux + +all: $(TARGETS) +clean: + rm -f $(TARGETS)
tests/nnp/checkcon.c new file +40 -0
@@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <selinux/selinux.h> +#include <selinux/context.h> + +int main (int argc,char **argv) +{ +char *con =NULL ; +context_t c; +const char *type; +int rc; + +if (argc !=2 ) { +fprintf (stderr,"usage: %s expected-type\n" , argv[0 ]); +exit (-1 ); + } + +if (getcon (&con) <0 ) { +perror ("getcon" ); +exit (-1 ); + } + + c =context_new (con); +if (!c) { +perror ("context_new" ); +exit (-1 ); + } + + type =context_type_get (c); +if (!type) { +perror ("context_type_get" ); +exit (-1 ); + + } + + rc =strcmp (type, argv[1 ]); +exit (rc); +}
tests/nnp/execnnp.c new file +25 -0
@@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/prctl.h> + +int main (int argc,char **argv) +{ +int rc; + +if (argc <2 ) { +fprintf (stderr,"usage: %s command [args...]\n" , argv[0 ]); +exit (-1 ); + } + + rc =prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 ); +if (rc <0 ) { +perror ("prctl PR_SET_NO_NEW_PRIVS" ); +exit (-1 ); + } + +execvp (argv[1 ], &argv[1 ]); +perror (argv[1 ]); +exit (1 ); +}
tests/nnp/test new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
In reply to Stephen SmalleyQuoted 1 line · Stephen Smalley
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Quoted 1 line
From
c1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions under NO_NEW_PRIVS or
NOSUID under certain circumstances.
If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
--- security/selinux/hooks.c | 54 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-)
security/selinux/hooks.c +0 -0
@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct
*mm, long pages)
/* binprm security operations */
+static int check_nnp_nosuid(const struct linux_binprm *bprm,
+ const struct task_security_struct *old_tsec,
+ const struct task_security_struct *new_tsec)
+{
+ int nnp = (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS);
+ int nosuid = (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID);
+ int rc;
+
+ if (!nnp && !nosuid)
+ return 0; /* neither NNP nor nosuid */
+
+ if (new_tsec->sid == old_tsec->sid)
+ return 0; /* No change in credentials */
+
+ rc = security_bounded_transition(old_tsec->sid, new_tsec->sid);
+ if (rc == 0)
+ return 0; /* allowed via bounded transition */
+
+ /* Only allow if dyntransition permission aka setcon() is allowed. */
+ rc = avc_has_perm(old_tsec->sid, new_tsec->sid, SECCLASS_PROCESS,
+ PROCESS__DYNTRANSITION, NULL);
+ if (rc) {
+ if (nnp)
+ return -EPERM;
+ else
+ return -EACCES;
+ }
+ return 0;
+}
+
static int selinux_bprm_set_creds(struct linux_binprm *bprm)
{
const struct task_security_struct *old_tsec;
@@ -2122,14 +2152,10 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
/* Reset exec SID on execve. */ new_tsec->exec_sid = 0;
- /*
- * Minimize confusion: if no_new_privs or nosuid and a
- * transition is explicitly requested, then fail the exec.
- */
- if (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)
- return -EPERM;
- if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
- return -EACCES;
+ /* Fail on NNP or nosuid if not an allowed transition. */
+ rc = check_nnp_nosuid(bprm, old_tsec, new_tsec);
+ if (rc)
+ return rc;
} else {
/* Check for a default transition on this program. */ rc = security_transition_sid(old_tsec->sid, isec->sid,
@@ -2137,15 +2163,19 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
&new_tsec->sid);
if (rc)
return rc;
+
+ /*
+ * Fallback to old SID on NNP or nosuid if not an allowed
+ * transition.
+ */
+ rc = check_nnp_nosuid(bprm, old_tsec, new_tsec);
+ if (rc)
+ new_tsec->sid = old_tsec->sid;
}
ad.type = LSM_AUDIT_DATA_PATH;
ad.u.path = bprm->file->f_path;
- if ((bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) ||
- (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS))
- new_tsec->sid = old_tsec->sid;
-
if (new_tsec->sid == old_tsec->sid) {
rc = avc_has_perm(old_tsec->sid, isec->sid,
SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, &ad);
Signature · 1 line
1.8.3.1
Paul Moore
maintainerRe: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
Quoted 21 lines · Paul Moore
Quoted 1 line · Stephen Smalley
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>
Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */
I think there might be an audit issue here; security_bounded_transition() will generate an audit record on failure which probably isn't what we want in this case.
Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;
I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
Quoted 80 lines · Paul Moore
Quoted 21 lines · Paul Moore
Quoted 1 line · Stephen Smalley
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ I think there might be an audit issue here;
security_bounded_transition()will generate an audit record on failure which probably isn't what we want in this case.Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
Quoted 2 lines
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
The claim was that dyntransition is sufficient since it would allow the caller to setcon() to the new domain directly and therefore perform any action in that domain. Thus, allowing it to transition to that domain upon exec under NNP or on a file in a nosuid mount does not enable it to do anything it could not already do directly.
However, this presumes that the policy writer does not merely add dyntransition to the caller domain upon encountering the avc denial in this situation without thinking about the implications and deciding whether to truly trust the caller domain in this way. Which is likely a dangerous assumption, especially for people who write policy via audit2allow.
At least with the bounded transition, you have to explicitly declare that the new domain is bounded by the caller domain and the kernel will then enforce the restriction that the new domain is not granted any permission not allowed to the caller domain.
I'm also unclear as to whether this in fact solves the actual problem for sandbox -X.
So I'd drop this patch for now at least.
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
Quoted 97 lines · Stephen Smalley
Quoted 80 lines · Paul Moore
Quoted 21 lines · Paul Moore
Quoted 1 line · Stephen Smalley
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ I think there might be an audit issue here;
security_bounded_transition()will generate an audit record on failure which probably isn't what we want in this case.Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
Quoted 2 lines
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
The claim was that dyntransition is sufficient since it would allow the caller to
setcon()to the new domain directly and therefore perform any action in that domain. Thus, allowing it to transition to that domain upon exec under NNP or on a file in a nosuid mount does not enable it to do anything it could not already do directly.However, this presumes that the policy writer does not merely add dyntransition to the caller domain upon encountering the avc denial in this situation without thinking about the implications and deciding whether to truly trust the caller domain in this way. Which is likely a dangerous assumption, especially for people who write policy via audit2allow.
Quoted 5 lines
At least with the bounded transition, you have to explicitly declare that the new domain is bounded by the caller domain and the kernel will then enforce the restriction that the new domain is not granted any permission not allowed to the caller domain.
How about making the change just for bounded transitions, then? No one will write the policy if the kernel doesn't support it.
Quoted 2 lines
I'm also unclear as to whether this in fact solves the actual problem for sandbox -X.
Dunno. dwalsh, does it?
Quoted 2 lines
So I'd drop this patch for now at least.
--Andy
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
We can use it to fix sandbox.
sandbox -X xterm can do the following
unconfined_t -> seunshare_t -> sandbox_x_t Then I allow sandbox_x_t to setcur to sandbox_x_client_t. sandbox_x_t can run the xserver, and the confined app will run as sandbox_x_client_t. If I am allowed to transition to a tighter domain, I can get the scripts to work.
Quoted 114 lines · Andy Lutomirski
Quoted 92 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 1 line · Stephen Smalley
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ I think there might be an audit issue here;
security_bounded_transition()will generate an audit record on failure which probably isn't what we want in this case.Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
Quoted 2 lines
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
The claim was that dyntransition is sufficient since it would allow the caller to
setcon()to the new domain directly and therefore perform any action in that domain. Thus, allowing it to transition to that domain upon exec under NNP or on a file in a nosuid mount does not enable it to do anything it could not already do directly.However, this presumes that the policy writer does not merely add dyntransition to the caller domain upon encountering the avc denial in this situation without thinking about the implications and deciding whether to truly trust the caller domain in this way. Which is likely a dangerous assumption, especially for people who write policy via audit2allow.
Quoted 5 lines
At least with the bounded transition, you have to explicitly declare that the new domain is bounded by the caller domain and the kernel will then enforce the restriction that the new domain is not granted any permission not allowed to the caller domain.
How about making the change just for bounded transitions, then? No one will write the policy if the kernel doesn't support it.
Quoted 2 lines
I'm also unclear as to whether this in fact solves the actual problem for sandbox -X.
Dunno. dwalsh, does it?
Quoted 1 line
So I'd drop this patch for now at least.
--Andy
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
Quoted 8 lines · Daniel J Walsh
We can use it to fix sandbox.
sandbox -X xterm can do the following
unconfined_t->seunshare_t->sandbox_x_tThen I allowsandbox_x_tto setcur tosandbox_x_client_t.sandbox_x_tcan run the xserver, and the confined app will run assandbox_x_client_t. If I am allowed to transition to a tighter domain, I can get the scripts to work.
Which of those transitions are on exec and which ones are via explicit setcon() call?
Would it work if you couldn't allow it via dyntransition but had to specify typebounds <callingdomain> <newdomain>;
instead?
Quoted 118 lines · Andy Lutomirski
Quoted 114 lines · Stephen Smalley
Quoted 92 lines · Paul Moore
Quoted 76 lines · Paul Moore
Quoted 20 lines · Stephen Smalley
Quoted 1 line
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ I think there might be an audit issue here;
security_bounded_transition()will generate an audit record on failure which probably isn't what we want in this case.Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
Quoted 2 lines
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
The claim was that dyntransition is sufficient since it would allow the caller to
setcon()to the new domain directly and therefore perform any action in that domain. Thus, allowing it to transition to that domain upon exec under NNP or on a file in a nosuid mount does not enable it to do anything it could not already do directly.However, this presumes that the policy writer does not merely add dyntransition to the caller domain upon encountering the avc denial in this situation without thinking about the implications and deciding whether to truly trust the caller domain in this way. Which is likely a dangerous assumption, especially for people who write policy via audit2allow.
Quoted 5 lines
At least with the bounded transition, you have to explicitly declare that the new domain is bounded by the caller domain and the kernel will then enforce the restriction that the new domain is not granted any permission not allowed to the caller domain.
How about making the change just for bounded transitions, then? No one will write the policy if the kernel doesn't support it.
Quoted 2 lines
I'm also unclear as to whether this in fact solves the actual problem for sandbox -X.
Dunno. dwalsh, does it?
Quoted 1 line
So I'd drop this patch for now at least.
--Andy
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].
Re: [PATCH v2] selinux: Permit exec transitions under NO_NEW_PRIVS or NOSUID under certain circumstances.
Quoted 11 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh
We can use it to fix sandbox.
sandbox -X xterm can do the following
unconfined_t->seunshare_t->sandbox_x_tThen I allowsandbox_x_tto setcur tosandbox_x_client_t.sandbox_x_tcan run the xserver, and the confined app will run assandbox_x_client_t. If I am allowed to transition to a tighter domain, I can get the scripts to work.Which of those transitions are on exec and which ones are via explicit
setcon()call?
seunshare will call setcon. sandbox_x_t would transition on exec when executing a new script or executing sandbox_file_t would transition to sandbox_x_client_t.
sandbox_x_client_t would be a subset of sandbox_x_t, basically not able to talk to X. Of course if this was written in CIL it would be a lot easier to do. :^)
Quoted 128 lines
Would it work if you couldn't allow it via dyntransition but had to specify typebounds <callingdomain> <newdomain>;
instead?Quoted 107 lines · Andy Lutomirski
Quoted 106 lines · Stephen Smalley
Quoted 92 lines · Paul Moore
Quoted 76 lines · Paul Moore
Quoted 20 lines · Stephen Smalley
Quoted 1 line
v2 - fix patch description to match the code.
Okay Stephen, I suppose you should get some special consideration, but is posting your patches inline really that hard :)
---
Fromc1fa21950c5c3eb0dd97ae5145fa3d3f04adc5c4Mon Sep 17 00:00:00 2001
From: Stephen Smalley <[email protected]>
Date: Thu, 12 Jun 2014 08:17:48 -0400
Subject: [PATCH] selinux: Permit exec transitions underNO_NEW_PRIVSor
NOSUID under certain circumstances.If the callee SID is bounded by the caller SID or if the caller SID is allowed to perform a dynamic transition (setcon) to the callee SID, then allowing the transition to occur poses no risk of privilege escalation and we can therefore safely allow the transition to occur. Add these two exemptions for both the case where a transition was explicitly requested by the application and the case where an automatic transition is defined in policy.
Quoted 2 lines
Signed-off-by Stephen Smalley <[email protected]>Acked-by Andy Lutomirski <[email protected]>Comments below ...
Quoted 16 lines
security/selinux/hooks.c +7
-0@@ -2086,6 +2086,36 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)/* binprm security operations */ +static int check_nnp_nosuid (const struct linux_binprm *bprm, +const struct task_security_struct *old_tsec, +const struct task_security_struct *new_tsec) +{ +int nnp = (bprm->unsafe &LSM_UNSAFE_NO_NEW_PRIVS ); +int nosuid = (bprm->file->f_path.mnt->mnt_flags &MNT_NOSUID ); +int rc;security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2106
Quoted 10 lines
security/selinux/hooks.c +10
-0+ +if (!nnp && !nosuid) +return 0 ;/* neither NNP nor nosuid */ + +if (new_tsec->sid == old_tsec->sid) +return 0 ;/* No change in credentials */ + + rc =security_bounded_transition (old_tsec->sid, new_tsec->sid); +if (rc ==0 ) +return 0 ;/* allowed via bounded transition */ I think there might be an audit issue here;
security_bounded_transition()will generate an audit record on failure which probably isn't what we want in this case.Other than that, this seems reasonable, even in the face of NNP, and as others point out, standard DAC capabilities do something similar.
security/selinux/hooks.c static int selinux_vm_enough_memory(struct mm_struct · line 2116
Quoted 10 lines
security/selinux/hooks.c +10
-0+/* Only allow if dyntransition permission aka setcon() is allowed. */ + rc =avc_has_perm (old_tsec->sid, new_tsec->sid,SECCLASS_PROCESS , +PROCESS__DYNTRANSITION ,NULL ); +if (rc) { +if (nnp) +return -EPERM ; +else +return -EACCES ; + } +return 0 ;I know this dyntransition/NNP/NOSUID interaction has been discussed quite a bit off-list (mostly while I was away, my apologies), but I haven't seen a lot on-list and while the descriptions hints at it the code itself doesn't elaborate on why this is "OK". I'd like to see some comments about why it is okay to allow the transition, regardless of NNP/NOSUID, if the dyntransition is allowed. I'd also like to see a quick comment about why we return -EPERM/- EACCES.
Quoted 2 lines
There was a lot of discussion around these points and I want to make sure the ideas aren't lost.
The claim was that dyntransition is sufficient since it would allow the caller to
setcon()to the new domain directly and therefore perform any action in that domain. Thus, allowing it to transition to that domain upon exec under NNP or on a file in a nosuid mount does not enable it to do anything it could not already do directly.However, this presumes that the policy writer does not merely add dyntransition to the caller domain upon encountering the avc denial in this situation without thinking about the implications and deciding whether to truly trust the caller domain in this way. Which is likely a dangerous assumption, especially for people who write policy via audit2allow.
Quoted 5 lines
At least with the bounded transition, you have to explicitly declare that the new domain is bounded by the caller domain and the kernel will then enforce the restriction that the new domain is not granted any permission not allowed to the caller domain.
How about making the change just for bounded transitions, then? No one will write the policy if the kernel doesn't support it.
Quoted 2 lines
I'm also unclear as to whether this in fact solves the actual problem for sandbox -X.
Dunno. dwalsh, does it?
Quoted 1 line
So I'd drop this patch for now at least.
Quoted 9 lines
Quoted 8 lines
--Andy
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected]._______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].