ofono: introduce dedicated SELinux domain ofono_t
PATCH 1/1 ofono: introduce dedicated SELinux domain ofono_t
Currently, the ofono daemon runs in the generic initrc_t domain. While functional, this configuration lacks proper process isolation and violates the principle of least privilege.
Define a dedicated domain (ofono_t) to confine the service, ensuring it operates in a restricted environment isolated from other init processes.
Grant the necessary permissions to resolve AVC denials observed during the transition to enforcing mode:
* DBus: Allow service registration on the system bus and communication
with org.bluez.
* Network: Allow net_admin capability and netlink socket creation
(route and kobject_uevent) for rmnet and udev handling.
* Filesystem: Authorize read access to configuration files in /etc
and /usr, and traversal of /sys and /run/udev.
* Logging: Allow write access to /dev/log for syslog integration.
--- policy/modules/services/ofono.fc | 1 + policy/modules/services/ofono.if | 1 + policy/modules/services/ofono.te | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 policy/modules/services/ofono.fc create mode 100644 policy/modules/services/ofono.if create mode 100644 policy/modules/services/ofono.te
policy/modules/services/ofono.fc new file +1 -0
@@ -0,0 +1 @@ +/usr/sbin/ofonod -- gen_context(system_u:object_r:ofono_exec_t,s0)
policy/modules/services/ofono.if new file +1 -0
@@ -0,0 +1 @@ +## <summary>ofono</summary>
policy/modules/services/ofono.te new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 42 lines · Wei Deng
Currently, the ofono daemon runs in the generic
initrc_tdomain. While functional, this configuration lacks proper process isolation and violates the principle of least privilege.Define a dedicated domain (
ofono_t) to confine the service, ensuring it operates in a restricted environment isolated from other init processes.Grant the necessary permissions to resolve AVC denials observed during the transition to enforcing mode:
* DBus: Allow service registration on the system bus and communication
withorg.bluez.
* Network: Allownet_admincapability and netlink socket creation
(route andkobject_uevent) for rmnet and udev handling.
* Filesystem: Authorize read access to configuration files in/etc
and/usr, and traversal of/sysand/run/udev.
* Logging: Allow write access to/dev/logfor syslog integration.Signed-off-by Wei Deng <[email protected]>--- policy/modules/services/ofono.fc | 1 + policy/modules/services/ofono.if | 1 + policy/modules/services/ofono.te | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)create mode 100644 policy/modules/services/ofono.fc create mode 100644 policy/modules/services/ofono.if create mode 100644 policy/modules/services/ofono.te
policy/modules/services/ofono.fc new file +1
-0@@ -0,0 +1 @@ +/usr/sbin/ofonod -- gen_context(system_u:object_r:ofono_exec_t,s0)policy/modules/services/ofono.if new file +0
-0
policy/modules/services/ofono.if line 1
Quoted 1 line
policy/modules/services/ofono.if new file +1
-0@@ -0,0 +1 @@ +## <summary>ofono</summary>
Please add something descriptive about ofono here (a sentence or two) so readers can know what ofono does without having to look it up.
Quoted 15 lines
policy/modules/services/ofono.te new file +9
-0@@ -0,0 +1,83 @@ +policy_module(ofono, 1.0) + +######################################## +# +# Declarations +# + +type ofono_t; +type ofono_exec_t;
policy/modules/services/ofono.te line 19
Quoted 10 lines
policy/modules/services/ofono.te new file +10
-0+ +init_daemon_domain(ofono_t, ofono_exec_t) + +######################################## +# +# Local Policy +# + +# 1. Self Rules (Capabilities & Sockets) +# --------------------------------------
Please remove these extra section titles here and below.
policy/modules/services/ofono.te line 31
Quoted 12 lines
policy/modules/services/ofono.te new file +12
-0+allow ofono_t self:capability net_admin; + +# Socket permissions +allow ofono_t self:bluetooth_socket create_stream_socket_perms; +allow ofono_t self:netlink_kobject_uevent_socket create_socket_perms; +allow ofono_t self:netlink_route_socket create_netlink_socket_perms; +allow ofono_t self:unix_dgram_socket { connect create write }; + +# 2. File System Access +# --------------------- +# Generic sysfs access using standard interface +dev_read_sysfs(ofono_t)
Which sysfs entries are read? We would like to tighten the controls on sysfs, so adding a coment here about what is read would be helpful, if possible.
policy/modules/services/ofono.te line 38
Quoted 6 lines
policy/modules/services/ofono.te new file +6
-0+# Read configuration files in /etc +files_read_etc_files(ofono_t) + +# Read files in /usr +files_read_usr_files(ofono_t) +allow ofono_t usr_t:file map;
This should not reference types that are not defined in this module. You should call an interface in the files module, creating an appropriate one if needed. This same change is needed several times below too.
Please see https://github.com/SELinuxProject/refpolicy/wiki/StyleGuide
Quoted 44 lines
policy/modules/services/ofono.te new file +44
-0+# Udev runtime access +gen_require(` + type udev_runtime_t; +') +allow ofono_t udev_runtime_t:dir search_dir_perms; +allow ofono_t udev_runtime_t:file read_file_perms; + +# 3. Logging +# ---------- +logging_send_syslog_msg(ofono_t) + +# Access to devlog +gen_require(` + type devlog_t; +') +allow ofono_t devlog_t:sock_file write_sock_file_perms; + +# 4. IPC / DBus / Network +# ----------------------- +# Connect to the system DBus +dbus_system_bus_client(ofono_t) + +gen_require(` + type system_dbusd_t; + type system_dbusd_runtime_t; + class dbus { acquire_svc send_msg }; +') + +# DBus specific service interactions +allow ofono_t system_dbusd_t:dbus { acquire_svc send_msg }; + +# Manual socket handling for system_dbusd +allow ofono_t system_dbusd_runtime_t:dir search_dir_perms; +allow ofono_t system_dbusd_runtime_t:sock_file write_sock_file_perms; + +# Bluetooth interactions via DBus +gen_require(` + type bluetooth_t; +') +allow bluetooth_t ofono_t:dbus send_msg; +allow ofono_t bluetooth_t:dbus send_msg; + +# Init interactions +init_dbus_chat(ofono_t)
Signature · 1 line
Chris PeBenito
Hi Chris PeBenito,
Thanks for your comments.
Quoted 30 lines · Christopher J. PeBenito
Quoted 29 lines · Wei Deng
Currently, the ofono daemon runs in the generic
initrc_tdomain. While functional, this configuration lacks proper process isolation and violates the principle of least privilege.Define a dedicated domain (
ofono_t) to confine the service, ensuring it operates in a restricted environment isolated from other init processes.Grant the necessary permissions to resolve AVC denials observed during the transition to enforcing mode:
* DBus: Allow service registration on the system bus and communication with
org.bluez.
* Network: Allownet_admincapability and netlink socket creation (route andkobject_uevent) for rmnet and udev handling. * Filesystem: Authorize read access to configuration files in/etcand/usr, and traversal of/sysand/run/udev.
* Logging: Allow write access to/dev/logfor syslog integration.Signed-off-by Wei Deng <[email protected]>---
policy/modules/services/ofono.fc | 1 + policy/modules/services/ofono.if | 1 + policy/modules/services/ofono.te | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)create mode 100644 policy/modules/services/ofono.fc create mode 100644 policy/modules/services/ofono.if create mode 100644 policy/modules/services/ofono.te
Quoted 16 lines
Quoted 13 lines
policy/modules/services/ofono.fc new file +1
-0@@ -0,0 +1 @@ +/usr/sbin/ofonod -- gen_context(system_u:object_r:ofono_exec_t,s0)policy/modules/services/ofono.if new file +0
-0policy/modules/services/ofono.if line 1
Quoted 1 line
policy/modules/services/ofono.if new file +1
-0@@ -0,0 +1 @@ +## <summary>ofono</summary>Please add something descriptive about ofono here (a sentence or two) so readers can know what ofono does without having to look it up.
OK, will add description about ofono here in the next patch.
Quoted 21 lines
Quoted 21 lines
policy/modules/services/ofono.te new file +13
-0@@ -0,0 +1,83 @@ +policy_module(ofono, 1.0) + +######################################## +# +# Declarations +# + +type ofono_t; +type ofono_exec_t; + +init_daemon_domain(ofono_t, ofono_exec_t) + +########################################
Quoted 8 lines
policy/modules/services/ofono.te line 19
Quoted 6 lines
policy/modules/services/ofono.te new file +6
-0+# +# Local Policy +# + +# 1. Self Rules (Capabilities & Sockets) +# --------------------------------------Please remove these extra section titles here and below.
OK, will remove.
Quoted 16 lines
Quoted 4 lines
policy/modules/services/ofono.te new file +2
-0+allow ofono_t self:capability net_admin; +policy/modules/services/ofono.te line 31
Quoted 10 lines
policy/modules/services/ofono.te new file +10
-0+# Socket permissions +allow ofono_t self:bluetooth_socket create_stream_socket_perms; +allow ofono_t self:netlink_kobject_uevent_socket create_socket_perms; +allow ofono_t self:netlink_route_socket create_netlink_socket_perms; +allow ofono_t self:unix_dgram_socket { connect create write }; + +# 2. File System Access +# --------------------- +# Generic sysfs access using standard interface +dev_read_sysfs(ofono_t)Which sysfs entries are read? We would like to tighten the controls on sysfs, so adding a coment here about what is read would be helpful, if possible.
Based on our testing and AVC analysis, ofono requires read access to generic sysfs_t entries for device discovery and enumeration. Specifically, it accesses:
- Bus traversal: Reading /sys/bus (to list available buses).
- Device Symlinks: Reading and resolving symlinks in /sys/bus/pci/devices/ (e.g., /sys/bus/pci/devices/0001:00:00.0).
- Device Properties: Reading uevent files within specific device paths (e.g., /sys/devices/platform/.../uevent) to identify hardware capabilities and driver binding.
Since these paths are labeled with the generic sysfs_t type, the dev_read_sysfs interface is necessary to allow this enumeration. I will add a comment to the policy clarifying that this is used for PCI/Platform device discovery and uevent reading.
Quoted 11 lines
policy/modules/services/ofono.te line 38
Quoted 8 lines
policy/modules/services/ofono.te new file +6
-0+# Read configuration files in /etc +files_read_etc_files(ofono_t) + +# Read files in /usr +files_read_usr_files(ofono_t) +allow ofono_t usr_t:file map;This should not reference types that are not defined in this module. You should call an interface in the files module, creating an appropriate one if needed. This same change is needed several times below too.
Quoted 2 lines
Please see https://github.com/SELinuxProject/refpolicy/wiki/StyleGuide
OK, thanks for your guide, will modify in the next patch.
Quoted 46 lines
Quoted 44 lines
policy/modules/services/ofono.te new file +44
-0+# Udev runtime access +gen_require(` + type udev_runtime_t; +') +allow ofono_t udev_runtime_t:dir search_dir_perms; +allow ofono_t udev_runtime_t:file read_file_perms; + +# 3. Logging +# ---------- +logging_send_syslog_msg(ofono_t) + +# Access to devlog +gen_require(` + type devlog_t; +') +allow ofono_t devlog_t:sock_file write_sock_file_perms; + +# 4. IPC / DBus / Network +# ----------------------- +# Connect to the system DBus +dbus_system_bus_client(ofono_t) + +gen_require(` + type system_dbusd_t; + type system_dbusd_runtime_t; + class dbus { acquire_svc send_msg }; +') + +# DBus specific service interactions +allow ofono_t system_dbusd_t:dbus { acquire_svc send_msg }; + +# Manual socket handling for system_dbusd +allow ofono_t system_dbusd_runtime_t:dir search_dir_perms; +allow ofono_t system_dbusd_runtime_t:sock_file write_sock_file_perms; + +# Bluetooth interactions via DBus +gen_require(` + type bluetooth_t; +') +allow bluetooth_t ofono_t:dbus send_msg; +allow ofono_t bluetooth_t:dbus send_msg; + +# Init interactions +init_dbus_chat(ofono_t)
Signature · 2 lines
Best Regards, Wei Deng