16cd6a6acSopenharmony_ciFile Labeling Statements 26cd6a6acSopenharmony_ci======================== 36cd6a6acSopenharmony_ci 46cd6a6acSopenharmony_cifilecon 56cd6a6acSopenharmony_ci------- 66cd6a6acSopenharmony_ci 76cd6a6acSopenharmony_ciDefine entries for labeling files. The compiler will produce these entries in a file called **`file_contexts`**`(5)` by default in the `cwd`. The compiler option `[-f|--filecontext <filename>]` may be used to specify a different path or file name. 86cd6a6acSopenharmony_ci 96cd6a6acSopenharmony_ci**Statement definition:** 106cd6a6acSopenharmony_ci 116cd6a6acSopenharmony_ci```secil 126cd6a6acSopenharmony_ci (filecon "path" file_type context_id) 136cd6a6acSopenharmony_ci``` 146cd6a6acSopenharmony_ci 156cd6a6acSopenharmony_ci**Where:** 166cd6a6acSopenharmony_ci 176cd6a6acSopenharmony_ci<table> 186cd6a6acSopenharmony_ci<colgroup> 196cd6a6acSopenharmony_ci<col width="25%" /> 206cd6a6acSopenharmony_ci<col width="75%" /> 216cd6a6acSopenharmony_ci</colgroup> 226cd6a6acSopenharmony_ci<tbody> 236cd6a6acSopenharmony_ci<tr class="odd"> 246cd6a6acSopenharmony_ci<td align="left"><p><code>filecon</code></p></td> 256cd6a6acSopenharmony_ci<td align="left"><p>The <code>filecon</code> keyword.</p></td> 266cd6a6acSopenharmony_ci</tr> 276cd6a6acSopenharmony_ci<tr class="even"> 286cd6a6acSopenharmony_ci<td align="left"><p><code>path</code></p></td> 296cd6a6acSopenharmony_ci<td align="left"><p>A string representing the file path that may be in the form of a regular expression. The string must be enclosed within double quotes (e.g. <code>"/this/is/a/path(/.*)?"</code>)</p></td> 306cd6a6acSopenharmony_ci</tr> 316cd6a6acSopenharmony_ci<tr class="odd"> 326cd6a6acSopenharmony_ci<td align="left"><p><code>file_type</code></p></td> 336cd6a6acSopenharmony_ci<td align="left"><p>A single keyword representing a file type in the <code>file_contexts</code> file as follows:</p> 346cd6a6acSopenharmony_ci<table> 356cd6a6acSopenharmony_ci<colgroup> 366cd6a6acSopenharmony_ci<col width="44%" /> 376cd6a6acSopenharmony_ci<col width="55%" /> 386cd6a6acSopenharmony_ci</colgroup> 396cd6a6acSopenharmony_ci<thead> 406cd6a6acSopenharmony_ci<tr class="odd"> 416cd6a6acSopenharmony_ci<td align="left"><p><strong>keyword</strong></p></td> 426cd6a6acSopenharmony_ci<td align="left"><p><strong>file_contexts entry</strong></p></td> 436cd6a6acSopenharmony_ci</tr> 446cd6a6acSopenharmony_ci</thead> 456cd6a6acSopenharmony_ci<tbody> 466cd6a6acSopenharmony_ci<tr class="even"> 476cd6a6acSopenharmony_ci<td align="left"><p><code>file</code></p></td> 486cd6a6acSopenharmony_ci<td align="left"><p><code>--</code></p></td> 496cd6a6acSopenharmony_ci</tr> 506cd6a6acSopenharmony_ci<tr class="odd"> 516cd6a6acSopenharmony_ci<td align="left"><p><code>dir</code></p></td> 526cd6a6acSopenharmony_ci<td align="left"><p><code>-d</code></p></td> 536cd6a6acSopenharmony_ci</tr> 546cd6a6acSopenharmony_ci<tr class="even"> 556cd6a6acSopenharmony_ci<td align="left"><p><code>char</code></p></td> 566cd6a6acSopenharmony_ci<td align="left"><p><code>-c</code></p></td> 576cd6a6acSopenharmony_ci</tr> 586cd6a6acSopenharmony_ci<tr class="odd"> 596cd6a6acSopenharmony_ci<td align="left"><p><code>block</code></p></td> 606cd6a6acSopenharmony_ci<td align="left"><p><code>-b</code></p></td> 616cd6a6acSopenharmony_ci</tr> 626cd6a6acSopenharmony_ci<tr class="even"> 636cd6a6acSopenharmony_ci<td align="left"><p><code>socket</code></p></td> 646cd6a6acSopenharmony_ci<td align="left"><p><code>-s</code></p></td> 656cd6a6acSopenharmony_ci</tr> 666cd6a6acSopenharmony_ci<tr class="odd"> 676cd6a6acSopenharmony_ci<td align="left"><p><code>pipe</code></p></td> 686cd6a6acSopenharmony_ci<td align="left"><p><code>-p</code></p></td> 696cd6a6acSopenharmony_ci</tr> 706cd6a6acSopenharmony_ci<tr class="even"> 716cd6a6acSopenharmony_ci<td align="left"><p><code>symlink</code></p></td> 726cd6a6acSopenharmony_ci<td align="left"><p><code>-l</code></p></td> 736cd6a6acSopenharmony_ci</tr> 746cd6a6acSopenharmony_ci<tr class="odd"> 756cd6a6acSopenharmony_ci<td align="left"><p><code>any</code></p></td> 766cd6a6acSopenharmony_ci<td align="left"><p>no entry</p></td> 776cd6a6acSopenharmony_ci</tr> 786cd6a6acSopenharmony_ci</tbody> 796cd6a6acSopenharmony_ci</table></td> 806cd6a6acSopenharmony_ci</tr> 816cd6a6acSopenharmony_ci<tr class="even"> 826cd6a6acSopenharmony_ci<td align="left"><p><code>context_id</code></p></td> 836cd6a6acSopenharmony_ci<td align="left"><p>The security context to be allocated to the file, which may be:</p> 846cd6a6acSopenharmony_ci<ul> 856cd6a6acSopenharmony_ci<li><p>A previously declared <code>context</code> identifier or an anonymous security context (<code>user role type levelrange</code>), the range MUST be defined whether the policy is MLS/MCS enabled or not.</p></li> 866cd6a6acSopenharmony_ci<li><p>An empty context list represented by <code>()</code> can be used to indicate that matching files should not be re-labeled. This will be interpreted as <code><<none>></code> within the <strong><code>file_contexts</code></strong><code>(5)</code> file.</p></li> 876cd6a6acSopenharmony_ci</ul></td> 886cd6a6acSopenharmony_ci</tr> 896cd6a6acSopenharmony_ci</tbody> 906cd6a6acSopenharmony_ci</table> 916cd6a6acSopenharmony_ci 926cd6a6acSopenharmony_ci**Examples:** 936cd6a6acSopenharmony_ci 946cd6a6acSopenharmony_ciThese examples use one named, one anonymous and one empty context definition: 956cd6a6acSopenharmony_ci 966cd6a6acSopenharmony_ci```secil 976cd6a6acSopenharmony_ci (context runas_exec_context (u object_r exec low_low)) 986cd6a6acSopenharmony_ci 996cd6a6acSopenharmony_ci (filecon "/system/bin/run-as" file runas_exec_context) 1006cd6a6acSopenharmony_ci (filecon "/dev/socket/wpa_wlan[0-9]" any u:object_r:wpa.socket:s0-s0) 1016cd6a6acSopenharmony_ci (filecon "/data/local/mine" dir ()) 1026cd6a6acSopenharmony_ci``` 1036cd6a6acSopenharmony_ci 1046cd6a6acSopenharmony_cito resolve/build `file_contexts` entries of (assuming MLS enabled policy): 1056cd6a6acSopenharmony_ci 1066cd6a6acSopenharmony_ci``` 1076cd6a6acSopenharmony_ci /system/bin/run-as -- u:object_r:runas.exec:s0 1086cd6a6acSopenharmony_ci /dev/socket/wpa_wlan[0-9] u:object_r:wpa.socket:s0 1096cd6a6acSopenharmony_ci /data/local/mine -d <<none>> 1106cd6a6acSopenharmony_ci``` 1116cd6a6acSopenharmony_ci 1126cd6a6acSopenharmony_cifsuse 1136cd6a6acSopenharmony_ci----- 1146cd6a6acSopenharmony_ci 1156cd6a6acSopenharmony_ciLabel filesystems that support SELinux security contexts. 1166cd6a6acSopenharmony_ci 1176cd6a6acSopenharmony_ci**Statement definition:** 1186cd6a6acSopenharmony_ci 1196cd6a6acSopenharmony_ci```secil 1206cd6a6acSopenharmony_ci (fsuse fstype fsname context_id) 1216cd6a6acSopenharmony_ci``` 1226cd6a6acSopenharmony_ci 1236cd6a6acSopenharmony_ci**Where:** 1246cd6a6acSopenharmony_ci 1256cd6a6acSopenharmony_ci<table> 1266cd6a6acSopenharmony_ci<colgroup> 1276cd6a6acSopenharmony_ci<col width="25%" /> 1286cd6a6acSopenharmony_ci<col width="75%" /> 1296cd6a6acSopenharmony_ci</colgroup> 1306cd6a6acSopenharmony_ci<tbody> 1316cd6a6acSopenharmony_ci<tr class="odd"> 1326cd6a6acSopenharmony_ci<td align="left"><p><code>fsuse</code></p></td> 1336cd6a6acSopenharmony_ci<td align="left"><p>The <code>fsuse</code> keyword.</p></td> 1346cd6a6acSopenharmony_ci</tr> 1356cd6a6acSopenharmony_ci<tr class="even"> 1366cd6a6acSopenharmony_ci<td align="left"><p><code>fstype</code></p></td> 1376cd6a6acSopenharmony_ci<td align="left"><p>A single keyword representing the type of filesystem as follows:</p> 1386cd6a6acSopenharmony_ci<ul> 1396cd6a6acSopenharmony_ci<li><p><code>task</code> - For pseudo filesystems supporting task related services such as pipes and sockets.</p></li> 1406cd6a6acSopenharmony_ci<li><p><code>trans</code> - For pseudo filesystems such as pseudo terminals and temporary objects.</p></li> 1416cd6a6acSopenharmony_ci<li><p><code>xattr</code> - Filesystems supporting the extended attribute <code>security.selinux</code>. The labeling is persistent for filesystems that support extended attributes.</p></li> 1426cd6a6acSopenharmony_ci</ul></td> 1436cd6a6acSopenharmony_ci</tr> 1446cd6a6acSopenharmony_ci<tr class="odd"> 1456cd6a6acSopenharmony_ci<td align="left"><p><code>fsname</code></p></td> 1466cd6a6acSopenharmony_ci<td align="left"><p>Name of the supported filesystem (e.g. <code>ext4</code> or <code>pipefs</code>).</p></td> 1476cd6a6acSopenharmony_ci</tr> 1486cd6a6acSopenharmony_ci<tr class="even"> 1496cd6a6acSopenharmony_ci<td align="left"><p><code>context_id</code></p></td> 1506cd6a6acSopenharmony_ci<td align="left"><p>The security context to be allocated to the network interface.</p> 1516cd6a6acSopenharmony_ci<p>A previously declared <code>context</code> identifier or an anonymous security context (<code>user role type levelrange</code>), the range MUST be defined whether the policy is MLS/MCS enabled or not.</p></td> 1526cd6a6acSopenharmony_ci</tr> 1536cd6a6acSopenharmony_ci</tbody> 1546cd6a6acSopenharmony_ci</table> 1556cd6a6acSopenharmony_ci 1566cd6a6acSopenharmony_ci**Examples:** 1576cd6a6acSopenharmony_ci 1586cd6a6acSopenharmony_ciThe [context](#context) identifiers are declared in the `file` namespace and the [`fsuse`](cil_file_labeling_statements.md#fsuse) statements in the global namespace: 1596cd6a6acSopenharmony_ci 1606cd6a6acSopenharmony_ci```secil 1616cd6a6acSopenharmony_ci (block file 1626cd6a6acSopenharmony_ci (type labeledfs) 1636cd6a6acSopenharmony_ci (roletype object_r labeledfs) 1646cd6a6acSopenharmony_ci (context labeledfs_context (u object_r labeledfs low_low)) 1656cd6a6acSopenharmony_ci 1666cd6a6acSopenharmony_ci (type pipefs) 1676cd6a6acSopenharmony_ci (roletype object_r pipefs) 1686cd6a6acSopenharmony_ci (context pipefs_context (u object_r pipefs low_low)) 1696cd6a6acSopenharmony_ci ... 1706cd6a6acSopenharmony_ci ) 1716cd6a6acSopenharmony_ci 1726cd6a6acSopenharmony_ci (fsuse xattr ex4 file.labeledfs_context) 1736cd6a6acSopenharmony_ci (fsuse xattr btrfs file.labeledfs_context) 1746cd6a6acSopenharmony_ci 1756cd6a6acSopenharmony_ci (fsuse task pipefs file.pipefs_context) 1766cd6a6acSopenharmony_ci (fsuse task sockfs file.sockfs_context) 1776cd6a6acSopenharmony_ci 1786cd6a6acSopenharmony_ci (fsuse trans devpts file.devpts_context) 1796cd6a6acSopenharmony_ci (fsuse trans tmpfs file.tmpfs_context) 1806cd6a6acSopenharmony_ci``` 1816cd6a6acSopenharmony_ci 1826cd6a6acSopenharmony_cigenfscon 1836cd6a6acSopenharmony_ci-------- 1846cd6a6acSopenharmony_ci 1856cd6a6acSopenharmony_ciUsed to allocate a security context to filesystems that cannot support any of the [`fsuse`](cil_file_labeling_statements.md#fsuse) file labeling options. Generally a filesystem would have a single default security context assigned by [`genfscon`](cil_file_labeling_statements.md#genfscon) from the root `(/)` that would then be inherited by all files and directories on that filesystem. The exception to this is the `/proc` filesystem, where directories can be labeled with a specific security context (as shown in the examples). 1866cd6a6acSopenharmony_ci 1876cd6a6acSopenharmony_ci**Statement definition:** 1886cd6a6acSopenharmony_ci 1896cd6a6acSopenharmony_ci```secil 1906cd6a6acSopenharmony_ci (genfscon fsname path [file_type] context_id) 1916cd6a6acSopenharmony_ci``` 1926cd6a6acSopenharmony_ci 1936cd6a6acSopenharmony_ci**Where:** 1946cd6a6acSopenharmony_ci 1956cd6a6acSopenharmony_ci<table> 1966cd6a6acSopenharmony_ci<colgroup> 1976cd6a6acSopenharmony_ci<col width="25%" /> 1986cd6a6acSopenharmony_ci<col width="75%" /> 1996cd6a6acSopenharmony_ci</colgroup> 2006cd6a6acSopenharmony_ci<tbody> 2016cd6a6acSopenharmony_ci<tr class="odd"> 2026cd6a6acSopenharmony_ci<td align="left"><p><code>genfscon</code></p></td> 2036cd6a6acSopenharmony_ci<td align="left"><p>The <code>genfscon</code> keyword.</p></td> 2046cd6a6acSopenharmony_ci</tr> 2056cd6a6acSopenharmony_ci<tr class="even"> 2066cd6a6acSopenharmony_ci<td align="left"><p><code>fsname</code></p></td> 2076cd6a6acSopenharmony_ci<td align="left"><p>Name of the supported filesystem (e.g. <code>rootfs</code> or <code>proc</code>).</p></td> 2086cd6a6acSopenharmony_ci</tr> 2096cd6a6acSopenharmony_ci<tr class="odd"> 2106cd6a6acSopenharmony_ci<td align="left"><p><code>path</code></p></td> 2116cd6a6acSopenharmony_ci<td align="left"><p>If <code>fsname</code> is <code>proc</code>, then the partial path (see examples). For all other types this must be ‘<code>/</code>’.</p></td> 2126cd6a6acSopenharmony_ci</tr> 2136cd6a6acSopenharmony_ci<tr class="even"> 2146cd6a6acSopenharmony_ci<td align="left"><p><code>file_type</code></p></td> 2156cd6a6acSopenharmony_ci<td align="left"><p>Optional keyword representing a file type. Valid values are the same as in [`filecon`](cil_file_labeling_statements.md#filecon) rules.</p></td> 2166cd6a6acSopenharmony_ci</tr> 2176cd6a6acSopenharmony_ci<tr class="odd"> 2186cd6a6acSopenharmony_ci<td align="left"><p><code>context_id</code></p></td> 2196cd6a6acSopenharmony_ci<td align="left"><p>A previously declared <code>context</code> identifier or an anonymous security context (<code>user role type levelrange</code>), the range MUST be defined whether the policy is MLS/MCS enabled or not.</p></td> 2206cd6a6acSopenharmony_ci</tr> 2216cd6a6acSopenharmony_ci</tbody> 2226cd6a6acSopenharmony_ci</table> 2236cd6a6acSopenharmony_ci 2246cd6a6acSopenharmony_ci**Examples:** 2256cd6a6acSopenharmony_ci 2266cd6a6acSopenharmony_ciThe [context](#context) identifiers are declared in the `file` namespace and the [`genfscon`](cil_file_labeling_statements.md#genfscon) statements are then inserted using the [`in`](cil_container_statements.md#in) container statement: 2276cd6a6acSopenharmony_ci 2286cd6a6acSopenharmony_ci```secil 2296cd6a6acSopenharmony_ci (file 2306cd6a6acSopenharmony_ci (type rootfs) 2316cd6a6acSopenharmony_ci (roletype object_r rootfs) 2326cd6a6acSopenharmony_ci (context rootfs_context (u object_r rootfs low_low)) 2336cd6a6acSopenharmony_ci 2346cd6a6acSopenharmony_ci (type proc) 2356cd6a6acSopenharmony_ci (roletype object_r proc) 2366cd6a6acSopenharmony_ci (context rootfs_context (u object_r proc low_low)) 2376cd6a6acSopenharmony_ci ... 2386cd6a6acSopenharmony_ci ) 2396cd6a6acSopenharmony_ci 2406cd6a6acSopenharmony_ci (in file 2416cd6a6acSopenharmony_ci (genfscon rootfs / rootfs_context) 2426cd6a6acSopenharmony_ci ; proc labeling can be further refined (longest matching prefix). 2436cd6a6acSopenharmony_ci (genfscon proc / proc_context) 2446cd6a6acSopenharmony_ci (genfscon proc /net/xt_qtaguid/ctrl qtaguid_proc_context) 2456cd6a6acSopenharmony_ci (genfscon proc /sysrq-trigger sysrq_proc_context) 2466cd6a6acSopenharmony_ci (genfscon selinuxfs / selinuxfs_context) 2476cd6a6acSopenharmony_ci ) 2486cd6a6acSopenharmony_ci``` 249