From 5d89abde998f80654cd8991d532329175864fcab Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 20 Mar 2019 15:36:26 -0700 Subject: [PATCH] Allow to getattr kmsg_device These denials occur on boot when android_get_control_file also changes from readlink() to realpath(), because realpath() will lstat() the given path. Some other domains (fastbootd, update_engine, etc.) also uses libcutils to write to kernel log, where android_get_control_file() is invoked, hence getattr is added to them as well. 04-28 06:15:22.290 618 618 I auditd : type=1400 audit(0.0:4): avc: denied { getattr } for comm="logd" path="/dev/kmsg" dev="tmpfs" ino=20917 scontext=u:r:logd:s0 tcontext=u:object_r:kmsg_device:s0 tclass=chr_file permissive=0 03-20 19:52:23.431 900 900 I auditd : type=1400 audit(0.0:7): avc: denied { getattr } for comm="android.hardwar" path="/dev/kmsg" dev="tmpfs" ino=20917 scontext=u:r:hal_health_default:s0 tcontext=u:object_r:kmsg_device:s0 tclass=chr_file permissive=0 ... 03-20 22:40:42.316 1 1 W init : type=1400 audit(0.0:33): avc: denied { getattr } for path="/dev/kmsg" dev="tmpfs" ino=21999 scontext=u:r:init:s0 tcontext=u:object_r:kmsg_device:s0 tclass=chr_file permissive=0 Test: no denials related to these Change-Id: I5263dd6b64c06fb092f3461858f57a1a09107429 --- public/fastbootd.te | 2 +- public/hal_health.te | 2 +- public/init.te | 2 +- public/logd.te | 2 +- public/update_engine.te | 2 +- public/update_verifier.te | 2 +- public/vdc.te | 2 +- public/vendor_init.te | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public/fastbootd.te b/public/fastbootd.te index 7b71c2cbd..d63af83ef 100644 --- a/public/fastbootd.te +++ b/public/fastbootd.te @@ -16,7 +16,7 @@ recovery_only(` allowxperm fastbootd functionfs:file ioctl { FUNCTIONFS_ENDPOINT_DESC }; # Log to serial - allow fastbootd kmsg_device:chr_file { open write }; + allow fastbootd kmsg_device:chr_file { open getattr write }; # battery info allow fastbootd sysfs_batteryinfo:file r_file_perms; diff --git a/public/hal_health.te b/public/hal_health.te index 019b523e1..dc7d0836e 100644 --- a/public/hal_health.te +++ b/public/hal_health.te @@ -21,7 +21,7 @@ r_dir_file(hal_health_server, sysfs_batteryinfo) wakelock_use(hal_health_server) # Write to /dev/kmsg -allow hal_health_server kmsg_device:chr_file w_file_perms; +allow hal_health_server kmsg_device:chr_file { getattr w_file_perms }; # Allow to use timerfd to wake itself up periodically to send health info. allow hal_health_server self:capability2 wake_alarm; diff --git a/public/init.te b/public/init.te index f5f42e7fb..739cc2ede 100644 --- a/public/init.te +++ b/public/init.te @@ -11,7 +11,7 @@ allow init tmpfs:chr_file { create setattr unlink rw_file_perms }; # # /dev/kmsg allow init tmpfs:chr_file relabelfrom; -allow init kmsg_device:chr_file { write relabelto }; +allow init kmsg_device:chr_file { getattr write relabelto }; # /dev/kmsg_debug userdebug_or_eng(` allow init kmsg_debug_device:chr_file { write relabelto }; diff --git a/public/logd.te b/public/logd.te index 6aac302d4..0cbefb43a 100644 --- a/public/logd.te +++ b/public/logd.te @@ -11,7 +11,7 @@ allow logd self:global_capability_class_set { setuid setgid setpcap sys_nice aud allow logd self:global_capability2_class_set syslog; allow logd self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_write }; allow logd kernel:system syslog_read; -allow logd kmsg_device:chr_file w_file_perms; +allow logd kmsg_device:chr_file { getattr w_file_perms }; allow logd system_data_file:{ file lnk_file } r_file_perms; allow logd pstorefs:dir search; allow logd pstorefs:file r_file_perms; diff --git a/public/update_engine.te b/public/update_engine.te index 65217266a..7bcaca640 100644 --- a/public/update_engine.te +++ b/public/update_engine.te @@ -13,7 +13,7 @@ allow update_engine self:global_capability_class_set { fowner sys_admin }; # denial. dontaudit update_engine self:global_capability_class_set fsetid; -allow update_engine kmsg_device:chr_file w_file_perms; +allow update_engine kmsg_device:chr_file { getattr w_file_perms }; allow update_engine update_engine_exec:file rx_file_perms; wakelock_use(update_engine); diff --git a/public/update_verifier.te b/public/update_verifier.te index 0a9090cd9..8d40cddcc 100644 --- a/public/update_verifier.te +++ b/public/update_verifier.te @@ -22,7 +22,7 @@ allow update_verifier sysfs_dm:file r_file_perms; allow update_verifier dm_device:blk_file r_file_perms; # Write to kernel message. -allow update_verifier kmsg_device:chr_file w_file_perms; +allow update_verifier kmsg_device:chr_file { getattr w_file_perms }; # Allow update_verifier to reboot the device. set_prop(update_verifier, powerctl_prop) diff --git a/public/vdc.te b/public/vdc.te index b59dcf682..e638e50a6 100644 --- a/public/vdc.te +++ b/public/vdc.te @@ -12,7 +12,7 @@ type vdc_exec, system_file_type, exec_type, file_type; allow vdc devpts:chr_file rw_file_perms; # vdc writes directly to kmsg during the boot process -allow vdc kmsg_device:chr_file w_file_perms; +allow vdc kmsg_device:chr_file { getattr w_file_perms }; # vdc talks to vold over Binder binder_use(vdc) diff --git a/public/vendor_init.te b/public/vendor_init.te index 6ed7b02d4..5a3e918ec 100644 --- a/public/vendor_init.te +++ b/public/vendor_init.te @@ -5,7 +5,7 @@ type vendor_init, domain, mlstrustedsubject; allow vendor_init init:unix_stream_socket { read write }; # Logging to kmsg -allow vendor_init kmsg_device:chr_file { open write }; +allow vendor_init kmsg_device:chr_file { open getattr write }; # Mount on /dev/usb-ffs/adb. allow vendor_init device:dir mounton;