# OpenHarmony SELinux Checké—®é¢˜å¤„ç†æŒ‡å¯¼ ## 概述 为规范OpenHarmony SELinuxç–ç•¥é…置,针对neverallowæ£€æŸ¥æ— æ³•è¦†ç›–åˆ°çš„åœºæ™¯å’Œäººå·¥å®¡æ ¸å®¹æ˜“é—æ¼çš„问题,OpenHarmonyæä¾›äº†ä¸€å¥—SELinuxç–略检查工具。 ## file_contextsä¸data分区二级目录使用æ£åˆ™è¡¨è¾¾å¼æ£€æŸ¥ ### 检查说明 data分区为å¯è¯»å†™åˆ†åŒºï¼Œå¤§éƒ¨åˆ†è¿›ç¨‹çš„æ•°æ®æ–‡ä»¶å’Œç”¨æˆ·çš„æ–‡ä»¶å˜æ”¾åœ¨data分区,文件数é‡åºžå¤§ï¼Œå®¹æ˜“出现碎片化问题。为é¿å…dataåˆ†åŒºæ‰“æ ‡ç¾æ€§èƒ½é—®é¢˜ï¼Œéœ€è¦é™åˆ¶data分区的二级目录ä¸èƒ½å˜åœ¨æ£åˆ™è¡¨è¾¾å¼ï¼Œè¯¥æ£€æŸ¥ä¸»è¦æ‰«æ`file_contexts`文件。 ### 编译拦截 在`file_contexts`ä¸ï¼Œdata分区二级目录使用æ£åˆ™è¡¨è¾¾å¼ï¼Œä¼šè§¦å‘编译报错,关键报错信æ¯`Regex is not allowed in the secondary directory under data`,报错如下: ```text Regex is not allowed in the secondary directory under data, check '/data/log(/.*)?' failed in file out/rk3568/obj/base/security/selinux_adapter/file_contexts:214 There are two solutions: 1. Add '/data/log(/.*)?' to whitelist file 'data_regex_whitelist.txt' under 'base/security/selinux_adapter/sepolicy'; 2. Modify '/data/log(/.*)?' to remove the regular expression ``` ### æ‹¦æˆªåŽŸå› è¯´æ˜Žä»¥ä¸‹`file_contexts`ä¸çš„å®šä¹‰æ˜¯éžæ³•çš„ï¼Œå› ä¸º`log(/.*)?`是æ£åˆ™è¡¨è¾¾å¼ï¼Œä¸”在data的第二级目录: ```text /data/log(/.*)? u:object_r:data_log:s0 ``` ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šå°†ä¸æ»¡è¶³çš„路径`/data/log/(.*)?`æ·»åŠ åˆ°`//base/security/selinux_adapter/sepolicy/`下的白å啿–‡ä»¶`data_regex_whitelist.txt`ä¸ï¼Œä¿®æ”¹è¯¥ç™½åå•需è¦è¯„估安全性和åˆç†æ€§ï¼Œå®¡æ…Žä¿®æ”¹ã€‚ - æ–¹å¼äºŒï¼šä¿®æ”¹data二级目录ä¸ä¸åˆç†çš„æ£åˆ™è¡¨è¾¾å¼ï¼Œä»¥æ»¡è¶³è¦æ±‚,例如,改æˆä»¥ä¸‹å½¢å¼ï¼Œåˆ™æ˜¯åˆæ³•的: ```text /data/log u:object_r:data_log:s0 /data/log/(.*)? u:object_r:data_log:s0 ``` ## file_contextsä¸ä½¿ç”¨ä¸€çº§ç›®å½•æ ‡ç¾æ£€æŸ¥ ### 检查说明 ä¸€çº§ç›®å½•æ ‡ç¾æ˜¯æŒ‡æ ¹è·¯å¾„下的åç›®å½•ä½¿ç”¨çš„æ ‡ç¾ï¼Œä¸»è¦æœ‰ï¼š ```text u:object_r:dev_file:s0 u:object_r:etc_file:s0 u:object_r:lib_file:s0 u:object_r:config_file:s0 u:object_r:updater_file:s0 u:object_r:system_file:s0 u:object_r:sys_prod_file:s0 u:object_r:chip_prod_file:s0 u:object_r:vendor_file:s0 u:object_r:data_file:s0 u:object_r:module_update_file:s0 ``` `file_contexts`ä¸ç¦æ¢ä½¿ç”¨ä¸€çº§ç›®å½•æ ‡ç¾æ¥å®šä¹‰è·¯å¾„æ ‡ç¾ï¼Œé¿å…é…ç½®ä¸åˆç†çš„SELinuxæƒé™ï¼Œå¯¹æ ¹è·¯å¾„çš„å目录产生影å“,构æˆå®‰å…¨éšæ‚£ã€‚ ### 编译拦截 在`file_contexts`é…ç½®ä¸ï¼Œä¸åˆç†çš„ä½¿ç”¨ä¸€çº§ç›®å½•æ ‡ç¾ï¼Œä¼šè§¦å‘编译报错,关键报错信æ¯`partition label is not allow to use`,报错如下: ``` partition label is not allow to use, check '/data/log u:object_r:data_file:s0' failed in file out/rk3568/obj/base/security/selinux_adapter/file_contexts:213 There are two solutions: 1. Add '/data/log u:object_r:data_file:s0' to whitelist file 'partition_label_use_whitelist.txt' under 'base/security/selinux_adapter/sepolicy'; 2. Change '/data/log u:object_r:data_file:s0' to avoid using label in ['u:object_r:dev_file:s0', 'u:object_r:etc_file:s0', 'u:object_r:lib_file:s0', 'u:object_r:config_file:s0', 'u:object_r:updater_file:s0', 'u:object_r:system_file:s0', 'u:object_r:sys_prod_file:s0', 'u:object_r:chip_prod_file:s0', 'u:object_r:vendor_file:s0', 'u:object_r:data_file:s0', 'u:object_r:module_update_file:s0'] ``` ### æ‹¦æˆªåŽŸå› è¯´æ˜Žä»¥ä¸‹`file_contexts`ä¸çš„å®šä¹‰æ˜¯éžæ³•çš„ï¼Œå› ä¸ºä¸º`/data/log`é…ç½®äº†æ ‡ç¾`u:object_r:data_file:s0`ï¼Œè¯¥æ ‡ç¾å±žäºŽä¸€çº§ç›®å½•æ ‡ç¾ï¼š ```text /data/log u:object_r:data_file:s0 ``` ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šå°†ä¸æ»¡è¶³çš„è·¯å¾„åŠæ ‡ç¾`'/data/log u:object_r:data_file:s0'`æ·»åŠ åˆ°`//base/security/selinux_adapter/sepolicy/`下的白å啿–‡ä»¶`partition_label_use_whitelist.txt`ä¸ï¼Œä¿®æ”¹è¯¥ç™½åå•需è¦è¯„估安全性和åˆç†æ€§ï¼Œå®¡æ…Žä¿®æ”¹ã€‚ - æ–¹å¼äºŒï¼šæ›´æ”¹`/data/log`çš„ä¸åˆç†æ ‡ç¾ï¼Œä½¿ç”¨è‡ªå®šä¹‰æ ‡ç¾ï¼Œä»¥æ»¡è¶³è¦æ±‚,例如,改æˆä»¥ä¸‹å½¢å¼ï¼Œåˆ™æ˜¯åˆæ³•的: ```text /data/log u:object_r:data_log:s0 ``` ## 使用高å±ç»„åˆæƒé™æ£€æŸ¥ ### 检查说明 当æŸä¸€å¯¹ä¸»ä½“å’Œå®¢ä½“åŒæ—¶æ‹¥æœ‰å‡ 个ä¸åŒçš„SELinuxæƒé™æ—¶ï¼Œå¯èƒ½å½¢æˆä¸€ç§æ”»å‡»è·¯å¾„ã€‚æ¤æ£€æŸ¥é¡¹ä¸»è¦æ£€æŸ¥user版本ç–略和开å‘者模å¼ç–略。检查项的é…置文件在`base/security/selinux_adapter/scripts/selinux_check/config/perm_group.json`,形å¼å¦‚下: ```json { "check_rules": [ { "name": "execute and execute_no_trans", "description": "process label should transform while execute a file", "perm_group": [ { "tclass": "*", "perm": "execute execute_no_trans" } ] } ] } ``` å…¶ä¸ï¼Œ`check_rules`表示所有æƒé™ç»„åˆæ£€æŸ¥é¡¹åˆ—表,æ¯ä¸€ä¸ªæ£€æŸ¥é¡¹ä¸åŒ…括`name`ã€`description`ã€`perm_group`ä¸‰ä¸ªå—æ®µï¼Œ`name`表示检查项的å称,`description`表示检查项æè¿°ï¼Œ`perm_group`表示详细的å¯èƒ½å˜åœ¨æ”»å‡»è·¯å¾„çš„æƒé™åˆ—表,其ä¸`tclass`表示æ“作类型,`perm`表示该æ“作类型下的æƒé™ï¼Œ`tclass`å¯ä»¥å¡«å…·ä½“æ“作类型,也å¯ä»¥å¡«`*`,填`*`表示会检查所有包括`perm`䏿ƒé™çš„æ“ä½œç±»åž‹ã€‚ ### 编译拦截 ä¸åˆç†çš„æƒé™é…置,会触å‘编译报错,关键报错信æ¯`check rule 'xxx' in user mode failed`,这里的`xxx`表示被拦截的检查项`name`,报错如下: ```text check rule 'execute and execute_no_trans' in user mode failed, process label should transform while execute a file violation list (scontext tcontext): appspawn appspawn_exec There are two solutions: 1. Add the above list to whitelist file 'perm_group_whitelist.json' under 'base/security/selinux_adapter/sepolicy' in 'user' part of 'execute and execute_no_trans' 2. Change the policy to avoid violating rule 'execute and execute_no_trans' check rule 'execute and execute_no_trans' in developer mode failed, process label should transform while execute a file violation list (scontext tcontext): appspawn appspawn_exec There are two solutions: 3. Add the above list to whitelist file 'perm_group_whitelist.json' under 'base/security/selinux_adapter/sepolicy' in 'developer' part of 'execute and execute_no_trans' 4. Change the policy to avoid violating rule 'execute and execute_no_trans' ``` ### æ‹¦æˆªåŽŸå› ä¸Šè¿°æŠ¥é”™æ˜¯å› ä¸ºï¼Œåœ¨userç–略和开å‘者ç–ç•¥ä¸ï¼Œä¸»ä½“`appspawn`和客体`appspawn_exec`ï¼Œéƒ½åŒæ—¶æ‹¥æœ‰`execute`å’Œ`execute_no_trans`æƒé™ï¼š ```text allow appspawn appspawn_exec:file { execute execute_no_trans }; ``` ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šå°†ä¸åˆç†çš„ä¸»ä½“å’Œå®¢ä½“ç»„åˆæ·»åŠ åˆ°`//base/security/selinux_adapter/sepolicy/`下的白å啿–‡ä»¶`perm_group_whitelist.json`ä¸ï¼Œä¿®æ”¹è¯¥ç™½åå•需è¦è¯„ä¼°åˆç†æ€§ï¼Œå®¡æ…Žæ·»åŠ ï¼Œè¯¥æ–‡ä»¶å¦‚ä¸‹ï¼š ```text { "whitelist": [ { "name": "execute and execute_no_trans", "user": [ "appspawn appspawn_exec" ], "developer": [ ] } ] } ``` å…¶ä¸ï¼Œ`whitelist`表示所有æƒé™ç»„åˆæ£€æŸ¥é¡¹ç™½åå•列表,æ¯ä¸€ä¸ªæ£€æŸ¥é¡¹ç™½åå•ä¸åŒ…括`name`ã€`user`ã€`developer`ä¸‰ä¸ªå—æ®µï¼Œ`name`表示检查项白åå•çš„å称,与检查项`name`对应,`user`表示检查项白åå•ä¸çš„`user`ç–略白åå•,`developer`表示检查项白åå•ä¸çš„å¼€å‘者ç–略白åå•。白åå•的填写ä½ç½®å‚考下表: **表1** ä¸»å®¢ä½“ç»„åˆæƒé™æ£€æŸ¥é¡¹ç™½åå•å—æ®µä¸ŽæŠ¥é”™å¯¹åº”关系 | è¿åuserç–ç•¥ | è¿ådeveloperç–ç•¥ | 写入嗿®µä½ç½® | | -------- | -------- | -------- | | 是 | 是 | user | | å¦ | 是 | developer | | 是 | å¦ | userï¼Œä¸”éœ€åˆ é™¤å½“å‰ä¸»å®¢ä½“在developerå—æ®µä¸çš„白åå• | - æ–¹å¼äºŒï¼šä¿®æ”¹ä¸åˆç†çš„ç–ç•¥ï¼Œä»¥æ»¡è¶³è¦æ±‚,例如,更改方案,é¿å…åŒæ—¶ç”³è¯·è¿™ä¸¤ä¸ªæƒé™ã€‚ ### åˆ é™¤å†—ä½™çš„ç™½åå• å½“æ•´æ”¹äº†ä¸åˆç†çš„æƒé™ç»„åˆé…ç½®åŽï¼Œåˆ 除了ä¸åˆç†çš„ç–ç•¥ï¼Œä½†æ˜¯æœªåŒæ—¶åˆ 除白å啿—¶ï¼Œä¹Ÿä¼šè§¦å‘编译报错,关键报错信æ¯`remove the following unnecessary whitelists in rule 'xxx' part 'user'`,这里的`xxx`表示被拦截的检查项`name`,报错如下: ```text check rule 'execute and execute_no_trans' failed in whitelist file 'perm_group_whitelist.json' remove the following unnecessary whitelists in rule 'execute and execute_no_trans' part 'user': appspawn appspawn_exec check rule 'execute and execute_no_trans' failed in whitelist file 'perm_group_whitelist.json' remove the following unnecessary whitelists in rule 'execute and execute_no_trans' part 'developer': appspawn appspawn_exec ``` 需è¦åŒæ—¶åˆ 除白åå•,将`//base/security/selinux_adapter/sepolicy/`下的白å啿–‡ä»¶`perm_group_whitelist.json`ä¸çš„相关白åå•åˆ é™¤ï¼Œè¯¥æ–‡ä»¶å¦‚ä¸‹ï¼š ```text { "whitelist": [ { "name": "execute and execute_no_trans", "user": [ "appspawn appspawn_exec" ], "developer": [ ] } ] } ``` è¿™é‡Œæ ¹æ®æŠ¥é”™ï¼Œè¦åˆ 除检查项`"execute and execute_no_trans"`下的`user`å—æ®µçš„白åå•`"appspawn appspawn_exec"`,å¦å¤–,其他冗余白åå•æŠ¥é”™çš„åˆ é™¤ä½ç½®å‚考下表: **表2** ä¸»å®¢ä½“ç»„åˆæƒé™æ£€æŸ¥é¡¹å†—余白åå•å—æ®µä¸ŽæŠ¥é”™å¯¹åº”关系 | user白åå•冗余 | developer白åå•冗余 | åˆ é™¤ç™½åå•å—æ®µä½ç½® | | -------- | -------- | -------- | | 是 | 是 | user | | å¦ | 是 | developer | | 是 | å¦ | user | ## 篡改高å±è¿›ç¨‹åŸºçº¿æ£€æŸ¥ ### 检查说明 OpenHarmonyä¸å˜åœ¨ä¸€äº›é«˜å±è¿›ç¨‹ï¼Œä¾‹å¦‚shellã€console,这些进程的SELinuxç–ç•¥éœ€è¦æœ‰ç®¡æŽ§ï¼Œé¿å…éšæ„åˆ é™¤å’Œæ–°å¢žï¼Œé€ æˆç³»ç»Ÿä¸å¯ç”¨æˆ–å¼•å…¥å®‰å…¨éšæ‚£ã€‚对于这些高å±è¿›ç¨‹xx,其基线ç–略在`//base/security/selinux_adapter/sepolicy/`下的`xx.baseline`文件ä¸ã€‚以sh基线为例,形å¼å¦‚下: ```text (allow sh vendor_file (dir (search))) developer_only(` (allow sh system_lib_file (dir (search))) ') ``` å…¶ä¸è¢«developer_only括起æ¥çš„ç–略,表示该ç–略仅作为开å‘者模å¼ä¸‹çš„基线;å¦åˆ™ï¼Œè¡¨ç¤ºè¯¥ç–略是user和开å‘者模å¼å…±ç”¨çš„基线。 ### 编译拦截 æ–°å¢žå’Œåˆ é™¤é«˜å±è¿›ç¨‹ç–略,都会触å‘编译报错,关键报错信æ¯`check 'xxx' baseline in user mode failed`,xxx表示高å±è¿›ç¨‹æ ‡ç¾ï¼ŒæŠ¥é”™å¦‚下: ```text check 'sh' baseline in user mode failed expect rule: (allow sh vendor_file (dir ())); actual rule: (allow sh vendor_file (dir (search))) There are two solutions: 1. Add the above actual rule to baseline file 'sh.baseline' under 'base/security/selinux_adapter/sepolicy' 2. Change the policy to satisfy expect rule check 'sh' baseline in developer mode failed expect rule: (allow sh vendor_file (dir ())); actual rule: (allow sh vendor_file (dir (search))) There are two solutions: 1. Add the above actual rule to baseline file 'sh.baseline' under 'base/security/selinux_adapter/sepolicy' and add developer_only 2. Change the policy to satisfy expect rule ``` ### æ‹¦æˆªåŽŸå› ä¸Šè¿°æŠ¥é”™æ˜¯å› ä¸ºï¼Œæ–°å¢žäº†shçš„ç–ç•¥`"allow sh vendor_file:dir search;"`,对应的cilå½¢å¼ä¸º`"(allow sh vendor_file (dir (search)))"`ï¼ŒåŒæ—¶è¿å了userå’Œdeveloper下的进程基线,期望的cilå½¢å¼åŸºçº¿æ˜¯`"(allow sh vendor_file (dir ()))"`。 ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šå°†æŠ¥é”™ä¸`"actual rule"`å—æ®µçš„cilç–ç•¥ï¼Œä½œä¸ºæ–°åŸºçº¿æ·»åŠ åˆ°`//base/security/selinux_adapter/sepolicy/`下的基线文件`xx.baseline`ä¸ï¼Œ`xx`为è¿ååŸºçº¿çš„è¿›ç¨‹æ ‡ç¾ã€‚修改该基线文件需è¦è¯„估安全性和åˆç†æ€§ï¼Œå®¡æ…Žä¿®æ”¹ã€‚å…¶ä¸ï¼ŒåŸºçº¿çš„填写ä½ç½®å‚考下表: **表3** 篡改高å±è¿›ç¨‹åŸºçº¿æ£€æŸ¥åŸºçº¿æ›´æ–°ä½ç½®ä¸ŽæŠ¥é”™å¯¹åº”关系 | user基线报错 | developer基线报错 | 更新基线是å¦éœ€è¦åœ¨developer_only内 | | -------- | -------- | -------- | | 是 | 是 | å¦ | | å¦ | 是 | 是 | | 是 | å¦ | å°†developer_only内的基线挪到外部 | - æ–¹å¼äºŒï¼šä¿®æ”¹ä¸åˆç†çš„ç–ç•¥ï¼Œä»¥æ»¡è¶³è¦æ±‚,例如,更改方案,é¿å…è¿å基线。 ### åˆ é™¤å†—ä½™çš„åŸºçº¿ 当整改了ä¸åˆç†çš„基线ç–ç•¥åŽï¼Œåˆ 除了ä¸åˆç†çš„ç–ç•¥ï¼Œä½†æ˜¯æœªåŒæ—¶åˆ 除基线时,也会触å‘编译报错,关键报错信æ¯`check 'xxx' baseline in user mode failed`,xxx表示高å±è¿›ç¨‹æ ‡ç¾ï¼ŒæŠ¥é”™å¦‚下: ``` check 'sh' baseline in user mode failed expect rule: (allow sh rootfs (dir (search))); actual rule: (allow sh rootfs (dir ())) There are two solutions: 1. Add the above actual rule to baseline file 'sh.baseline' under 'base/security/selinux_adapter/sepolicy' 2. Change the policy to satisfy expect rule check 'sh' baseline in developer mode failed expect rule: (allow sh rootfs (dir (search))); actual rule: (allow sh rootfs (dir ())) There are two solutions: 1. Add the above actual rule to baseline file 'sh.baseline' under 'base/security/selinux_adapter/sepolicy' and add developer_only 2. Change the policy to satisfy expect rule ``` 需è¦åŒæ—¶åˆ 除基线,将`//base/security/selinux_adapter/sepolicy/`下的基线文件`sh.baseline`ä¸çš„ç›¸å…³åŸºçº¿åˆ é™¤ã€‚ è¿™é‡Œæ ¹æ®æŠ¥é”™ï¼Œè¦åˆ 除基线`"(allow sh rootfs (dir (search)))"`,å¦å¤–,以符åˆ`"actual rule"`ï¼Œå…¶ä»–å†—ä½™åŸºçº¿æŠ¥é”™çš„åˆ é™¤ä½ç½®å‚考下表: **表4** 篡改高å±è¿›ç¨‹åŸºçº¿æ£€æŸ¥å†—余基线与报错对应关系 | user基线冗余 | developer基线冗余 | åˆ é™¤åŸºçº¿å—æ®µä½ç½® | | -------- | -------- | -------- | | 是 | 是 | developer_only外 | | å¦ | 是 | developer_only内 | | 是 | å¦ | developer_only外 | ## ioctlçš„æƒé™ç–略检查 ### 检查说明 涉åŠé…ç½®ioctl相关的SELinuxç–略时,除了é…ç½®allowè§„åˆ™ä»¥å¤–ï¼Œè¿˜éœ€è¦æ ¹æ®avc日志对ioctlçš„ioctlcmd进行é™åˆ¶ï¼Œå¦åˆ™ä¼šå¯¼è‡´æ‰€æœ‰çš„ioctlcmdæƒé™éƒ½è¢«å¼€æ”¾ï¼Œä¸æ»¡è¶³æƒé™æœ€å°åŒ–原则。 ### 编译拦截 é…置的 allow 规则访问æƒé™åŒ…å«äº† ioctl,但未é™å®š ioctl æƒé™å‚数时,会触å‘编译报错,关键报错信æ¯`check ioctl rule in user mode failed.`,报错如下: ```text check ioctl rule in user mode failed. violation list (allow scontext tcontext:tclass ioctl) allow wifi_host data_service_el1_file:file ioctl; allow wifi_host dev_hdfwifi:chr_file ioctl; allow write_updater updater_block_file:blk_file ioctl; please add "allowxperm" rule based on the above list. ``` ### æ‹¦æˆªåŽŸå› ä»…æ·»åŠ `allow scontext tcontext:tclass ioctl`规则会导致主体有对tcontext:tclass所有ioctlçš„æƒé™ï¼Œæƒé™è¿‡å¤§è¢«ç¼–è¯‘æ‹¦æˆªï¼Œéœ€æ·»åŠ å…·ä½“çš„allowxperm对ioctlæƒé™ç²¾ç»†åŒ–管控,达到æƒé™æœ€å°åŒ–。 ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šæ ¹æ®avc日志对ioctlçš„ioctlcmd进行é™åˆ¶ã€‚例如,有下é¢çš„avc日志: ```text #avc: denied { ioctl } for pid=1 comm="init" path="/data/app/el1/bundle/public" dev="mmcblk0p11" ino=652804 ioctlcmd=0x6613 scontext=u:r:init:s0 tcontext=u:object_r:data_app_el1_file:s0 tclass=dir permissive=0 ``` æ ¹æ®è¯¥avc日志é…置了å…许ioctlçš„SELinuxç–略: ```text allow init data_app_el1_file:dir { ioctl }; ``` åŒæ—¶ï¼Œè¿˜éœ€è¦æ ¹æ®avc日志ä¸çš„`ioctlcmd=0x6613`å—æ®µï¼Œåœ¨ç›¸åŒuser或开å‘者模å¼åŸºçº¿ä¸‹æ·»åŠ allowxperm,进一æ¥é™åˆ¶ioctl的开放范围: ```text allowxperm init data_app_el1_file:dir ioctl { 0x6613 }; ``` - æ–¹å¼äºŒï¼šå°†æ‹¦æˆªæ—¥å¿—ä¸çš„ "scontext tcontext tclass" å—ç¬¦æ·»åŠ åˆ°`//base/security/selinux_adapter/sepolicy/`下白åå• `ioctl_xperm_whitelist.json` ä¸ï¼Œä¿®æ”¹è¯¥ç™½åå•需è¦è¯„ä¼°åˆç†æ€§ã€‚ æ‹¦æˆªæ—¥å¿—ä¸ `user mode` 表示该ç–略是user和开å‘者模å¼å…±ç”¨çš„基线,å¦å¤– `developer mode` 则表示该ç–略仅作为开å‘者模å¼ä¸‹çš„åŸºçº¿ï¼Œç›¸åº”æ·»åŠ åˆ°ç™½åå•列表ä¸ã€‚ ```text { "whitelist": { "user": [ "wifi_host data_service_el1_file file" ], "developer": [ ] } } ``` ## permissive 主体类型的æƒé™æ£€æŸ¥ ### 检查说明 å¢žåŠ permissive 的主体类型,会放开其访问所有客体的æƒé™ï¼Œä¸æ»¡è¶³æƒé™æœ€å°åŒ–原则。 ### 编译拦截 在ç–略文件ä¸å¢žåŠ `permissive scontext;` åŽï¼Œä¼šè§¦å‘ç¼–è¯‘æŠ¥é”™ï¼Œå…³é”®æŠ¥é”™ä¿¡æ¯ `check permissive rule in user mode failed.`,报错如下: ```text check permissive rule in user mode failed. violation list (scontext): sa_subsys_dfx_service There are two solutions: 1. Add the above list to whitelist file 'permissive_whitelist.json' under 'base/security/selinux_adapter/sepolicy' in 'user' mode. 2. Change the policy to avoid violating rule. ``` ### æ‹¦æˆªåŽŸå› è§„åˆ™ä¸å˜åœ¨æ–°å¢žçš„ permissive 主体类型。 ### ä¿®å¤æ–¹æ³• ä¸»è¦æœ‰ä¸¤ç§ä¿®å¤æ–¹å¼ï¼š - æ–¹å¼ä¸€ï¼šåˆ 除ä¸å¿…è¦çš„ permissive 定义。 - æ–¹å¼äºŒï¼šæ·»åŠ ä¸»ä½“ç±»åž‹scontext到 `//base/security/selinux_adapter/sepolicy/` 下白åå• `permissive_whitelist.json` ä¸ï¼Œä¿®æ”¹è¯¥ç™½åå•需è¦è¯„ä¼°åˆç†æ€§ã€‚ æ‹¦æˆªæ—¥å¿—ä¸ `user mode` 表示该ç–略是user和开å‘者模å¼å…±ç”¨çš„基线,å¦å¤– `developer mode` 则表示该ç–略仅作为开å‘者模å¼ä¸‹çš„åŸºçº¿ï¼Œç›¸åº”æ·»åŠ åˆ°ç™½å啿–‡ä»¶ã€‚ ```text { "whitelist": { "user": [ "sa_subsys_dfx_service" ], "developer": [ ] } } ```