Skip to contentSkip to conversation

Introduce allow_bluetooth boolean

PATCH In review Lukas Vrabec 2 participants 3 messages Apr 26, 2019 – Apr 27, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Introduce allow_bluetooth boolean

Because of new bluetooth_socket which is part of extended_socket_class policy capability, it's possible to control which SELinux domains can use bluetooth wireless technology. Default value of the boolean is turned off.

---
 policy/global_tunables               | 7 +++++++
 policy/modules/admin/netutils.te     | 4 ++++
 policy/modules/services/arpwatch.te  | 4 ++++
 policy/modules/services/bluetooth.if | 4 ++++
 policy/modules/services/bluetooth.te | 4 ++++
 policy/modules/services/ntop.te      | 4 ++++
 policy/modules/system/init.te        | 4 ++++
 policy/modules/system/userdomain.if  | 8 ++++++++
 8 files changed, 39 insertions(+)
policy/global_tunables +7 -0
index affc020f..69b356e2 100644
@@ -4,6 +4,13 @@
 # file should be used.
 #
 
+## <desc>
+## <p>
+## Allow all system processes and Linux users to use bluetooth wireless technology.
+## </p>
+## </desc>
+gen_tunable(allow_bluetooth,false)
+
 ## <desc>
 ## <p>
 ## Allow unconfined executables to make their heap memory executable.  Doing this is a really bad idea. Probably indicates a badly coded executable, but could indicate an attack. This executable should be reported in bugzilla
policy/modules/admin/netutils.te +4 -0
index 46560a09..b4e66e8f 100644
@@ -99,6 +99,10 @@ optional_policy(`
 	xen_append_log(netutils_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow netutils_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 ########################################
 #
 # Ping local policy
policy/modules/services/arpwatch.te +4 -0
index 87aed96f..7e817035 100644
@@ -77,6 +77,10 @@ miscfiles_read_localization(arpwatch_t)
 userdom_dontaudit_search_user_home_dirs(arpwatch_t)
 userdom_dontaudit_use_unpriv_user_fds(arpwatch_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow arpwatch_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	mta_send_mail(arpwatch_t)
 ')
policy/modules/services/bluetooth.if +4 -0
index dc61988c..5fda4f69 100644
@@ -68,6 +68,10 @@ interface(`bluetooth_stream_connect',`
 	files_search_pids($1)
 	allow $1 bluetooth_t:socket rw_socket_perms;
 	stream_connect_pattern($1, bluetooth_var_run_t, bluetooth_var_run_t, bluetooth_t)
+
+    tunable_policy(`deny_bluetooth',`',`
+        allow $1 bluetooth_t:bluetooth_socket rw_socket_perms;
+    ')
 ')
 
 ########################################
policy/modules/services/bluetooth.te +4 -0
index 45e5a361..fa9daa48 100644
@@ -133,6 +133,10 @@ userdom_dontaudit_use_unpriv_user_fds(bluetooth_t)
 userdom_dontaudit_use_user_terminals(bluetooth_t)
 userdom_dontaudit_search_user_home_dirs(bluetooth_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow bluetooth_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 optional_policy(`
 	dbus_system_bus_client(bluetooth_t)
 	dbus_connect_system_bus(bluetooth_t)
policy/modules/services/ntop.te +4 -0
index 178bbb1d..50157b88 100644
@@ -96,6 +96,10 @@ miscfiles_read_localization(ntop_t)
 userdom_dontaudit_use_unpriv_user_fds(ntop_t)
 userdom_dontaudit_search_user_home_dirs(ntop_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow ntop_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	apache_read_sys_content(ntop_t)
 ')
policy/modules/system/init.te +4 -0
index 00f36c99..26eff7bc 100644
@@ -523,6 +523,10 @@ optional_policy(`
 	unconfined_domain(init_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow init_t self:bluetooth_socket { create_socket_perms listen };
+')
+
 ########################################
 #
 # Init script local policy
policy/modules/system/userdomain.if +8 -0
index 5221bd13..50d2e080 100644
@@ -1189,6 +1189,10 @@ template(`userdom_unpriv_user_template', `
 		corenet_udp_bind_generic_port($1_t)
 	')
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_socket_perms;
+    ')
+
 	optional_policy(`
 		netutils_run_ping_cond($1_t, $1_r)
 		netutils_run_traceroute_cond($1_t, $1_r)
@@ -1362,6 +1366,10 @@ template(`userdom_admin_user_template',`
 	userdom_manage_user_home_content_sockets($1_t)
 	userdom_user_home_dir_filetrans_user_home_content($1_t, { dir file lnk_file fifo_file sock_file })
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_stream_socket_perms;
+    ')
+
 	optional_policy(`
 		postgresql_unconfined($1_t)
 	')
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · Lukas Vrabec

Because of new bluetooth_socket which is part of extended_socket_class policy capability, it's possible to control which SELinux domains can use bluetooth wireless technology. Default value of the boolean is turned off.

Two observations:

1. are you using 4 spaces ident instead of 8 space tab indentation?
2. this rule is questionable:
allow init_t self:bluetooth_socket { create_socket_perms listen };

Quoted 150 lines
---
 policy/global_tunables               | 7 +++++++
 policy/modules/admin/netutils.te     | 4 ++++
 policy/modules/services/arpwatch.te  | 4 ++++
 policy/modules/services/bluetooth.if | 4 ++++
 policy/modules/services/bluetooth.te | 4 ++++
 policy/modules/services/ntop.te      | 4 ++++
 policy/modules/system/init.te        | 4 ++++
 policy/modules/system/userdomain.if  | 8 ++++++++
 8 files changed, 39 insertions(+)
policy/global_tunables +7 -0
index affc020f..69b356e2 100644
@@ -4,6 +4,13 @@
 # file should be used.
 #
 
+## <desc>
+## <p>
+## Allow all system processes and Linux users to use bluetooth wireless technology.
+## </p>
+## </desc>
+gen_tunable(allow_bluetooth,false)
+
 ## <desc>
 ## <p>
 ## Allow unconfined executables to make their heap memory executable.  Doing this is a really bad idea. Probably indicates a badly coded executable, but could indicate an attack. This executable should be reported in bugzilla
policy/modules/admin/netutils.te +4 -0
index 46560a09..b4e66e8f 100644
@@ -99,6 +99,10 @@ optional_policy(`
 	xen_append_log(netutils_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow netutils_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 ########################################
 #
 # Ping local policy
policy/modules/services/arpwatch.te +4 -0
index 87aed96f..7e817035 100644
@@ -77,6 +77,10 @@ miscfiles_read_localization(arpwatch_t)
 userdom_dontaudit_search_user_home_dirs(arpwatch_t)
 userdom_dontaudit_use_unpriv_user_fds(arpwatch_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow arpwatch_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	mta_send_mail(arpwatch_t)
 ')
policy/modules/services/bluetooth.if +4 -0
index dc61988c..5fda4f69 100644
@@ -68,6 +68,10 @@ interface(`bluetooth_stream_connect',`
 	files_search_pids($1)
 	allow $1 bluetooth_t:socket rw_socket_perms;
 	stream_connect_pattern($1, bluetooth_var_run_t, bluetooth_var_run_t, bluetooth_t)
+
+    tunable_policy(`deny_bluetooth',`',`
+        allow $1 bluetooth_t:bluetooth_socket rw_socket_perms;
+    ')
 ')
 
 ########################################
policy/modules/services/bluetooth.te +4 -0
index 45e5a361..fa9daa48 100644
@@ -133,6 +133,10 @@ userdom_dontaudit_use_unpriv_user_fds(bluetooth_t)
 userdom_dontaudit_use_user_terminals(bluetooth_t)
 userdom_dontaudit_search_user_home_dirs(bluetooth_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow bluetooth_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 optional_policy(`
 	dbus_system_bus_client(bluetooth_t)
 	dbus_connect_system_bus(bluetooth_t)
policy/modules/services/ntop.te +4 -0
index 178bbb1d..50157b88 100644
@@ -96,6 +96,10 @@ miscfiles_read_localization(ntop_t)
 userdom_dontaudit_use_unpriv_user_fds(ntop_t)
 userdom_dontaudit_search_user_home_dirs(ntop_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow ntop_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	apache_read_sys_content(ntop_t)
 ')
policy/modules/system/init.te +4 -0
index 00f36c99..26eff7bc 100644
@@ -523,6 +523,10 @@ optional_policy(`
 	unconfined_domain(init_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow init_t self:bluetooth_socket { create_socket_perms listen };
+')
+
 ########################################
 #
 # Init script local policy
policy/modules/system/userdomain.if +8 -0
index 5221bd13..50d2e080 100644
@@ -1189,6 +1189,10 @@ template(`userdom_unpriv_user_template', `
 		corenet_udp_bind_generic_port($1_t)
 	')
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_socket_perms;
+    ')
+
 	optional_policy(`
 		netutils_run_ping_cond($1_t, $1_r)
 		netutils_run_traceroute_cond($1_t, $1_r)
@@ -1362,6 +1366,10 @@ template(`userdom_admin_user_template',`
 	userdom_manage_user_home_content_sockets($1_t)
 	userdom_user_home_dir_filetrans_user_home_content($1_t, { dir file lnk_file fifo_file sock_file })
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_stream_socket_perms;
+    ')
+
 	optional_policy(`
 		postgresql_unconfined($1_t)
 	')
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
#2 lore raw
Quoted 11 lines · Dominick Grift
Quoted 4 lines · Lukas Vrabec

Because of new bluetooth_socket which is part of extended_socket_class policy capability, it's possible to control which SELinux domains can use bluetooth wireless technology. Default value of the boolean is turned off.

Two observations:

1. are you using 4 spaces ident instead of 8 space tab indentation?
2. this rule is questionable:
allow init_t self:bluetooth_socket { create_socket_perms listen };

I looked into this and tracked the above down to this:

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

In that report the bluetoothd executable file was mislabeled and that is why it ended up in init_t.

Please address the indents and remove the above rule.

Quoted 156 lines
Quoted 151 lines
---
 policy/global_tunables               | 7 +++++++
 policy/modules/admin/netutils.te     | 4 ++++
 policy/modules/services/arpwatch.te  | 4 ++++
 policy/modules/services/bluetooth.if | 4 ++++
 policy/modules/services/bluetooth.te | 4 ++++
 policy/modules/services/ntop.te      | 4 ++++
 policy/modules/system/init.te        | 4 ++++
 policy/modules/system/userdomain.if  | 8 ++++++++
 8 files changed, 39 insertions(+)
policy/global_tunables +7 -0
index affc020f..69b356e2 100644
@@ -4,6 +4,13 @@
 # file should be used.
 #
 
+## <desc>
+## <p>
+## Allow all system processes and Linux users to use bluetooth wireless technology.
+## </p>
+## </desc>
+gen_tunable(allow_bluetooth,false)
+
 ## <desc>
 ## <p>
 ## Allow unconfined executables to make their heap memory executable.  Doing this is a really bad idea. Probably indicates a badly coded executable, but could indicate an attack. This executable should be reported in bugzilla
policy/modules/admin/netutils.te +4 -0
index 46560a09..b4e66e8f 100644
@@ -99,6 +99,10 @@ optional_policy(`
 	xen_append_log(netutils_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow netutils_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 ########################################
 #
 # Ping local policy
policy/modules/services/arpwatch.te +4 -0
index 87aed96f..7e817035 100644
@@ -77,6 +77,10 @@ miscfiles_read_localization(arpwatch_t)
 userdom_dontaudit_search_user_home_dirs(arpwatch_t)
 userdom_dontaudit_use_unpriv_user_fds(arpwatch_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow arpwatch_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	mta_send_mail(arpwatch_t)
 ')
policy/modules/services/bluetooth.if +4 -0
index dc61988c..5fda4f69 100644
@@ -68,6 +68,10 @@ interface(`bluetooth_stream_connect',`
 	files_search_pids($1)
 	allow $1 bluetooth_t:socket rw_socket_perms;
 	stream_connect_pattern($1, bluetooth_var_run_t, bluetooth_var_run_t, bluetooth_t)
+
+    tunable_policy(`deny_bluetooth',`',`
+        allow $1 bluetooth_t:bluetooth_socket rw_socket_perms;
+    ')
 ')
 
 ########################################
policy/modules/services/bluetooth.te +4 -0
index 45e5a361..fa9daa48 100644
@@ -133,6 +133,10 @@ userdom_dontaudit_use_unpriv_user_fds(bluetooth_t)
 userdom_dontaudit_use_user_terminals(bluetooth_t)
 userdom_dontaudit_search_user_home_dirs(bluetooth_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow bluetooth_t self:bluetooth_socket create_stream_socket_perms;
+')
+
 optional_policy(`
 	dbus_system_bus_client(bluetooth_t)
 	dbus_connect_system_bus(bluetooth_t)
policy/modules/services/ntop.te +4 -0
index 178bbb1d..50157b88 100644
@@ -96,6 +96,10 @@ miscfiles_read_localization(ntop_t)
 userdom_dontaudit_use_unpriv_user_fds(ntop_t)
 userdom_dontaudit_search_user_home_dirs(ntop_t)
 
+tunable_policy(`allow_bluetooth',`
+    allow ntop_t self:bluetooth_socket create_socket_perms;
+')
+
 optional_policy(`
 	apache_read_sys_content(ntop_t)
 ')
policy/modules/system/init.te +4 -0
index 00f36c99..26eff7bc 100644
@@ -523,6 +523,10 @@ optional_policy(`
 	unconfined_domain(init_t)
 ')
 
+tunable_policy(`allow_bluetooth',`
+    allow init_t self:bluetooth_socket { create_socket_perms listen };
+')
+
 ########################################
 #
 # Init script local policy
policy/modules/system/userdomain.if +8 -0
index 5221bd13..50d2e080 100644
@@ -1189,6 +1189,10 @@ template(`userdom_unpriv_user_template', `
 		corenet_udp_bind_generic_port($1_t)
 	')
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_socket_perms;
+    ')
+
 	optional_policy(`
 		netutils_run_ping_cond($1_t, $1_r)
 		netutils_run_traceroute_cond($1_t, $1_r)
@@ -1362,6 +1366,10 @@ template(`userdom_admin_user_template',`
 	userdom_manage_user_home_content_sockets($1_t)
 	userdom_user_home_dir_filetrans_user_home_content($1_t, { dir file lnk_file fifo_file sock_file })
 
+    tunable_policy(`allow_bluetooth',`
+        allow $1_t self:bluetooth_socket create_stream_socket_perms;
+    ')
+
 	optional_policy(`
 		postgresql_unconfined($1_t)
 	')
Signature · 1 line
2.20.1
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift