Skip to contentSkip to conversation

disable setenforce

DISCUSSION Russell Coker 2 participants 4 messages Sep 12, 2005 – Sep 17, 2005 1 message not in the archive SELinux security module

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Todd Merritt

I can't find where I read this now, could somebody please tell me what I need to add/remove from the strict policy to disallow running of the setenforce command (but still allow changing enforcement mode via rebooting) ?

I've attached a patch against the latest rawhide policy (which should also work against the latest FC4 policy).

This patch adds a new boolean named secure_mode_policyload to cover loading policy, setting boolean states, and setting enforcing mode. It also adds a new boolean named secure_mode_insmod to control module loading.

NB Setting secure_mode_policyload to default to 1 at boot time will work, but that means policy can only be loaded once at boot (should be able to install new policy and reboot the machine though). Setting secure_mode_insmod at boot will probably make the boot process fail for all non-trivial machines, the initial values of booleans are set before modules for devices such as Ethernet cards. Setting secure_mode_insmod after the boot process is completed might be a good idea if you have no plans to use USB or Cardbus/PCMCIA, there have been exploits which relied on the ability to trick the system into loading modules (EG the ptrace exploit).

We could probably do with more work in this area, but the patch I have attached works reasonably well and adds usefully to the secure_mode functionality so I believe it's worthy of inclusion.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
global_macros.te renamed from global_macros.te.orig +2 -0
@@ -699,8 +699,10 @@
 allow $1 domain:msg  { send receive };
 
 # Access the security API.
+if (!secure_mode) {
 allow $1 security_t:security *;
 auditallow $1 security_t:security { load_policy setenforce setbool };
+}dnl end if !secure_mode
 
 # Perform certain system operations that lacked individual capabilities.
 allow $1 kernel_t:system *;
core_macros.te renamed from core_macros.te.orig +6 -0
@@ -306,8 +306,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode) {
 allow $1 security_t:security setenforce;
 auditallow $1 security_t:security setenforce;
+}dnl end if !secure_mode
 ')
 
 ##################################
@@ -326,8 +328,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode) {
 allow $1 security_t:security setbool;
 auditallow $1 security_t:security setbool;
+}dnl end if !secure_mode
 ')
 
 ##################################
@@ -367,8 +371,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode) {
 allow $1 security_t:security load_policy;
 auditallow $1 security_t:security load_policy;
+}dnl end if !secure_mode
 ')
 
 #################################
#2 lore raw
Quoted 7 lines · Russell Coker

I've attached a patch against the latest rawhide policy (which should also work against the latest FC4 policy).

This patch adds a new boolean named secure_mode_policyload to cover loading policy, setting boolean states, and setting enforcing mode. It also adds a new boolean named secure_mode_insmod to control module loading.

Quoted 9 lines

NB Setting secure_mode_policyload to default to 1 at boot time will work, but that means policy can only be loaded once at boot (should be able to install new policy and reboot the machine though). Setting secure_mode_insmod at boot will probably make the boot process fail for all non-trivial machines, the initial values of booleans are set before modules for devices such as Ethernet cards. Setting secure_mode_insmod after the boot process is completed might be a good idea if you have no plans to use USB or Cardbus/PCMCIA, there have been exploits which relied on the ability to trick the system into loading modules (EG the ptrace exploit).

Did you attach the wrong patch? The one you sent doesn't define new booleans; it just wraps additional rules with the existing secure_mode boolean.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 10 lines

NB Setting secure_mode_policyload to default to 1 at boot time will work, but that means policy can only be loaded once at boot (should be able to install new policy and reboot the machine though). Setting secure_mode_insmod at boot will probably make the boot process fail for all non-trivial machines, the initial values of booleans are set before modules for devices such as Ethernet cards. Setting secure_mode_insmod after the boot process is completed might be a good idea if you have no plans to use USB or Cardbus/PCMCIA, there have been exploits which relied on the ability to trick the system into loading modules (EG the ptrace exploit).

Quoted 3 lines

Did you attach the wrong patch? The one you sent doesn't define new booleans; it just wraps additional rules with the existing secure_mode boolean.

I attached the patch, re-worked it, and then forgot to attach the new patch.

The correct patch is attached to this message.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
global_macros.te renamed from global_macros.te.orig +2 -0
@@ -699,8 +699,10 @@
 allow $1 domain:msg  { send receive };
 
 # Access the security API.
+if (!secure_mode_policyload) {
 allow $1 security_t:security *;
 auditallow $1 security_t:security { load_policy setenforce setbool };
+}dnl end if !secure_mode_policyload
 
 # Perform certain system operations that lacked individual capabilities.
 allow $1 kernel_t:system *;
core_macros.te renamed from core_macros.te.orig +6 -0
@@ -306,8 +306,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security setenforce;
 auditallow $1 security_t:security setenforce;
+}dnl end if !secure_mode_policyload
 ')
 
 ##################################
@@ -326,8 +328,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security setbool;
 auditallow $1 security_t:security setbool;
+}dnl end if !secure_mode_policyload
 ')
 
 ##################################
@@ -367,8 +371,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security load_policy;
 auditallow $1 security_t:security load_policy;
+}dnl end if !secure_mode_policyload
 ')
 
 #################################
program/load_policy.te renamed from program/load_policy.te.orig +4 -0
@@ -8,6 +8,10 @@
 # load_policy_t is the domain type for load_policy 
 # load_policy_exec_t is the file type for the executable
 
+# boolean to determine whether the system permits loading policy, setting
+# enforcing mode, and changing boolean values.  Set this to true and you
+# have to reboot to set it back
+bool secure_mode_policyload false;
 
 type load_policy_t, domain;
 role sysadm_r types load_policy_t;
program/modutil.te renamed from program/modutil.te.orig +6 -1
@@ -77,6 +77,11 @@
 ;
 role system_r types insmod_t;
 role sysadm_r types insmod_t;
+type insmod_exec_t, file_type, exec_type, sysadmfile;
+
+bool secure_mode_insmod false;
+
+if (!secure_mode_insmod) {
 
 ifdef(`unlimitedUtils', `
 unconfined_domain(insmod_t) 
@@ -161,7 +166,6 @@
 allow insmod_t device_t:dir read;
 allow insmod_t devpts_t:dir { getattr search };
 
-type insmod_exec_t, file_type, exec_type, sysadmfile;
 domain_auto_trans(privmodule, insmod_exec_t, insmod_t)
 can_exec(insmod_t, { insmod_exec_t shell_exec_t bin_t sbin_t etc_t })
 allow insmod_t devtty_t:chr_file rw_file_perms;
@@ -177,6 +181,7 @@
 
 # for nscd
 dontaudit insmod_t var_run_t:dir search;
+}dnl end if !secure_mode_insmod
 
 ifdef(`crond.te', `
 rw_dir_create_file(system_crond_t, var_log_ksyms_t)
#4 lore raw
Quoted 8 lines · Russell Coker
Quoted 3 lines

Did you attach the wrong patch? The one you sent doesn't define new booleans; it just wraps additional rules with the existing secure_mode boolean.

I attached the patch, re-worked it, and then forgot to attach the new patch.

The correct patch is attached to this message.

I hate doing this.

Just after I sent the previous patch I discovered a minor bug. When building a policy with ypbind.te included the nested booleans break the compile. The attached patch fixes this.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
global_macros.te renamed from global_macros.te.orig +2 -0
@@ -699,8 +699,10 @@
 allow $1 domain:msg  { send receive };
 
 # Access the security API.
+if (!secure_mode_policyload) {
 allow $1 security_t:security *;
 auditallow $1 security_t:security { load_policy setenforce setbool };
+}dnl end if !secure_mode_policyload
 
 # Perform certain system operations that lacked individual capabilities.
 allow $1 kernel_t:system *;
core_macros.te renamed from core_macros.te.orig +6 -0
@@ -306,8 +306,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security setenforce;
 auditallow $1 security_t:security setenforce;
+}dnl end if !secure_mode_policyload
 ')
 
 ##################################
@@ -326,8 +328,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security setbool;
 auditallow $1 security_t:security setbool;
+}dnl end if !secure_mode_policyload
 ')
 
 ##################################
@@ -367,8 +371,10 @@
 # Access selinuxfs.
 allow $1 security_t:dir { read search getattr };
 allow $1 security_t:file { getattr read write };
+if (!secure_mode_policyload) {
 allow $1 security_t:security load_policy;
 auditallow $1 security_t:security load_policy;
+}dnl end if !secure_mode_policyload
 ')
 
 #################################
program/load_policy.te renamed from program/load_policy.te.orig +4 -0
@@ -8,6 +8,10 @@
 # load_policy_t is the domain type for load_policy 
 # load_policy_exec_t is the file type for the executable
 
+# boolean to determine whether the system permits loading policy, setting
+# enforcing mode, and changing boolean values.  Set this to true and you
+# have to reboot to set it back
+bool secure_mode_policyload false;
 
 type load_policy_t, domain;
 role sysadm_r types load_policy_t;
program/modutil.te renamed from program/modutil.te.orig +7 -2
@@ -77,11 +77,16 @@
 ;
 role system_r types insmod_t;
 role sysadm_r types insmod_t;
+type insmod_exec_t, file_type, exec_type, sysadmfile;
+
+bool secure_mode_insmod false;
+
+can_ypbind(insmod_t)
+if (!secure_mode_insmod) {
 
 ifdef(`unlimitedUtils', `
 unconfined_domain(insmod_t) 
 ')
-can_ypbind(insmod_t)
 uses_shlib(insmod_t)
 read_locale(insmod_t)
 
@@ -161,7 +166,6 @@
 allow insmod_t device_t:dir read;
 allow insmod_t devpts_t:dir { getattr search };
 
-type insmod_exec_t, file_type, exec_type, sysadmfile;
 domain_auto_trans(privmodule, insmod_exec_t, insmod_t)
 can_exec(insmod_t, { insmod_exec_t shell_exec_t bin_t sbin_t etc_t })
 allow insmod_t devtty_t:chr_file rw_file_perms;
@@ -177,6 +181,7 @@
 
 # for nscd
 dontaudit insmod_t var_run_t:dir search;
+}dnl end if !secure_mode_insmod
 
 ifdef(`crond.te', `
 rw_dir_create_file(system_crond_t, var_log_ksyms_t)