Skip to contentSkip to conversation

alsactl policy

PATCH Martin Orr 2 participants 3 messages Sep 16, 2007 – Sep 18, 2007 SELinux security module

lore
Share & tools
lore

Martin Orr

author
#0 lore raw

Here's a new version of the patch I sent a while ago to add policy for alsactl. This is run from an init script to set set volume levels on boot. At least on Debian and Fedora, it is also run by udev when a sound card is detected.

modules/admin/alsa.te +22 -1
Index: policy/modules/admin/alsa.te
===================================================================
@@ -8,12 +8,18 @@
 
 type alsa_t;
 type alsa_exec_t;
-application_domain(alsa_t, alsa_exec_t)
+init_system_domain(alsa_t, alsa_exec_t)
 role system_r types alsa_t;
 
 type alsa_etc_rw_t;
 files_type(alsa_etc_rw_t)
 
+type alsa_var_lib_t;
+files_type(alsa_var_lib_t)
+
+type alsa_state_t;
+files_type(alsa_state_t)
+
 ########################################
 #
 # Local policy
@@ -30,9 +36,23 @@
 manage_lnk_files_pattern(alsa_t,alsa_etc_rw_t,alsa_etc_rw_t)
 
 files_read_etc_files(alsa_t)
+files_read_usr_files(alsa_t)
+files_search_pids(alsa_t)
 
+allow alsa_t alsa_state_t:file manage_file_perms;
+ifdef(`distro_debian',`
+	files_search_var_lib(alsa_t)
+	filetrans_pattern(alsa_t,alsa_var_lib_t,alsa_state_t,file)
+',`
+	files_etc_filetrans(alsa_t,alsa_state_t,file)
+')
+
+dev_read_sound(alsa_t)
+dev_write_sound(alsa_t)
+
 term_use_generic_ptys(alsa_t)
 term_dontaudit_use_unallocated_ttys(alsa_t)
+init_dontaudit_use_fds(alsa_t)
 
 libs_use_ld_so(alsa_t)
 libs_use_shared_libs(alsa_t)
@@ -43,6 +63,7 @@
 
 userdom_manage_unpriv_user_semaphores(alsa_t)
 userdom_manage_unpriv_user_shared_mem(alsa_t)
+userdom_search_generic_user_home_dirs(alsa_t)
 
 optional_policy(`
 	nscd_socket_use(alsa_t)
modules/admin/alsa.if +23 -0
Index: policy/modules/admin/alsa.if
===================================================================
@@ -74,3 +74,26 @@
 	read_files_pattern($1,alsa_etc_rw_t,alsa_etc_rw_t)
 	read_lnk_files_pattern($1,alsa_etc_rw_t,alsa_etc_rw_t)
 ')
+
+########################################
+## <summary>
+##	Read alsa state file.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`alsa_read_state',`
+	gen_require(`
+		type alsa_state_t, alsa_var_lib_t;
+	')
+	ifdef(`distro_debian',`
+		files_search_var_lib($1)
+		read_files_pattern($1,alsa_var_lib_t,alsa_state_t)
+	',`
+		files_search_etc($1)
+		allow $1 alsa_state_t:file read_file_perms;
+	')
+')
modules/admin/alsa.fc +6 -0
Index: policy/modules/admin/alsa.fc
===================================================================
@@ -1,4 +1,10 @@
 
 /etc/alsa/pcm(/.*)?		gen_context(system_u:object_r:alsa_etc_rw_t,s0)
 
+/etc/(alsa/)?asound\.state --	gen_context(system_u:object_r:alsa_state_t,s0)
+/var/lib/alsa		-d	gen_context(system_u:object_r:alsa_var_lib_t,s0)
+/var/lib/alsa/asound.state --	gen_context(system_u:object_r:alsa_state_t,s0)
+
 /usr/bin/ainit 		--	gen_context(system_u:object_r:alsa_exec_t,s0)
+/usr/sbin/alsactl	--	gen_context(system_u:object_r:alsa_exec_t,s0)
+/usr/bin/amixer		--	gen_context(system_u:object_r:alsa_exec_t,s0)
modules/system/udev.te +5 -0
Index: policy/modules/system/udev.te
===================================================================
@@ -190,6 +190,11 @@
 ')
 
 optional_policy(`
+	alsa_domtrans(udev_t)
+	alsa_read_state(udev_t)
+')
+
+optional_policy(`
 	brctl_domtrans(udev_t)
 ')
 

--
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.

#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 16 lines · Martin Orr

Here's a new version of the patch I sent a while ago to add policy for alsactl. This is run from an init script to set set volume levels on boot. At least on Debian and Fedora, it is also run by udev when a sound card is detected.

Index: policy/modules/admin/alsa.te
===================================================================

modules/admin/alsa.te +1 -1
@@ -8,12 +8,18 @@
 
 type alsa_t;
 type alsa_exec_t;
-application_domain(alsa_t, alsa_exec_t)
+init_system_domain(alsa_t, alsa_exec_t)
 role system_r types alsa_t;

modules/admin/alsa.te line 22

Quoted 10 lines
modules/admin/alsa.te +6 -0
 
 type alsa_etc_rw_t;
 files_type(alsa_etc_rw_t)
 
+type alsa_var_lib_t;
+files_type(alsa_var_lib_t)
+
+type alsa_state_t;
+files_type(alsa_state_t)
+

We already have alsa_etc_rw_t for this. So we could either change alsa_etc_rw_t to this context and typealias it or leave it as rw_t. Or alternatively just allow alsa to write to alsa_var_lib_t,

Fedora stores asound.state under etc. Although it probably would be better in var/lib

I have opened a bugzilla for Fedora to write their asound.state file there.

https://bugzilla.redhat.com/show_bug.cgi?id=293301

Quoted 28 lines
modules/admin/alsa.te +14 -0
 ########################################
 #
 # Local policy
@@ -30,9 +36,23 @@
 manage_lnk_files_pattern(alsa_t,alsa_etc_rw_t,alsa_etc_rw_t)
 
 files_read_etc_files(alsa_t)
+files_read_usr_files(alsa_t)
+files_search_pids(alsa_t)
 
+allow alsa_t alsa_state_t:file manage_file_perms;
+ifdef(`distro_debian',`
+	files_search_var_lib(alsa_t)
+	filetrans_pattern(alsa_t,alsa_var_lib_t,alsa_state_t,file)
+',`
+	files_etc_filetrans(alsa_t,alsa_state_t,file)
+')
+
+dev_read_sound(alsa_t)
+dev_write_sound(alsa_t)
+
 term_use_generic_ptys(alsa_t)
 term_dontaudit_use_unallocated_ttys(alsa_t)
+init_dontaudit_use_fds(alsa_t)
 
 libs_use_ld_so(alsa_t)
 libs_use_shared_libs(alsa_t)

modules/admin/alsa.te line 66

Quoted 4 lines
modules/admin/alsa.te +1 -0
@@ -43,6 +63,7 @@
 
 userdom_manage_unpriv_user_semaphores(alsa_t)
 userdom_manage_unpriv_user_shared_mem(alsa_t)
+userdom_search_generic_user_home_dirs(alsa_t)

Probably wrong interface moving forward. You probably need to allow it to search all non prived user home dirs.

Quoted 24 lines
modules/admin/alsa.te +0 -0
 optional_policy(`
 	nscd_socket_use(alsa_t)

Index: policy/modules/admin/alsa.if
===================================================================

modules/admin/alsa.if +13 -0
@@ -74,3 +74,26 @@
 	read_files_pattern($1,alsa_etc_rw_t,alsa_etc_rw_t)
 	read_lnk_files_pattern($1,alsa_etc_rw_t,alsa_etc_rw_t)
 ')
+
+########################################
+## <summary>
+##	Read alsa state file.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`alsa_read_state',`
+	gen_require(`

modules/admin/alsa.if line 99

Quoted 10 lines
modules/admin/alsa.if +10 -0
+		type alsa_state_t, alsa_var_lib_t;
+	')
+	ifdef(`distro_debian',`
+		files_search_var_lib($1)
+		read_files_pattern($1,alsa_var_lib_t,alsa_state_t)
+	',`
+		files_search_etc($1)
+		allow $1 alsa_state_t:file read_file_perms;
+	')
+')

This should change to read lib if you eliminate state_t.

modules/admin/alsa.fc line 7

Quoted 12 lines

Index: policy/modules/admin/alsa.fc
===================================================================

modules/admin/alsa.fc +4 -0
@@ -1,4 +1,10 @@
 
 /etc/alsa/pcm(/.*)?		gen_context(system_u:object_r:alsa_etc_rw_t,s0)
 
+/etc/(alsa/)?asound\.state --	gen_context(system_u:object_r:alsa_state_t,s0)
+/var/lib/alsa		-d	gen_context(system_u:object_r:alsa_var_lib_t,s0)
+/var/lib/alsa/asound.state --	gen_context(system_u:object_r:alsa_state_t,s0)
+

/var/lib/alsa(/.*)? gen_context(system_u:object_r:alsa_var_lib_t,s0)
Would be a lot less error prone.

modules/admin/alsa.fc line 9

Quoted 2 lines
modules/admin/alsa.fc +1 -0
 /usr/bin/ainit 		--	gen_context(system_u:object_r:alsa_exec_t,s0)
+/usr/sbin/alsactl	--	gen_context(system_u:object_r:alsa_exec_t,s0)

/sbin/alsactl on Fedora

Quoted 20 lines
modules/admin/alsa.fc +1 -0
+/usr/bin/amixer		--	gen_context(system_u:object_r:alsa_exec_t,s0)

Index: policy/modules/system/udev.te
===================================================================

modules/system/udev.te +5 -1
@@ -190,6 +190,11 @@
 ')
 
 optional_policy(`
+	alsa_domtrans(udev_t)
+	alsa_read_state(udev_t)
+')
+
+optional_policy(`
 	brctl_domtrans(udev_t)
 ')
 
 
--
Quoted 3 lines

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.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFG7o1wrlYvE4MpobMRApLpAJsEDfZaayv9e1+cULOZpebxwf0qMQCg1Mn9 3l5j9MGDoafTx8oXRjFAK7s=
=u/Cr
-----END PGP SIGNATURE-----

--
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.

author
#2 lore raw
Quoted 12 lines · Daniel J Walsh

modules/admin/alsa.te line 22

Quoted 9 lines

type alsa_etc_rw_t;
files_type(alsa_etc_rw_t)

modules/admin/alsa.te +6 -0
+type alsa_var_lib_t;
+files_type(alsa_var_lib_t)
+
+type alsa_state_t;
+files_type(alsa_state_t)
+

We already have alsa_etc_rw_t for this. So we could either change alsa_etc_rw_t to this context and typealias it or leave it as rw_t. Or alternatively just allow alsa to write to alsa_var_lib_t,

OK, I thought that alsa_etc_rw_t was for something else. Since I don't have any /etc/alsa/pcm directory, I didn't know what it was for.

Quoted 6 lines

Fedora stores asound.state under etc. Although it probably would be better in var/lib

I have opened a bugzilla for Fedora to write their asound.state file there.

https://bugzilla.redhat.com/show_bug.cgi?id=293301

There is a bug in the upstream BTS to change this as well:
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=3128

Thanks for your reviewing time,

Signature · 6 lines
Martin Orr

--
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.