All of lore.kernel.org
 help / color / mirror / Atom feed
* [v1 PATCH 2/7] Separate tunable from boolean during compile.
@ 2011-08-29  7:53 Harry Ciao
  2011-08-29  7:53 ` [v1 PATCH 3/7] Write and read TUNABLE flags in related data structures Harry Ciao
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Harry Ciao @ 2011-08-29  7:53 UTC (permalink / raw)
  To: cpebenito, slawrence; +Cc: selinux

Both boolean and tunable keywords are processed by define_bool_tunable(),
argument 0 and 1 would be passed for boolean and tunable respectively.
For tunable, a TUNABLE flag would be set in cond_bool_datum_t.flags.

Note, when creating an if-else conditional we can not know if the
tunable identifier is indeed a tunable(for example, a boolean may be
misused in tunable_policy() or vice versa), thus the TUNABLE flag
for cond_node_t would be calculated and used in expansion when all
booleans/tunables copied during link.

Signed-off-by: Harry Ciao <qingtao.cao@windriver.com>
---
 checkpolicy/module_compiler.c |   16 +++++++++++++++-
 checkpolicy/module_compiler.h |    1 +
 checkpolicy/policy_define.c   |    4 +++-
 checkpolicy/policy_define.h   |    2 +-
 checkpolicy/policy_parse.y    |    8 +++++++-
 checkpolicy/policy_scan.l     |    2 ++
 libsepol/src/conditional.c    |    1 +
 7 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/checkpolicy/module_compiler.c b/checkpolicy/module_compiler.c
index 1c1d1d5..ffffaf1 100644
--- a/checkpolicy/module_compiler.c
+++ b/checkpolicy/module_compiler.c
@@ -1045,7 +1045,7 @@ int require_user(int pass)
 	}
 }
 
-int require_bool(int pass)
+static int require_bool_tunable(int pass, int is_tunable)
 {
 	char *id = queue_remove(id_queue);
 	cond_bool_datum_t *booldatum = NULL;
@@ -1063,6 +1063,8 @@ int require_bool(int pass)
 		yyerror("Out of memory!");
 		return -1;
 	}
+	if (is_tunable)
+		booldatum->flags |= COND_BOOL_FLAGS_TUNABLE;
 	retval =
 	    require_symbol(SYM_BOOLS, id, (hashtab_datum_t *) booldatum,
 			   &booldatum->s.value, &booldatum->s.value);
@@ -1094,6 +1096,16 @@ int require_bool(int pass)
 	}
 }
 
+int require_bool(int pass)
+{
+	return require_bool_tunable(pass, 0);
+}
+
+int require_tunable(int pass)
+{
+	return require_bool_tunable(pass, 1);
+}
+
 int require_sens(int pass)
 {
 	char *id = queue_remove(id_queue);
@@ -1328,6 +1340,8 @@ void append_cond_list(cond_list_t * cond)
 		     tmp = tmp->next) ;
 		tmp->next = cond->avfalse_list;
 	}
+
+	old_cond->flags |= cond->flags;
 }
 
 void append_avrule(avrule_t * avrule)
diff --git a/checkpolicy/module_compiler.h b/checkpolicy/module_compiler.h
index 45a21cd..72c2d9b 100644
--- a/checkpolicy/module_compiler.h
+++ b/checkpolicy/module_compiler.h
@@ -58,6 +58,7 @@ int require_attribute(int pass);
 int require_attribute_role(int pass);
 int require_user(int pass);
 int require_bool(int pass);
+int require_tunable(int pass);
 int require_sens(int pass);
 int require_cat(int pass);
 
diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
index ded27f7..1bf669c 100644
--- a/checkpolicy/policy_define.c
+++ b/checkpolicy/policy_define.c
@@ -1494,7 +1494,7 @@ avrule_t *define_cond_compute_type(int which)
 	return avrule;
 }
 
-int define_bool(void)
+int define_bool_tunable(int is_tunable)
 {
 	char *id, *bool_value;
 	cond_bool_datum_t *datum;
@@ -1524,6 +1524,8 @@ int define_bool(void)
 		return -1;
 	}
 	memset(datum, 0, sizeof(cond_bool_datum_t));
+	if (is_tunable)
+		datum->flags |= COND_BOOL_FLAGS_TUNABLE;
 	ret = declare_symbol(SYM_BOOLS, id, datum, &value, &value);
 	switch (ret) {
 	case -3:{
diff --git a/checkpolicy/policy_define.h b/checkpolicy/policy_define.h
index fc8cd4d..92a9be7 100644
--- a/checkpolicy/policy_define.h
+++ b/checkpolicy/policy_define.h
@@ -21,7 +21,7 @@ cond_expr_t *define_cond_expr(uint32_t expr_type, void *arg1, void* arg2);
 int define_attrib(void);
 int define_attrib_role(void);
 int define_av_perms(int inherits);
-int define_bool(void);
+int define_bool_tunable(int is_tunable);
 int define_category(void);
 int define_class(void);
 int define_common_perms(void);
diff --git a/checkpolicy/policy_parse.y b/checkpolicy/policy_parse.y
index 0a17bdc..49ac15f 100644
--- a/checkpolicy/policy_parse.y
+++ b/checkpolicy/policy_parse.y
@@ -101,6 +101,7 @@ typedef int (* require_func_t)();
 %token ALIAS
 %token ATTRIBUTE
 %token BOOL
+%token TUNABLE
 %token IF
 %token ELSE
 %token TYPE_TRANSITION
@@ -269,6 +270,7 @@ te_decl			: attribute_def
                         | typeattribute_def
                         | typebounds_def
                         | bool_def
+			| tunable_def
                         | transition_def
                         | range_trans_def
                         | te_avtab_def
@@ -295,8 +297,11 @@ opt_attr_list           : ',' id_comma_list
 			| 
 			;
 bool_def                : BOOL identifier bool_val ';'
-                        {if (define_bool()) return -1;}
+                        { if (define_bool_tunable(0)) return -1; }
                         ;
+tunable_def		: TUNABLE identifier bool_val ';'
+			{ if (define_bool_tunable(1)) return -1; }
+			;
 bool_val                : CTRUE
  			{ if (insert_id("T",0)) return -1; }
                         | CFALSE
@@ -820,6 +825,7 @@ require_decl_def        : ROLE        { $$ = require_role; }
                         | ATTRIBUTE_ROLE   { $$ = require_attribute_role; }
                         | USER        { $$ = require_user; }
                         | BOOL        { $$ = require_bool; }
+			| TUNABLE     { $$ = require_tunable; }
                         | SENSITIVITY { $$ = require_sens; }
                         | CATEGORY    { $$ = require_cat; }
                         ;
diff --git a/checkpolicy/policy_scan.l b/checkpolicy/policy_scan.l
index ed27bbe..a61e0db 100644
--- a/checkpolicy/policy_scan.l
+++ b/checkpolicy/policy_scan.l
@@ -92,6 +92,8 @@ TYPE |
 type				{ return(TYPE); }
 BOOL |
 bool                            { return(BOOL); }
+TUNABLE |
+tunable				{ return(TUNABLE); }
 IF |
 if				{ return(IF); }
 ELSE |
diff --git a/libsepol/src/conditional.c b/libsepol/src/conditional.c
index 1482387..efdedb0 100644
--- a/libsepol/src/conditional.c
+++ b/libsepol/src/conditional.c
@@ -160,6 +160,7 @@ cond_node_t *cond_node_create(policydb_t * p, cond_node_t * node)
 		for (i = 0; i < min(node->nbools, COND_MAX_BOOLS); i++)
 			new_node->bool_ids[i] = node->bool_ids[i];
 		new_node->expr_pre_comp = node->expr_pre_comp;
+		new_node->flags = node->flags;
 	}
 
 	return new_node;
-- 
1.7.0.4


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply related	[flat|nested] 13+ messages in thread
* v1 Discard unused tunables from raw policy
@ 2011-08-29  8:20 Harry Ciao
  2011-08-29  8:21 ` [v1 PATCH 6/7] Skip tunable identifier and cond_node_t in expansion Harry Ciao
  0 siblings, 1 reply; 13+ messages in thread
From: Harry Ciao @ 2011-08-29  8:20 UTC (permalink / raw)
  To: cpebenito, slawrence; +Cc: selinux


Special Notes
---------------
1. So far the latest master toolchain seems to have a segfault problem related
   with the commit of "libsemanage: patch for MCS/MLS in user files", which
   would be gone if we revert that commit or specify
   "disable-genhomedircon = true" in semanage.conf.
   
2. After using the "-P" option for semodule to preserve all tunables, the
   "preserve_tunables" flag file created in module store would be preserved
   after "make load" completes, resulting in builds after that would inherit
   same behavior until this flag file is mannually removed.
   
   Other options such as "-D/--disalbe_dontaudit" shares the same behavior.


Major differences from v0
---------------------------
1. As suggested by Chris, the mixture of tunables and booleans in one
   expression won't be allowed, so bail out with error rather than printing
   information message in bool_copy_callback() in link.c;

2. As suggested by Joshua, move the separate_tunables() from the very end of
   link to the very beginning of expand (and renamed to discard_tunables()
   now), this is for the interest of preserving the linked policy intact for
   analysis purpose;

3. As required by Dan and suggested by Joshua, add a new flag
   "preserve_tunables" in sepol_handle_t to save and pass a new option "-P"
   from semodule to the expand phase, so that all tunables would be treated
   as booleans and preserved in the raw policy for debug purpose.


Tests I've done
----------------
1. Apply below patchset for refpolicy to cope with toolchain:

   0001-Add-the-definition-of-the-boolean_policy-marcro.patch
   0002-user_ping-is-a-tunable-use-tunable_policy-for-it.patch
   0003-mmap_low_allowed-is-a-tunable-use-tunable_policy-for.patch
   0004-secure_mode_insmod-is-a-boolean-use-boolean_policy-f.patch

   Mostly these patches would add a new boolean_policy() macro and make
   the tunable_policy() macro use "tunable" keyword rather than "bool".

2. We can see the size of policy.X droped significantly from 466k to 316k.

3. With the checkpolicy tool, we can see there are only 4 booleans preserved in
   the raw policy:

   Choose:  f
   secure_mode : 0
   pppd_can_insmod : 0
   secure_mode_insmod : 0
   secure_mode_policyload : 0

4. So far the "console_login" tunable defaults to true, we can see the related
   type_change rules for console_device_t in its conditionals are available in
   the raw policy:

   11 rules match the search criteria.
   Number of enabled conditional rules: 0
   Number of disabled conditional rules: 0
   
   type_change auditadm_t console_device_t : chr_file user_tty_device_t;
   type_change dbadm_t console_device_t : chr_file user_tty_device_t;
   type_change guest_t console_device_t : chr_file user_tty_device_t;
   type_change logadm_t console_device_t : chr_file user_tty_device_t;
   type_change secadm_t console_device_t : chr_file user_tty_device_t;
   type_change staff_t console_device_t : chr_file user_tty_device_t;
   type_change sysadm_t console_device_t : chr_file user_tty_device_t;
   type_change unconfined_t console_device_t : chr_file user_tty_device_t;
   type_change user_t console_device_t : chr_file user_tty_device_t;
   type_change webadm_t console_device_t : chr_file user_tty_device_t;
   type_change xguest_t console_device_t : chr_file user_tty_device_t;

5. Re-build policy with console_login defaults to false, then all above
   type_change rules for console_device_t would be gone:

   0 rules match the search criteria.
   Number of enabled conditional rules: 0
   Number of disabled conditional rules: 0
   
   (And the raw policy's size would further goes down from 3163312 bytes
    to 3163180 bytes)
   
6. Specifiy the "-P" option for semodule to preserve all tunables:

   ls /usr/share/selinux/refpolicy/*.pp | grep -v base.pp | sudo /usr/sbin/semodule -P -s refpolicy -b /usr/share/selinux/refpolicy/base.pp

   And we can see that the size of raw policy would be back to 466k with all
   tunables preserved as booleans:

   cao@cao-laptop:/etc/selinux/refpolicy$ ls -lt policy/
   total 12240
   -rw-r--r--. 1 root root 4666684 2011-08-29 14:49 policy.24
   cao@cao-laptop:/etc/selinux/refpolicy$
   
   Choose:  f
   allow_ftpd_full_access : 0
   allow_zebra_write_config : 0
   cdrecord_read_content : 0
   fcron_crond : 0
   mmap_low_allowed : 0
   samba_share_fusefs : 0
   sepgsql_enable_users_ddl : 1
   allow_ftpd_use_cifs : 0
   allow_java_execstack : 0
   cron_can_relabel : 0
   openvpn_enable_homedirs : 0
   samba_export_all_ro : 0
   secure_mode : 0
   spamassassin_can_network : 0
   virt_use_sysfs : 0
   xserver_object_manager : 0
   allow_cvs_read_shadow : 0
   allow_gssd_read_tmp : 1
   allow_httpd_bugzilla_script_anon_write : 0
   fenced_can_network_connect : 0
   httpd_enable_ftp_server : 0
   httpd_use_nfs : 0
   nfs_export_all_ro : 0
   qemu_use_usb : 1
   user_dmesg : 0
   virt_use_nfs : 0
   xguest_mount_media : 1
   allow_httpd_munin_script_anon_write : 0
   allow_httpd_squid_script_anon_write : 0
   allow_mplayer_execstack : 0
   named_write_master_zones : 0
   portage_use_nfs : 0
   pppd_can_insmod : 0
   qemu_use_nfs : 1
   virt_use_samba : 0
   virt_use_usb : 1
   xend_run_blktap : 1
   allow_httpd_anon_write : 0
   allow_httpd_user_script_anon_write : 0
   allow_ssh_keysign : 0
   cobbler_anon_write : 0
   entropyd_use_audio : 0
   exim_can_connect_db : 0
   httpd_can_network_relay : 0
   samba_create_home_dirs : 0
   samba_enable_home_dirs : 0
   spamd_enable_home_dirs : 1
   telepathy_tcp_connect_generic_network_ports : 0
   use_lpd_server : 0
   user_direct_mouse : 0
   allow_httpd_mediawiki_script_anon_write : 0
   allow_httpd_prewikka_script_anon_write : 0
   allow_rsync_anon_write : 0
   clamd_use_jit : 0
   httpd_tty_comm : 0
   httpd_unified : 0
   init_upstart : 0
   qemu_full_network : 0
   qemu_use_comm : 0
   rsync_export_all_ro : 0
   secure_mode_insmod : 0
   squid_connect_any : 0
   user_ping : 0
   virt_use_comm : 0
   allow_execmod : 0
   httpd_use_gpg : 0
   samba_share_nfs : 0
   user_tcp_server : 0
   user_ttyfile_stat : 0
   virt_use_fusefs : 0
   allow_user_postgresql_connect : 0
   console_login : 0
   httpd_builtin_scripting : 0
   httpd_can_sendmail : 0
   httpd_enable_cgi : 0
   racoon_read_shadow : 0
   allow_ftpd_use_nfs : 0
   allow_httpd_mojomojo_script_anon_write : 0
   samba_run_unconfined : 0
   wine_mmap_zero_ignore : 0
   xen_use_nfs : 0
   allow_execheap : 0
   allow_execstack : 0
   allow_httpd_nagios_script_anon_write : 0
   allow_httpd_w3c_validator_script_anon_write : 0
   rgmanager_can_network_connect : 0
   samba_domain_controller : 0
   samba_export_all_rw : 0
   varnishd_connect_any : 0
   allow_kerberos : 0
   global_ssp : 0
   gpg_agent_env_file : 0
   httpd_dbus_avahi : 0
   mozilla_read_content : 0
   nfs_export_all_rw : 0
   sepgsql_unconfined_dbadm : 1
   sftpd_anon_write : 0
   webadm_manage_user_files : 0
   allow_httpd_apcupsd_cgi_script_anon_write : 0
   ftp_home_dir : 0
   httpd_enable_homedirs : 0
   httpd_ssi_exec : 0
   httpd_use_cifs : 0
   mysql_connect_any : 0
   pppd_for_user : 0
   qemu_use_cifs : 1
   sftpd_enable_homedirs : 0
   squid_use_tproxy : 0
   telepathy_connect_all_ports : 0
   xguest_connect_network : 1
   allow_httpd_awstats_script_anon_write : 0
   allow_httpd_cvs_script_anon_write : 0
   allow_httpd_git_script_anon_write : 0
   allow_httpd_smokeping_cgi_script_anon_write : 0
   allow_httpd_sys_script_anon_write : 0
   allow_saslauthd_read_shadow : 0
   allow_ypbind : 0
   sftpd_full_access : 0
   user_rw_noexattrfile : 0
   allow_ptrace : 0
   dbadm_manage_user_files : 0
   exim_manage_user_files : 0
   puppet_manage_all_files : 0
   secure_mode_policyload : 0
   tftp_anon_write : 0
   use_samba_home_dirs : 0
   xend_run_qemu : 1
   allow_mount_anyfile : 0
   allow_user_mysql_connect : 0
   dbadm_read_user_files : 0
   exim_read_user_files : 0
   httpd_can_network_connect : 0
   mail_read_content : 0
   smartmon_3ware : 0
   ssh_sysadm_login : 0
   webadm_read_user_files : 0
   xdm_sysadm_login : 0
   xguest_use_bluetooth : 1
   allow_execmem : 0
   allow_ftpd_anon_write : 0
   allow_httpd_cobbler_script_anon_write : 0
   allow_httpd_nutups_cgi_script_anon_write : 0
   allow_nfsd_anon_write : 0
   allow_polyinstantiation : 0
   allow_smbd_anon_write : 0
   allow_write_xshm : 0
   httpd_can_network_connect_db : 0
   privoxy_connect_any : 0
   tor_bind_all_unreserved_ports : 0
   use_nfs_home_dirs : 0
   vbetool_mmap_zero_ignore : 0
   
   Choose:
   
7. Monolithic policy builds ok:   
   cao@cao-laptop:/work/selinux/refpolicy$ sudo make policy
   ......
   cao@cao-laptop:/work/selinux/refpolicy$ ls -lt policy.24
   -rw-r--r--. 1 root root 3163312 2011-08-29 15:00 policy.24
   cao@cao-laptop:/work/selinux/refpolicy$

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-08-29  8:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-29  7:53 [v1 PATCH 2/7] Separate tunable from boolean during compile Harry Ciao
2011-08-29  7:53 ` [v1 PATCH 3/7] Write and read TUNABLE flags in related data structures Harry Ciao
2011-08-29  8:24   ` Harry Ciao
2011-08-29  7:53 ` [v1 PATCH 4/7] Copy and check the cond_bool_datum_t.flags during link Harry Ciao
2011-08-29  8:24   ` Harry Ciao
2011-08-29  7:53 ` [PATCH 5/7] Permanently discard disabled branches of tunables in expansion Harry Ciao
2011-08-29  8:24   ` Harry Ciao
2011-08-29  7:53 ` [v1 PATCH 6/7] Skip tunable identifier and cond_node_t " Harry Ciao
2011-08-29  8:24   ` Harry Ciao
2011-08-29  7:53 ` [v1 PATCH 7/7] Create a new preserve_tunables flag in sepol_handle_t Harry Ciao
2011-08-29  8:25   ` Harry Ciao
2011-08-29  8:22 ` [v1 PATCH 2/7] Separate tunable from boolean during compile Harry Ciao
  -- strict thread matches above, loose matches on Subject: below --
2011-08-29  8:20 v1 Discard unused tunables from raw policy Harry Ciao
2011-08-29  8:21 ` [v1 PATCH 6/7] Skip tunable identifier and cond_node_t in expansion Harry Ciao

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.