1e41f4b71Sopenharmony_ci# OpenHarmony SELinux Policy Checklist
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Introduction
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciNot all the SELinux policies converted from AVC logs are appropriate for use. You need to review and modify them. This topic provides the SELinux policy checklist for your reference.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## SELinux Policies for Applications
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThe attributes corresponding to the SELinux types of application processes and application data are classified based on the Ability Privilege Levels (APLs) of applications. The following table lists the mappings between them.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci| APL| Application Process Attribute| Application Directory Attribute|
12e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
13e41f4b71Sopenharmony_ci| normal | normal_hap_attr | normal_hap_data_file_attr |
14e41f4b71Sopenharmony_ci| system_basic | system_basic_hap_attr | system_basic_hap_data_file_attr |
15e41f4b71Sopenharmony_ci| system_core | system_core_hap_attr | system_core_hap_data_file_attr |
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciFor details about the APLs, see [Application APL](../../application-dev/security/AccessToken/app-permission-mgmt-overview.md#application-apl).
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciIn addition, the **hap_domain** attribute indicates all application processes.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciYou need to modify the application SELinux type based on the application APL. For example, the policy configured based on the AVC log is as follows:
22e41f4b71Sopenharmony_ci```text
23e41f4b71Sopenharmony_ciallow normal_hap huks_service:binder { call };
24e41f4b71Sopenharmony_ci```
25e41f4b71Sopenharmony_ciThis policy allows binder communication between the application process labeled **normal_hap** and huks_service. Considering huks_service provides the HUKS capability for all applications, you need to change **normal_hap** to **hap_domain**.
26e41f4b71Sopenharmony_ci```text
27e41f4b71Sopenharmony_ciallow hap_domain huks_service:binder { call };
28e41f4b71Sopenharmony_ci```
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciThe following table lists the attributes for applications of different APIs and their directories.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci| Application| Attribute|
33e41f4b71Sopenharmony_ci| -------- | -------- |
34e41f4b71Sopenharmony_ci| normal applications| normal_hap_attr |
35e41f4b71Sopenharmony_ci| system_basic applications| system_basic_hap_attr |
36e41f4b71Sopenharmony_ci| system_core applications| system_core_hap_attr |
37e41f4b71Sopenharmony_ci| All applications| hap_domain |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| Application Directory| Attribute|
40e41f4b71Sopenharmony_ci| -------- | -------- |
41e41f4b71Sopenharmony_ci| Directories of normal applications| normal_hap_data_file_attr |
42e41f4b71Sopenharmony_ci| Directories of system_basic applications| system_basic_hap_data_file_attr |
43e41f4b71Sopenharmony_ci| Directories of system_core applications| system_core_hap_data_file_attr |
44e41f4b71Sopenharmony_ci| All application directories| normal_hap_data_file_attr & system_basic_hap_data_file_attr & system_core_hap_data_file_attr |
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci## New SELinux Policies for ioctl
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciFor ioctl, you need to restrict **ioctlcmd** based on AVC logs in addition to configuring **allow** rules. Otherwise, all **ioctlcmd** permissions are granted, which violates the least privilege principle. For example, the AVC log is as follows:
49e41f4b71Sopenharmony_ci```text
50e41f4b71Sopenharmony_ci#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
51e41f4b71Sopenharmony_ci```
52e41f4b71Sopenharmony_ciThe SELinux policy that allows ioctl is configured based on the AVC log as follows:
53e41f4b71Sopenharmony_ci```text
54e41f4b71Sopenharmony_ciallow init data_app_el1_file:dir { ioctl };
55e41f4b71Sopenharmony_ci```
56e41f4b71Sopenharmony_ciYou need to further restrict **ioctlcmd** based on "ioctlcmd=0x6613" in the AVC log.
57e41f4b71Sopenharmony_ci```text
58e41f4b71Sopenharmony_ciallowxperm init data_app_el1_file:dir ioctl { 0x6613 };
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci## Using neverallow to Protect Services
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciYou can use **neverallow** rules to prevent improper policy configuration and protect services.
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ciFor example, the SELinux type of the database file of the subject process accesstoken_service is **accesstoken_data_file**. For security purposes, the database file can be read and written only by the accesstoken_service process only. In this case, you can configure a **neverallow** rule to achieve this purpose.
66e41f4b71Sopenharmony_ci```text
67e41f4b71Sopenharmony_cineverallow { domain -accesstoken_service } accesstoken_data_file:file *;
68e41f4b71Sopenharmony_ci```
69e41f4b71Sopenharmony_ciThis rule prevents all the other processes except accesstoken_service from accessing accesstoken_data_file.
70