Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/htdocs/index.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 52 - (hide annotations) (download) (as text)
Thu Aug 30 21:18:05 2012 UTC (11 years, 7 months ago) by kumaneko
File MIME type: text/html
File size: 159699 byte(s)


1 kumaneko 10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2     <html lang="en-US">
3     <head>
4     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 kumaneko 15 <meta http-equiv="content-style-type" content="text/css">
6     <link rel="stylesheet" href="media/caitsith.css" media="all" type="text/css">
7 kumaneko 10 <title>CaitSith Documentation</title>
8     </head>
9     <body>
10    
11     <h1>CaitSith -- A simplified access restriction module for system protection.</h1>
12    
13     <p>CaitSith is an access restriction module for Linux systems. This module gives you ability to restrict access (e.g. opening files, executing programs) at the kernel level. This module is designed for ease of use.</p>
14    
15 kumaneko 34 <p><a href="https://events.linuxfoundation.org/events/linuxcon" target="_blank"><img src="http://storage.pardot.com/6342/52656/lfe_at_badge_linuxcon.png" width="150" height="150" alt="I'll be Speaking at LinuxCon 2012! Join me!" border="0"></a></p>
16    
17 kumaneko 30 <p>Below is documentation but is partially under construction. Sorry.</p>
18 kumaneko 10
19     <hr>
20    
21 kumaneko 29 <h2><a name="index">Index</a></h2>
22 kumaneko 10
23 kumaneko 15 <p><a href="#difference_with_tomoyo">1. Difference with TOMOYO (for existing TOMOYO users)</a></p>
24    
25 kumaneko 10 <ul>
26 kumaneko 15 <li><a href="#1.1">1.1. About pathnames and management programs</a></li>
27     <li><a href="#1.2">1.2. About policy syntax</a></li>
28 kumaneko 10 </ul>
29    
30 kumaneko 15 <p><a href="#how_to_install">2. How to install</a></p>
31    
32     <ul>
33     <li><a href="#2.1">2.1. Install dependencies</a></li>
34     <li><a href="#2.2">2.2. Download and patch the kernel</a></li>
35     <li><a href="#2.3">2.3. Configure the kernel</a></li>
36     <li><a href="#2.4">2.4. Compile and install the kernel</a></li>
37     <li><a href="#2.5">2.5. Install the userspace tools</a></li>
38     <li><a href="#2.6">2.6. Initializing configuration</a></li>
39     <li><a href="#2.7">2.7. Configuring your bootloader</a></li>
40     <li><a href="#2.8">2.8. Rebooting your system</a></li>
41     <li><a href="#2.9">2.9. How can I disable/uninstall CaitSith?</a></li>
42     </ul>
43    
44     <p><a href="#how_to_develop_policy">3. How to develop policy</a></p>
45    
46 kumaneko 16 <ul>
47     <li><a href="#3.1">3.1. Policy file structure</a></li>
48     <li><a href="#3.2">3.2. Updating policy configuration</a></li>
49     <li><a href="#3.3">3.3. Example of simple access restriction rule</a></li>
50 kumaneko 20 <li><a href="#3.4">3.4. Understanding two viewpoints</a></li>
51 kumaneko 16 </ul>
52    
53 kumaneko 29 <p><a href="#condition_list">4. List of conditions</a></p>
54 kumaneko 10
55     <ul>
56 kumaneko 29 <li><a href="#4.1">4.1. Using string arguments in conditions</a></li>
57     <li><a href="#4.2">4.2. Using numeric arguments in conditions</a></li>
58     <li><a href="#4.3">4.3. Using process's information in conditions</a></li>
59     <li><a href="#4.4">4.4. Using IP address arguments in conditions</a></li>
60     <li><a href="#4.5">4.5. Using command line arguments in conditions</a></li>
61     <li><a href="#4.6">4.6. Using environment variable arguments in conditions</a></li>
62     <li><a href="#4.7">4.7. Using file's DAC permissions in conditions</a></li>
63     <li><a href="#4.8">4.8. Using handle file's type in conditions</a></li>
64     <li><a href="#4.9">4.9. Using file's attributes in conditions</a></li>
65 kumaneko 10 </ul>
66    
67 kumaneko 30 <p><a href="#syntax_list">5. List of syntaxes</a></p>
68 kumaneko 29
69 kumaneko 30 <ul>
70     <li><a href="#5.1">5.1. execute</a></li>
71     <li><a href="#5.2">5.2. read</a></li>
72     <li><a href="#5.3">5.3. write</a></li>
73     <li><a href="#5.4">5.4. append</a></li>
74     <li><a href="#5.5">5.5. create</a></li>
75     <li><a href="#5.6">5.6. unlink</a></li>
76     <li><a href="#5.7">5.7. getattr</a></li>
77     <li><a href="#5.8">5.8. mkdir</a></li>
78     <li><a href="#5.9">5.9. rmdir</a></li>
79     <li><a href="#5.10">5.10. mkfifo</a></li>
80     <li><a href="#5.11">5.11. mksock</a></li>
81     <li><a href="#5.12">5.12. truncate</a></li>
82     <li><a href="#5.13">5.13. symlink</a></li>
83     <li><a href="#5.14">5.14. mkblock</a></li>
84     <li><a href="#5.15">5.15. mkchar</a></li>
85     <li><a href="#5.16">5.16. link</a></li>
86     <li><a href="#5.17">5.17. rename</a></li>
87     <li><a href="#5.18">5.18. chmod</a></li>
88     <li><a href="#5.19">5.19. chown</a></li>
89     <li><a href="#5.20">5.20. chgrp</a></li>
90     <li><a href="#5.21">5.21. ioctl</a></li>
91     <li><a href="#5.22">5.22. chroot</a></li>
92     <li><a href="#5.23">5.23. mount</a></li>
93     <li><a href="#5.24">5.24. unmount</a></li>
94     <li><a href="#5.25">5.25. pivot_root</a></li>
95     <li><a href="#5.26">5.26. inet_stream_bind</a></li>
96     <li><a href="#5.27">5.27. inet_stream_listen</a></li>
97     <li><a href="#5.28">5.28. inet_stream_connect</a></li>
98     <li><a href="#5.29">5.29. inet_stream_accept</a></li>
99     <li><a href="#5.30">5.30. inet_dgram_bind</a></li>
100     <li><a href="#5.31">5.31. inet_dgram_send</a></li>
101     <li><a href="#5.32">5.32. inet_dgram_recv</a></li>
102     <li><a href="#5.33">5.33. inet_raw_bind</a></li>
103     <li><a href="#5.34">5.34. inet_raw_send</a></li>
104     <li><a href="#5.35">5.35. inet_raw_recv</a></li>
105     <li><a href="#5.36">5.36. unix_stream_bind</a></li>
106     <li><a href="#5.37">5.37. unix_stream_listen</a></li>
107     <li><a href="#5.38">5.38. unix_stream_connect</a></li>
108     <li><a href="#5.39">5.39. unix_stream_accept</a></li>
109     <li><a href="#5.40">5.40. unix_dgram_bind</a></li>
110     <li><a href="#5.41">5.41. unix_dgram_send</a></li>
111     <li><a href="#5.42">5.42. unix_dgram_recv</a></li>
112     <li><a href="#5.43">5.43. unix_seqpacket_bind</a></li>
113     <li><a href="#5.44">5.44. unix_seqpacket_listen</a></li>
114     <li><a href="#5.45">5.45. unix_seqpacket_connect</a></li>
115     <li><a href="#5.46">5.46. unix_seqpacket_accept</a></li>
116     <li><a href="#5.47">5.47. ptrace</a></li>
117     <li><a href="#5.48">5.48. signal</a></li>
118     <li><a href="#5.49">5.49. environ</a></li>
119     <li><a href="#5.50">5.50. modify_policy</a></li>
120     <li><a href="#5.51">5.51. use_netlink_socket</a></li>
121     <li><a href="#5.52">5.52. use_packet_socket</a></li>
122     <li><a href="#5.53">5.53. use_reboot</a></li>
123     <li><a href="#5.54">5.54. use_vhangup</a></li>
124     <li><a href="#5.55">5.55. set_time</a></li>
125     <li><a href="#5.56">5.56. set_priority</a></li>
126     <li><a href="#5.57">5.57. set_hostname</a></li>
127     <li><a href="#5.58">5.58. use_kernel_module</a></li>
128     <li><a href="#5.59">5.59. use_new_kernel</a></li>
129     <li><a href="#5.60">5.60. manual_domain_transition</a></li>
130     <li><a href="#5.61">5.61. auto_domain_transition</a></li>
131     </ul>
132    
133     <p><a href="#advanced_usage">6. Advanced usage</a></p>
134    
135 kumaneko 10 <hr>
136    
137     <h2><a name="difference_with_tomoyo">1. Difference with TOMOYO (for existing TOMOYO users)</a></h2>
138    
139 kumaneko 15 <p>CaitSith was derived from TOMOYO Linux, but usage of CaitSith would be too different to imagine that CaitSith was derived from TOMOYO Linux. If you are already using TOMOYO Linux, please read the difference described below.</p>
140 kumaneko 10
141 kumaneko 30 <hr>
142 kumaneko 15 <h3><a name="1.1">1.1. About pathnames and management programs</a></h3>
143 kumaneko 10
144 kumaneko 22 <p><code>/proc/ccs/domain_policy</code>, <code>/proc/ccs/exception_policy</code>, <code>/proc/ccs/profile</code>, <code>/proc/ccs/manager</code> and <code>/proc/ccs/stat</code> have been aggregated into <code>/proc/caitsith/policy</code>.</p>
145 kumaneko 10
146 kumaneko 22 <p><code>/etc/ccs/policy/current/domain_policy.conf</code>, <code>/etc/ccs/policy/current/exception_policy.conf</code>, <code>/etc/ccs/policy/current/profile.conf</code>, <code>/etc/ccs/policy/current/manager.conf</code> and <code>/etc/ccs/policy/current/stat.conf</code> have been aggregated into <code>/etc/caitsith/policy/current</code>.</p>
147 kumaneko 10
148 kumaneko 22 <p>Built-in policy files which are located under kernel source directory as <code>security/ccsecurity/policy/domain_policy.conf</code>, <code>security/ccsecurity/policy/exception_policy.conf</code>, <code>security/ccsecurity/policy/profile.conf</code>, <code>security/ccsecurity/policy/manager.conf</code> and <code>security/ccsecurity/policy/stat.conf</code> have been aggregated into <code>security/caitsith/policy/policy.conf</code>.</p>
149 kumaneko 10
150 kumaneko 22 <p>Only <code>/sbin/caitsith-init</code>, <code>/usr/sbin/caitsith-auditd</code>, <code>/usr/sbin/caitsith-loadpolicy</code>, <code>/usr/sbin/caitsith-notifyd</code>, <code>/usr/sbin/caitsith-pstree</code>, <code>/usr/sbin/caitsith-queryd</code>, <code>/usr/sbin/caitsith-savepolicy</code>, <code>/usr/lib/caitsith/audit-exec-param</code>, <code>/usr/lib/caitsith/caitsith-agent</code> and <code>/usr/lib/caitsith/init_policy</code> are provided for managing policy. (In other words, programs such as <code>/usr/sbin/ccs-editpolicy</code> and <code>/usr/sbin/ccs-setprofile</code> have been removed.)</p>
151 kumaneko 10
152 kumaneko 28 <p>Command line arguments for specifying type of policy to load/save have been removed from <code>/usr/sbin/caitsith-loadpolicy</code> and <code>/usr/sbin/caitsith-savepolicy</code>.</p>
153 kumaneko 10
154 kumaneko 28 <p>Command line arguments for specifying profile type have been removed from <code>/usr/lib/caitsith/init_policy</code>.</p>
155 kumaneko 10
156 kumaneko 30 <hr>
157 kumaneko 15 <h3><a name="1.2">1.2. About policy syntax</a></h3>
158 kumaneko 10
159 kumaneko 28 <p>Policy syntax has been drastically changed. TOMOYO Linux uses process's domainname as a key for grouping permissions to do some operations. In other words, TOMOYO Linux's policy is collection of "which domain can do ..." rules. On the other hand, CaitSith uses operation as a key for checking permission. In other words, CaitSith's policy is collection of "which operation can be done by ..." rules. This change is intended for allowing users to protect resources using blacklisting approach. In CaitSith, process's domainname is nothing but one of optional parameters that can be used for controlling whether to grant or deny specific operations. Users can write rules without managing domainnames unless needed.</p>
160 kumaneko 10
161     <p>Process's domainname representation has changed from space delimited multiple words (e.g. "&lt;kernel&gt; /sbin/init /etc/rc.d/rc.sysinit") to a single word (e.g. "/sbin/init").</p>
162    
163     <p>Domain transitions no longer happen unless explicitly specified by policy.</p>
164    
165     <p>Distinction of disabled/learning/permissive/enforcing mode has been removed.</p>
166    
167     <p>"path_group" keyword has been renamed to "string_group", and "address_group" keyword has been renamed to "ip_group".</p>
168    
169     <p>Representation of \ character has been changed from \\ to \134.</p>
170    
171 kumaneko 28 <p>Distinction between directory's pathname and non-directory's pathname has been removed by removing trailing / character from pathname.</p>
172 kumaneko 10
173     <p>A new wildcard /\(dir\)/ has been introduced for helping converting from (e.g.) "/tmp/\{\*\}/" to "/tmp/\(\*\)/\*", for directory's pathname (except the root directory itself) no longer ends with / character which previously matched /\{\*\}/ wildcard.</p>
174    
175     <p>Category keywords (i.e. "file", "network", "ipc", "misc", "capability", "task") have been removed because access control levels which was specified using profile has been removed. Some of operation keywords have been renamed (e.g. "network inet stream connect" became "inet_stream_connect", "misc env" became "environ").</p>
176    
177     <p>"task auto_execute_handler" keyword has been renamed to "handler=" argument of "execute" keyword. This is intended for using execute handler for preprocessing purpose when executing specific programs rather than when executing from specific domains. "task denied_execute_handler" keyword has been removed.</p>
178    
179     <p>Domain argument has been removed from permission to send signals (i.e. "signal" directive), for kill() system call accepts negative number for specifying multiple processes. It is impossible to selectively deny sending signals because it is not permitted to sleep while sending signals.</p>
180    
181     <p>Restriction granularity for ptrace operation has changed from boolean (i.e. "capability SYS_PTRACE") to command number + domainname.</p>
182    
183     <p>Restriction granularity for environment variables has changed from name only to both name and values.</p>
184    
185     <p>Several variables for referencing file's attributes have been added.</p>
186    
187     <p>Local port reserve functionality (i.e. "deny_autobind" keyword) has been removed.</p>
188    
189 kumaneko 30 <hr>
190 kumaneko 10 <h2><a name="how_to_install">2. How to install</a></h2>
191    
192 kumaneko 15 <p>Since CaitSith is a kernel component, you will have to compile your own kernel.</p>
193 kumaneko 10
194 kumaneko 30 <hr>
195 kumaneko 15 <h3><a name="2.1">2.1. Install dependencies</a></h3>
196 kumaneko 10
197 kumaneko 15 <p>These packages are required for compiling the kernel and the userspace tools:</p>
198 kumaneko 10
199 kumaneko 15 <ul>
200     <li><strong>wget</strong>: to download sources</li>
201     <li><strong>patch</strong>: to patch the kernel</li>
202     <li><strong>gcc</strong>: to build the kernel and tools</li>
203     <li><strong>make</strong>: to build the kernel and tools</li>
204     <li><strong>ncurses-devel</strong> or <strong>libncurses-dev</strong>: to build the tools</li>
205     </ul>
206    
207     <p>These can be installed with the following commands:</p>
208    
209     <p><strong>RedHat distributions</strong></p>
210     <pre class="command">
211     # yum -y install wget patch gcc make ncurses-devel
212     </pre>
213     <p><strong>Debian distributions</strong></p>
214     <pre class="command">
215     # apt-get -y install wget patch gcc make libncurses-dev
216     </pre>
217     <p><strong>SUSE distributions</strong></p>
218     <pre class="command">
219     # yast -i wget patch gcc make ncurses-devel
220     </pre>
221    
222 kumaneko 30 <hr>
223 kumaneko 15 <h3><a name="2.2">2.2. Download and patch the kernel</a></h3>
224    
225     <p>Download the kernel source from <a href="http://www.kernel.org/pub/linux/kernel/v2.6/">linux-2.6</a> or <a href="http://www.kernel.org/pub/linux/kernel/v3.0/">linux-3</a>.<br>
226     Linux kernel 2.6.27 and later are supported from the linux-2.6 tree.<br>
227     Linux kernel 3.0 and later are supported from the linux-3 tree.</p>
228    
229     <p>Extract the kernel source and go to the extracted directory.<br>
230 kumaneko 28 In the operations below, "$VERSION" should be replaced with appropriate kernel version. For example "3.3" if using Linux kernel 3.3.6, "2.6.27" if using Linux kernel 2.6.27.62.<br>
231 kumaneko 45 Also, there are several patches which can be applied to distributor's latest kernels. For example "2.6.32-centos-6.3" if using CentOS 6.3's latest kernel:</p>
232 kumaneko 15
233     <pre class="command">
234 kumaneko 52 $ wget -O caitsith-patch-0.1-20120831.tar.gz 'http://sourceforge.jp/frs/redir.php?m=jaist&amp;f=/caitsith/55464/caitsith-patch-0.1-20120831.tar.gz'
235     $ wget -O caitsith-patch-0.1-20120831.tar.gz.asc 'http://sourceforge.jp/frs/redir.php?m=jaist&amp;f=/caitsith/55464/caitsith-patch-0.1-20120831.tar.gz.asc'
236 kumaneko 15 $ wget http://I-love.SAKURA.ne.jp/kumaneko-key
237     $ gpg --import kumaneko-key
238 kumaneko 52 $ gpg caitsith-patch-0.1-20120831.tar.gz.asc
239     $ tar -zxf caitsith-patch-0.1-20120831.tar.gz
240 kumaneko 22 $ sed -i -e 's/CCSECURITY/CAITSITH/g' -e 's/ccsecurity/caitsith/g' -- patches/ccs-patch-*.diff
241 kumaneko 28 $ patch -sp1 &lt; patches/ccs-patch-$VERSION.diff
242 kumaneko 15 </pre>
243 kumaneko 10
244 kumaneko 30 <hr>
245 kumaneko 15 <h3><a name="2.3">2.3. Configure the kernel</a></h3>
246 kumaneko 10
247 kumaneko 15 <pre class="command">
248     $ make -s menuconfig
249     </pre>
250 kumaneko 10
251 kumaneko 15 <p>Choose the following options in "Security options" section:</p>
252 kumaneko 10
253 kumaneko 15 <ul>
254     <li>[*] CaitSith support</li>
255     <li>[ ] &nbsp;&nbsp;Compile as loadable kernel module</li>
256     <li>[ ] &nbsp;&nbsp;Disable by default</li>
257     <li>[ ] &nbsp;&nbsp;Do not modify 'struct task_struct' in order to keep KABI</li>
258     <li>[ ] &nbsp;&nbsp;Activate without calling userspace policy loader.</li>
259 kumaneko 22 <li>(<code>/sbin/caitsith-init</code>) Location of userspace policy loader</li>
260     <li>(<code>/sbin/init</code>) Trigger for calling userspace policy loader</li>
261 kumaneko 15 <li>[*] &nbsp;&nbsp;Enable readdir operation restriction.</li>
262     <li>[*] &nbsp;&nbsp;Enable getattr operation restriction.</li>
263     <li>[*] &nbsp;&nbsp;Enable socket operation restriction.</li>
264     <li>[*] &nbsp;&nbsp;Enable non-POSIX capability operation restriction.</li>
265     <li>[*] &nbsp;&nbsp;Enable ptrace operation restriction.</li>
266     <li>[*] &nbsp;&nbsp;Enable kill operation restriction.</li>
267     <li>[*] &nbsp;&nbsp;Enable environment variable names/values restriction.</li>
268     <li>[*] &nbsp;&nbsp;Enable execute handler functionality.</li>
269     <li>[*] &nbsp;&nbsp;Enable domain transition without program execution request.</li>
270     <li>[*] &nbsp;&nbsp;Enable automatic domain transition.</li>
271     </ul>
272    
273     <p><em>"Compile as loadable kernel module"</em> is useful when there is a file size limitation for vmlinux (e.g. embedded systems).</p>
274    
275     <p><em>"Disable by default"</em> will enable CaitSith only when "caitsith=on" is passed to the kernel's command line options. If this option is not selected, "caitsith=off" will disable CaitSith.</p>
276    
277     <p><em>"Do not modify 'struct task_struct' in order to keep KABI"</em> will manage "struct task_struct" variables outside "struct task_struct" in order to avoid Kernel Application Binary Interface (KABI) breakage. Choose this option if wanting to patch against distributor's kernels without breaking KABI. However, since "struct caitsith_operations" must be exported to loadable kernel modules (LKMs) in order to allow them to call CaitSith's functions, build scripts may still print warning messages.</p>
278    
279 kumaneko 22 <p>There are two types of CaitSith's policy configuration. The former is embedded into the kernel and the latter is saved as files on the filesystems (e.g. <code>/etc/caitsith/</code> directory). You will need to rebuild the kernel whenever updating the former, but allows you to load policy without using userspace policy loader (e.g. <code>/sbin/caitsith-init</code>). The latter is loaded by executing userspace policy loader when the access control by CaitSith is about to be activated (e.g. when <code>/sbin/init</code> starts). <em>Activate without calling userspace policy loader.</em> allows you to activate access control by CaitSith as soon as the former is loaded. This option is useful when it is difficult to call policy loader (e.g. embedded systems).</p>
280 kumaneko 15
281     <p><em>Location of userspace policy loader</em> is available only when <em>Activate without calling userspace policy loader.</em> is not selected. This option specifies the default pathname of the userspace policy loader. You can override this setting via the "CCS_loader=" kernel command-line option.</p>
282    
283 kumaneko 22 <p><em>Trigger for calling userspace policy loader</em> is available only when <em>Activate without calling userspace policy loader.</em> is not selected. This option specifies the default pathname of the activation trigger. You can override this setting via the "CCS_trigger=" kernel command-line option. For example, if you pass "init=<code>/bin/systemd</code>" option, you may also want to pass "CCS_trigger=<code>/bin/systemd</code>" option.</p>
284 kumaneko 15
285 kumaneko 30 <hr>
286 kumaneko 15 <h3><a name="2.4">2.4. Compile and install the kernel</a></h3>
287    
288 kumaneko 22 <p>The policy configuration which will be embedded into the kernel needs to exist as <code>security/caitsith/policy/policy.conf</code>. But you can proceed without creating that file because you don't have the policy configuration to embed as of this step. (You may come back here after you developed policy configuration to embed.)</p>
289 kumaneko 15
290     <p>Once the kernel has been configured, compile and install the kernel with the following commands:</p>
291    
292     <pre class="command">
293     $ make -s
294     $ su
295     # make -s modules_install install
296     </pre>
297    
298     <p>Create initrd/initramfs if required.</p>
299    
300 kumaneko 30 <hr>
301 kumaneko 15 <h3><a name="2.5">2.5. Install the userspace tools</a></h3>
302    
303     <p>Make sure the dependencies described above have been installed. Compile and install the tools with the following commands:</p>
304    
305     <pre class="command">
306 kumaneko 27 $ wget -O caitsith-tools-0.1-20120505.tar.gz 'http://sourceforge.jp/frs/redir.php?m=jaist&amp;f=/caitsith/55465/caitsith-tools-0.1-20120505.tar.gz'
307     $ wget -O caitsith-tools-0.1-20120505.tar.gz.asc 'http://sourceforge.jp/frs/redir.php?m=jaist&amp;f=/caitsith/55465/caitsith-tools-0.1-20120505.tar.gz.asc'
308     $ gpg caitsith-tools-0.1-20120505.tar.gz.asc
309     $ tar -zxf caitsith-tools-0.1-20120505.tar.gz
310 kumaneko 10 $ cd caitsith-tools/
311 kumaneko 15 $ make -s USRLIBDIR=/usr/lib
312     $ su
313     # make -s USRLIBDIR=/usr/lib install
314     </pre>
315 kumaneko 10
316 kumaneko 22 <p>Please change USRLIBDIR=<code>/usr/lib</code> to USRLIBDIR=<code>/usr/lib64</code> (for 64bits userspace) or USRLIBDIR=<code>/usr/lib32</code> (for 32bits userspace) if needed.</p>
317 kumaneko 10
318 kumaneko 15 <p>Programs listed below are main userspace tools used for administrating CaitSith.</p>
319 kumaneko 10
320 kumaneko 15 <ul>
321 kumaneko 22 <li><code>/sbin/caitsith-init</code></li>
322     <li><code>/usr/sbin/caitsith-auditd</code></li>
323     <li><code>/usr/sbin/caitsith-loadpolicy</code></li>
324     <li><code>/usr/sbin/caitsith-notifyd</code></li>
325     <li><code>/usr/sbin/caitsith-pstree</code></li>
326     <li><code>/usr/sbin/caitsith-queryd</code></li>
327     <li><code>/usr/sbin/caitsith-savepolicy</code></li>
328 kumaneko 15 </ul>
329    
330 kumaneko 22 <p>You will probably want to add <code>/usr/sbin</code> to your PATH so that the commands can be run easily. If you are using <code>/bin/bash</code>, append the following line to <code>~/.bashrc</code>:</p>
331 kumaneko 15
332     <pre>
333     export PATH=$PATH:/usr/sbin
334     </pre>
335    
336 kumaneko 30 <hr>
337 kumaneko 15 <h3><a name="2.6">2.6. Initializing configuration</a></h3>
338    
339 kumaneko 22 <p>Before you can make use of CaitSith, an initialization procedure must take place. This prepares the files in which policy information will be stored. All policy files are <strong>stored in the "<code>/etc/caitsith/</code>" directory</strong>.</p>
340 kumaneko 15
341     <p>Run the following command as root user to initialize:</p>
342    
343     <pre class="command">
344     # /usr/lib/caitsith/init_policy
345     </pre>
346     <pre class="output">
347     Creating policy directory... OK
348     Creating configuration directory... OK
349     Creating default policy... OK.
350     Creating module loader... OK.
351     Creating configuration file for caitsith-auditd ... OK.
352     Creating configuration file for caitsith-notifyd ... OK.
353     </pre>
354    
355 kumaneko 22 <p>CaitSith can generate audit logs and allows you to read them via <code>/proc/caitsith/audit</code> interface. To save <code>/proc/caitsith/audit</code> automatically, start <code>/usr/sbin/caitsith-auditd</code> from somewhere. Default setting (specified in <code>/etc/caitsith/tools/auditd.conf</code>) sends access allowed logs to <code>/dev/null</code>, access unmatched logs to <code>/var/log/caitsith/unmatched.log</code>, access denied logs to <code>/var/log/caitsith/denied.log</code>. (The meaning and example of allowed/unmatched/denied will be explained in <a href="#3.3">Example of simple access restriction rule</a>.)</p>
356 kumaneko 15
357 kumaneko 22 <p>CaitSith can ask for your decision about access requests which will be denied unless you grant them via <code>/proc/caitsith/query</code> interface. To notify immediately the occurrence of access requests which CaitSith is about to deny, start <code>/usr/sbin/caitsith-notifyd</code> from somewhere. Default setting (specified in <code>/etc/caitsith/tools/notifyd.conf</code>) sends mails to root@localhost with subject "Notification from caitsith-notifyd" up to once per a minute.</p>
358 kumaneko 15
359 kumaneko 22 <p>Below example launches <code>/usr/sbin/caitsith-auditd</code> and <code>/usr/sbin/caitsith-notifyd</code> from <code>/etc/rc.local</code> script:</p>
360 kumaneko 15
361     <pre>
362     #!/bin/sh
363     #
364     # This script will be executed *after* all the other init scripts.
365     # You can put your own initialization stuff in here if you don't
366     # want to do the full Sys V style init stuff.
367    
368     touch /var/lock/subsys/local
369     /usr/sbin/caitsith-auditd
370     /usr/sbin/caitsith-notifyd
371     </pre>
372    
373 kumaneko 30 <hr>
374 kumaneko 15 <h3><a name="2.7">2.7. Configuring your bootloader</a></h3>
375    
376     <p>Now edit your bootloader (e.g. GRUB) to include the kernel you have just compiled. If the <em>"Disable by default"</em> option was selected during kernel configuration, remember to include "caitsith=on" in the kernel boot options. Consult the documentation for your distribution and bootloader to find out how to boot your CaitSith kernel.</p>
377    
378 kumaneko 22 <p>CaitSith supports the kernel boot option "CCS_trigger". This is useful for systems that run a program other than <code>/sbin/init</code> on startup, for example when booting using systemd which uses <code>/bin/systemd</code>. In this case, you should include "CCS_trigger=<code>/bin/systemd</code>" in the kernel boot options.</p>
379 kumaneko 15
380 kumaneko 16 <pre>
381     # grub.conf generated by anaconda
382     #
383     # Note that you do not have to rerun grub after making changes to this file
384     # NOTICE: You do not have a /boot partition. This means that
385     # all kernel and initrd paths are relative to /, eg.
386     # root (hd0,0)
387     # kernel /boot/vmlinuz-version ro root=/dev/sda1
388     # initrd /boot/initrd-[generic-]version.img
389     #boot=/dev/sda
390     default=1
391     timeout=5
392     splashimage=(hd0,0)/boot/grub/splash.xpm.gz
393     #hiddenmenu
394     title CentOS (3.2.14-caitsith)
395     root (hd0,0)
396     kernel /boot/vmlinuz-3.2.14-caitsith ro root=UUID=cc8371f3-bb2c-47b4-bd8f-318124f523df rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=jp106 crashkernel=auto
397     initrd /boot/initramfs-3.2.14-caitsith.img
398     title CentOS (2.6.32-220.7.1.el6.i686)
399     root (hd0,0)
400     kernel /boot/vmlinuz-2.6.32-220.7.1.el6.i686 ro root=UUID=cc8371f3-bb2c-47b4-bd8f-318124f523df rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=jp106 crashkernel=auto
401     initrd /boot/initramfs-2.6.32-220.7.1.el6.i686.img
402     </pre>
403    
404 kumaneko 33 <p>In Fedora 17, /sbin/init exists as a symlink to /usr/lib/systemd/systemd . However, since /init script in the initramfs tries to execute /usr/lib/systemd/systemd (the pathname printed by readlink command) rather than /sbin/init (the pathname passed to readlink command), the trigger for activating CaitSith is /usr/lib/systemd/systemd rather than /sbin/init :</p>
405    
406     <pre>
407     # By the time we get here, the root filesystem should be mounted.
408     # Try to find init.
409     for i in "$(getarg real_init=)" "$(getarg init=)" $(getargs rd.distroinit=) /sbin/init; do
410     [ -n "$i" ] || continue
411    
412     __p=$(readlink -f "${NEWROOT}/${i}")
413     if [ -x "$__p" ]; then
414     INIT="$i"
415     break
416     fi
417     done
418     </pre>
419    
420     <p>Therefore, in Fedora 17, you need to include "CCS_trigger=/usr/lib/systemd/systemd" in the kernel boot options if you didn't specify /usr/lib/systemd/systemd at <a href="#2.3">2.3. Configure the kernel</a>. You may directly edit /boot/grub2/grub.cfg file. But it is recommended that you also modify GRUB_CMDLINE_LINUX line in /etc/default/grub file like below in case you update kernel packages in the future:</p>
421    
422     <pre>
423     GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=True rd.luks=0 KEYTABLE=en LANG=en_US.UTF-8 rhgb quiet CCS_trigger=/usr/lib/systemd/systemd"
424     </pre>
425    
426 kumaneko 30 <hr>
427 kumaneko 15 <h3><a name="2.8">2.8. Rebooting your system</a></h3>
428    
429 kumaneko 16 <p>Now you have finished all preparation. Reboot your system and choose the entry with CaitSith kernel at the GRUB screen, or at whatever other bootloader you have installed:</p>
430 kumaneko 15
431 kumaneko 16 <img src="media/grub-screen.png" alt="grub-screen.png" title="Select CaitSith enabled kernel" width="640" height="480">
432 kumaneko 15
433     <p>If everything was installed properly and the bootloader was correctly configured, the kernel should boot as normal and CaitSith should be activated:</p>
434    
435 kumaneko 16 <img src="media/caitsith-activated.png" alt="caitsith-activated.png" title="CaitSith activated" width="720" height="400">
436 kumaneko 15
437 kumaneko 30 <hr>
438 kumaneko 15 <h3><a name="2.9">2.9. How can I disable/uninstall CaitSith?</a></h3>
439    
440 kumaneko 28 <p>If your system becomes unable to boot during the course of this guide or any time in the future, it may be due to policy configuration or something related to CaitSith. If this is the case, it is possible that the kernel can still be booted by disabling CaitSith. This can be done by appending "caitsith=off" at the kernel's command line options.</p>
441 kumaneko 15
442     <p>CaitSith fortunately does not require the modification of any existing Linux binaries, libraries or applications. Thus, uninstalling CaitSith is very easy. It is simply a matter of uninstalling the kernel and userspace tools that you installed above. You can reboot with the kernel provided by your distribution and then remove the entry from your bootloader.</p>
443    
444 kumaneko 30 <hr>
445 kumaneko 10 <h2><a name="how_to_develop_policy">3. How to develop policy</a></h2>
446    
447 kumaneko 30 <hr>
448 kumaneko 16 <h3><a name="3.1">3.1. Policy file structure</a></h3>
449 kumaneko 10
450 kumaneko 16 <p>CaitSith's policy file consists with "Header part" and "ACL part".</p>
451 kumaneko 10
452 kumaneko 17 <h4><a name="3.1.1">3.1.1. Header part of policy file</a></h4>
453    
454 kumaneko 16 <p>Header part consists with below lines.</p>
455 kumaneko 10
456 kumaneko 16 <pre>
457     POLICY_VERSION=20120401
458 kumaneko 17 stat $stat_name $stat_value
459 kumaneko 16 quota memory policy $max_byte_for_policy
460     quota memory audit $max_byte_for_audit_logs
461     quota memory query $max_byte_for_query
462     quota audit[$audit_index] allowed=$max_logs_for_allowed_request unmatched=$max_logs_for_unmatched_request denied=$max_logs_for_denied_request
463     string_group $string_group_name $string_group_member
464     number_group $number_group_name $number_group_member
465     ip_group $ip_group_name $ip_group_member
466     </pre>
467 kumaneko 10
468 kumaneko 16 <ul>
469     <li>POLICY_VERSION line defines policy version.</li>
470 kumaneko 17 <li>stat lines are for showing statistics information such as memory usage. $stat_name and $stat_value are simply ignored.</li>
471 kumaneko 16 <li>$max_byte_for_policy is max amount of memory in byte which can be allocated for policy. Default is unlimited.</li>
472     <li>$max_byte_for_audit_logs is max amount of memory in byte which can be allocated for audit logs. Default is unlimited. $max_byte_for_audit_logs=16777216 should be sufficient.</li>
473     <li>$max_byte_for_query is max amount of memory in byte which can be allocated for interactive enforcement. Default is unlimited. $max_byte_for_audit_logs=1048576 should be sufficient.</li>
474     <li>quota audit[$audit_index] lines (0 &lt;= $audit_index &lt;= 255) are max number of audit logs which can be held in the kernel space. $max_logs_for_allowed_request is for allowed requests. $max_logs_for_unmatched_request is for unmatched requests. $max_logs_for_denied_request is for denied requests. Default is 0. Unless you have special reasons, you should set 0 to $max_logs_for_allowed_request. Regarding $max_logs_for_unmatched_request and $max_logs_for_denied_request, 1024 should be sufficient.</li>
475     <li>string_group $string_group_name lines define group of strings. $string_group_member is a member for $string_group_name group.</li>
476     <li>number_group $number_group_name lines define group of numbers. $number_group_member is a member for $number_group_name group.</li>
477     <li>ip_group $ip_group_name lines define group of IP addresses. $ip_group_member is a member for $ip_group_name group.</li>
478     </ul>
479 kumaneko 10
480 kumaneko 17 <h4><a name="3.1.2">3.1.2. ACL part of policy file</a></h4>
481 kumaneko 16
482 kumaneko 17 <p>ACL part consists with 0 or more repetitions of below block.</p>
483    
484 kumaneko 16 <pre>
485     $acl_priority acl $operation $conditions_to_filter
486     audit $audit_index
487     $cond_priority $decision $conditions_to_allow_or_deny
488     </pre>
489    
490     <ul>
491     <li>A block which starts with $acl_priority determines whether to evaluate rules in this block or not.</li>
492     <li>Blocks which start with $acl_priority can be defined as many as you need.</li>
493     <li>$acl_priority is a priority (an integer between 0 and 65535) which controls which block should be evaluated first (among all blocks defined in the policy).</li>
494     <li>Blocks are evaluated from smaller $acl_priority values to larger $acl_priority values.</li>
495     <li>If two blocks have same $acl_priority value, the block which is defined first is evaluated first.</li>
496     <li>$operation is "operation".</li>
497     <li>$conditions_to_filter is "conditional expressions" which can be applied to "operation". Omit $conditions_to_filter to evaluate this block unconditionally.</li>
498     <li>Access requests will be denied if one of deny lines (among all blocks defined in the policy) matches.</li>
499     </ul>
500    
501     <p>$decision lines in a block is evaluated only when the block's $acl_priority line matched.</p>
502    
503     <ul>
504     <li>A line which starts with $cond_priority determines whether to grant the access request or not.</li>
505     <li>Lines which start with $cond_priority can be defined as many as you need.</li>
506     <li>$cond_priority is a priority (an integer between 0 and 65535) which controls which line should be checked first (among all lines defined in the block).</li>
507     <li>Lines are checked from smaller $cond_priority values to larger priority values.</li>
508     <li>If two lines have same $cond_priority value, the line which is defined first is checked first.</li>
509     <li>$decision is either allow or deny.</li>
510     <li>$conditions_to_allow_or_deny is "conditional expressions" which can be applied to "operation". Omit $conditions_to_allow_or_deny to match this line unconditionally.</li>
511     </ul>
512    
513     <p>Checking of $decision lines in a block lasts until it matches a $decision line or it reaches to the end of block.</p>
514    
515     <ul>
516     <li>If $conditions_to_allow_or_deny of a deny line matches, the access request is denied. At the same time, access denied log is generated if memory used for audit logs is smaller than $max_byte_for_audit_logs bytes and number of denied logs which is in the kernel is smaller than $max_logs_for_denied_request of quota audit[$audit_index] line where $audit_index is specified by audit line of this block.</li>
517     <li>If $conditions_to_allow_or_deny of an allow line matches, the evaluation of this block ends and proceeds to next block. At the same time, access allowed log is generated if memory used for audit logs is smaller than $max_byte_for_audit_logs bytes and number of allowed logs which is in the kernel is smaller than $max_logs_for_allowed_request of quota audit[$audit_index] line where $audit_index is specified by audit line of this block.</li>
518     <li>If none of $conditions_to_allow_or_deny matches, the evaluation of this block ends and proceeds to next block. At the same time, access unmatched log is generated if memory used for audit logs is smaller than $max_byte_for_audit_logs bytes and number of unmatched logs which is in the kernel is smaller than $max_logs_for_unmatched_request of quota audit[$audit_index] line where $audit_index is specified by audit line of this block.</li>
519     </ul>
520    
521 kumaneko 30 <p>Access requests will be denied only when "deny" line of "acl" block matched. (There are two exceptions. Regarding permission to change domains manually (i.e. <a href="#5.60">acl manual_domain_transition</a> blocks) and permission to change domains automatically (i.e. <a href="#5.61">acl auto_domain_transition</a> blocks), access requests will be granted only when "allow" line of all blocks match, in order to avoid unintended domain transition.)</p>
522 kumaneko 16
523     <p>$acl_priority and $cond_priority values are used for two purposes. One is for selectively deny operations using "deny" lines. For example,</p>
524    
525     <pre>
526     10 acl read path.fsmagic=0x9FA0
527     audit 0
528     10 deny path="proc:/cmdline"
529     20 allow
530     </pre>
531    
532 kumaneko 22 <p>denies opening <code>/proc/cmdline</code> on the proc filesystem (proc filesystem's magic number is 0x9FA0) for reading while allowing opening all other files.</p>
533 kumaneko 16
534 kumaneko 30 <p>The other is for controlling which "transition=" and "handler=" arguments should be used when these arguments matched more than once. This will be explained in <a href="#advanced_usage">advanced usage</a>.</p>
535 kumaneko 16
536 kumaneko 17 <h4><a name="3.1.3">3.1.3. An example policy file</a></h4>
537    
538 kumaneko 22 <p>Below is an example of <code>/etc/caitsith/policy/current</code> file on CentOS. The content of this file varies depending on environments you are using, and will be updated as you develop policy.</p>
539 kumaneko 16
540     <pre>
541     POLICY_VERSION=20120401
542    
543     quota memory audit 16777216
544     quota memory query 1048576
545     quota audit[1] allowed=0 denied=1024 unmatched=1024
546    
547     10000 acl execute
548     audit 0
549     10 allow path="/sbin/modprobe" transition="/sbin/modprobe"
550     10 allow path="/sbin/init" transition="/sbin/init"
551     10 allow path="/sbin/mingetty" transition="/sbin/mingetty"
552     10 allow path="/sbin/udevd" transition="/sbin/udevd"
553     10 allow path="/usr/sbin/anacron" transition="/usr/sbin/anacron"
554     10 allow path="/usr/sbin/crond" transition="/usr/sbin/crond"
555     10 allow path="/usr/sbin/httpd" transition="/usr/sbin/httpd"
556     10 allow path="/usr/sbin/logrotate" transition="/usr/sbin/logrotate"
557     10 allow path="/usr/sbin/nmbd" transition="/usr/sbin/nmbd"
558     10 allow path="/usr/sbin/smbd" transition="/usr/sbin/smbd"
559     10 allow path="/usr/sbin/sshd" transition="/usr/sbin/sshd"
560     10 allow path="/etc/rc.d/init.d/ntpd" transition="/etc/rc.d/init.d/ntpd"
561     10 allow path="/etc/rc.d/init.d/single" transition="/etc/rc.d/init.d/single"
562     10 allow path="/etc/rc.d/init.d/killall" transition="/etc/rc.d/init.d/killall"
563     10 allow path="/etc/rc.d/init.d/ip6tables" transition="/etc/rc.d/init.d/ip6tables"
564     10 allow path="/etc/rc.d/init.d/halt" transition="/etc/rc.d/init.d/halt"
565     10 allow path="/etc/rc.d/init.d/netfs" transition="/etc/rc.d/init.d/netfs"
566     10 allow path="/etc/rc.d/init.d/messagebus" transition="/etc/rc.d/init.d/messagebus"
567     10 allow path="/etc/rc.d/init.d/sandbox" transition="/etc/rc.d/init.d/sandbox"
568     10 allow path="/etc/rc.d/init.d/rsyslog" transition="/etc/rc.d/init.d/rsyslog"
569     10 allow path="/etc/rc.d/init.d/smb" transition="/etc/rc.d/init.d/smb"
570     10 allow path="/etc/rc.d/init.d/sshd" transition="/etc/rc.d/init.d/sshd"
571     10 allow path="/etc/rc.d/init.d/cgconfig" transition="/etc/rc.d/init.d/cgconfig"
572     10 allow path="/etc/rc.d/init.d/udev-post" transition="/etc/rc.d/init.d/udev-post"
573     10 allow path="/etc/rc.d/init.d/firstboot" transition="/etc/rc.d/init.d/firstboot"
574     10 allow path="/etc/rc.d/init.d/ntpdate" transition="/etc/rc.d/init.d/ntpdate"
575     10 allow path="/etc/rc.d/init.d/crond" transition="/etc/rc.d/init.d/crond"
576     10 allow path="/etc/rc.d/init.d/restorecond" transition="/etc/rc.d/init.d/restorecond"
577     10 allow path="/etc/rc.d/init.d/httpd" transition="/etc/rc.d/init.d/httpd"
578     10 allow path="/etc/rc.d/init.d/rdisc" transition="/etc/rc.d/init.d/rdisc"
579     10 allow path="/etc/rc.d/init.d/postfix" transition="/etc/rc.d/init.d/postfix"
580     10 allow path="/etc/rc.d/init.d/saslauthd" transition="/etc/rc.d/init.d/saslauthd"
581     10 allow path="/etc/rc.d/init.d/netconsole" transition="/etc/rc.d/init.d/netconsole"
582     10 allow path="/etc/rc.d/init.d/network" transition="/etc/rc.d/init.d/network"
583     10 allow path="/etc/rc.d/init.d/avahi-daemon" transition="/etc/rc.d/init.d/avahi-daemon"
584     10 allow path="/etc/rc.d/init.d/auditd" transition="/etc/rc.d/init.d/auditd"
585     10 allow path="/etc/rc.d/init.d/nmb" transition="/etc/rc.d/init.d/nmb"
586     10 allow path="/etc/rc.d/init.d/iptables" transition="/etc/rc.d/init.d/iptables"
587     10 allow path="/etc/rc.d/init.d/cgred" transition="/etc/rc.d/init.d/cgred"
588    
589     0 acl modify_policy
590     audit 1
591     1 deny task.uid!=0
592     1 deny task.euid!=0
593     100 allow task.exe="/usr/sbin/caitsith-loadpolicy"
594     100 allow task.exe="/usr/sbin/caitsith-queryd"
595     10000 deny
596     </pre>
597    
598 kumaneko 30 <hr>
599 kumaneko 16 <h3><a name="3.2">3.2. Updating policy configuration</a></h3>
600    
601     <p>There are two ways to update policy configuration.</p>
602    
603 kumaneko 22 <p>One is to use <code>/sbin/caitsith-init</code> which is automatically called when <code>/sbin/init</code> starts. <code>/sbin/caitsith-init</code> reads policy from <code>/etc/caitsith/policy/current</code> and writes to <code>/proc/caitsith/policy</code> interface. Therefore, you can update policy configuration by updating <code>/etc/caitsith/policy/current</code> and rebooting your system.</p>
604 kumaneko 16
605 kumaneko 22 <p>The other is to use <code>/usr/sbin/caitsith-loadpolicy</code> which is defined for loading policy after your system has booted. <code>/usr/sbin/caitsith-loadpolicy</code> reads policy from standard input and writes to <code>/proc/caitsith/policy</code> interface. Therefore, you can update policy configuration without updating <code>/etc/caitsith/policy/current</code> and rebooting your system. For example, if you want to append a "string_group mygroup1 /" line to <code>/proc/caitsith/policy</code> interface, run below command:</p>
606 kumaneko 16
607     <pre class="command">
608     # echo 'string_group mygroup1 /' | /usr/sbin/caitsith-loadpolicy
609     </pre>
610    
611 kumaneko 22 <p>If you want to delete the "string_group mygroup1 /" line from <code>/proc/caitsith/policy</code> interface, run below command:</p>
612 kumaneko 16
613     <pre class="command">
614     # echo 'delete string_group mygroup1 /' | /usr/sbin/caitsith-loadpolicy
615     </pre>
616    
617 kumaneko 22 <p>The contents in <code>/proc/caitsith/policy</code> will be lost when your system shuts down or reboots. To save <code>/proc/caitsith/policy</code> as <code>/etc/caitsith/policy/current</code>, run below command:</p>
618 kumaneko 16
619     <pre class="command">
620     # /usr/sbin/caitsith-savepolicy
621     </pre>
622    
623 kumaneko 30 <hr>
624 kumaneko 16 <h3><a name="3.3">3.3. Example of simple access restriction rule</a></h3>
625    
626 kumaneko 17 <p>Let's experience how CaitSith restricts access using simple examples.</p>
627    
628     <h4><a name="3.3.1">3.3.1. Telling CaitSith which access requests should be checked</a></h4>
629    
630     <p>By default, CaitSith does not deny access requests. To restrict access requests, you need to tell CaitSith which access requests should be denied.</p>
631    
632 kumaneko 22 <p>Below rule will check access requests which open <code>/tmp/file1</code> for reading.</p>
633 kumaneko 17
634     <pre>
635     100 acl read path="/tmp/file1"
636     audit 1
637     </pre>
638    
639 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>. Since <code>/usr/sbin/caitsith-loadpolicy</code> reads policy from standard input, you can use ^D (Ctrl-D) to indicate end of input:</p>
640 kumaneko 17
641     <pre class="command">
642     # /usr/sbin/caitsith-loadpolicy
643     </pre>
644     <pre>
645     100 acl read path="/tmp/file1"
646     audit 1
647     ^D
648     </pre>
649    
650     <p>You may use a temporary file if you worry typos.</p>
651    
652     <pre class="command">
653     # cat &gt; ~/policy.tmp
654     </pre>
655     <pre>
656     100 acl read path="/tmp/file1"
657     audit 1
658     ^D
659     </pre>
660     <pre class="command">
661     # /usr/sbin/caitsith-loadpolicy &lt; ~/policy.tmp
662     # rm ~/policy.tmp
663     </pre>
664    
665 kumaneko 22 <p>You can confirm that above rule is appended to <code>/proc/caitsith/policy</code> by reading <code>/proc/caitsith/policy</code>.</p>
666 kumaneko 17
667     <pre class="command">
668     # cat /proc/caitsith/policy
669     </pre>
670     <pre>
671     POLICY_VERSION=20120401
672     stat Policy updated: 7 (Last: 2012/04/08 04:56:45)
673     stat Requests denied: 0
674     stat Memory used by policy: 6048
675     stat Memory used by audit: 0
676     stat Memory used by query: 0
677     quota memory audit 16777216
678     quota memory query 1048576
679     quota audit[1] allowed=0 denied=1024 unmatched=1024
680    
681     10000 acl execute
682     audit 0
683     10 allow path="/sbin/modprobe" transition="/sbin/modprobe"
684     10 allow path="/sbin/init" transition="/sbin/init"
685     10 allow path="/sbin/mingetty" transition="/sbin/mingetty"
686     10 allow path="/sbin/udevd" transition="/sbin/udevd"
687     10 allow path="/usr/sbin/anacron" transition="/usr/sbin/anacron"
688     10 allow path="/usr/sbin/crond" transition="/usr/sbin/crond"
689     10 allow path="/usr/sbin/httpd" transition="/usr/sbin/httpd"
690     10 allow path="/usr/sbin/logrotate" transition="/usr/sbin/logrotate"
691     10 allow path="/usr/sbin/nmbd" transition="/usr/sbin/nmbd"
692     10 allow path="/usr/sbin/smbd" transition="/usr/sbin/smbd"
693     10 allow path="/usr/sbin/sshd" transition="/usr/sbin/sshd"
694     10 allow path="/etc/rc.d/init.d/ntpd" transition="/etc/rc.d/init.d/ntpd"
695     10 allow path="/etc/rc.d/init.d/single" transition="/etc/rc.d/init.d/single"
696     10 allow path="/etc/rc.d/init.d/killall" transition="/etc/rc.d/init.d/killall"
697     10 allow path="/etc/rc.d/init.d/ip6tables" transition="/etc/rc.d/init.d/ip6tables"
698     10 allow path="/etc/rc.d/init.d/halt" transition="/etc/rc.d/init.d/halt"
699     10 allow path="/etc/rc.d/init.d/netfs" transition="/etc/rc.d/init.d/netfs"
700     10 allow path="/etc/rc.d/init.d/messagebus" transition="/etc/rc.d/init.d/messagebus"
701     10 allow path="/etc/rc.d/init.d/sandbox" transition="/etc/rc.d/init.d/sandbox"
702     10 allow path="/etc/rc.d/init.d/rsyslog" transition="/etc/rc.d/init.d/rsyslog"
703     10 allow path="/etc/rc.d/init.d/smb" transition="/etc/rc.d/init.d/smb"
704     10 allow path="/etc/rc.d/init.d/sshd" transition="/etc/rc.d/init.d/sshd"
705     10 allow path="/etc/rc.d/init.d/cgconfig" transition="/etc/rc.d/init.d/cgconfig"
706     10 allow path="/etc/rc.d/init.d/udev-post" transition="/etc/rc.d/init.d/udev-post"
707     10 allow path="/etc/rc.d/init.d/firstboot" transition="/etc/rc.d/init.d/firstboot"
708     10 allow path="/etc/rc.d/init.d/ntpdate" transition="/etc/rc.d/init.d/ntpdate"
709     10 allow path="/etc/rc.d/init.d/crond" transition="/etc/rc.d/init.d/crond"
710     10 allow path="/etc/rc.d/init.d/restorecond" transition="/etc/rc.d/init.d/restorecond"
711     10 allow path="/etc/rc.d/init.d/httpd" transition="/etc/rc.d/init.d/httpd"
712     10 allow path="/etc/rc.d/init.d/rdisc" transition="/etc/rc.d/init.d/rdisc"
713     10 allow path="/etc/rc.d/init.d/postfix" transition="/etc/rc.d/init.d/postfix"
714     10 allow path="/etc/rc.d/init.d/saslauthd" transition="/etc/rc.d/init.d/saslauthd"
715     10 allow path="/etc/rc.d/init.d/netconsole" transition="/etc/rc.d/init.d/netconsole"
716     10 allow path="/etc/rc.d/init.d/network" transition="/etc/rc.d/init.d/network"
717     10 allow path="/etc/rc.d/init.d/avahi-daemon" transition="/etc/rc.d/init.d/avahi-daemon"
718     10 allow path="/etc/rc.d/init.d/auditd" transition="/etc/rc.d/init.d/auditd"
719     10 allow path="/etc/rc.d/init.d/nmb" transition="/etc/rc.d/init.d/nmb"
720     10 allow path="/etc/rc.d/init.d/iptables" transition="/etc/rc.d/init.d/iptables"
721     10 allow path="/etc/rc.d/init.d/cgred" transition="/etc/rc.d/init.d/cgred"
722    
723     100 acl read path="/tmp/file1"
724     audit 1
725    
726     0 acl modify_policy
727     audit 1
728     1 deny task.uid!=0
729     1 deny task.euid!=0
730     100 allow task.exe="/usr/sbin/caitsith-loadpolicy"
731     100 allow task.exe="/usr/sbin/caitsith-queryd"
732     10000 deny
733     </pre>
734    
735     <h4><a name="3.3.2">3.3.2. Access requests which will be implicitly allowed by CaitSith</a></h4>
736    
737 kumaneko 22 <p>Make sure that <code>/usr/sbin/caitsith-auditd</code> is running.</p>
738 kumaneko 17
739     <pre class="command">
740     # pidof caitsith-auditd
741     </pre>
742     <pre>
743     3627
744     </pre>
745    
746 kumaneko 22 <p>Now, create <code>/tmp/file1</code> file.</p>
747 kumaneko 17
748     <pre class="command">
749     # touch /tmp/file1
750     </pre>
751    
752 kumaneko 22 <p>Then, open <code>/tmp/file1</code> for reading.</p>
753 kumaneko 17
754     <pre class="command">
755     # cat /tmp/file1
756     </pre>
757    
758 kumaneko 22 <p>Check <code>/var/log/caitsith/unmatched.log</code> for access unmatched log of this access request. You will find an entry like below:</p>
759 kumaneko 17
760     <pre class="command">
761     # grep /tmp/file1 /var/log/caitsith/unmatched.log
762     </pre>
763     <pre>
764     #2012/04/08 04:58:40# global-pid=3678 result=unmatched priority=100 / read path="/tmp/file1" task.pid=3678 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
765     </pre>
766    
767 kumaneko 19 <p>Note the <strong>result=unmatched</strong> part of the entry. This indicates that access request was checked but matched neither "allow" nor "deny" rule.</p>
768 kumaneko 17
769 kumaneko 19 <p>Note the <strong>priority=100</strong> part of the entry. This indicates that this entry was generated by rules which have 100 as priority.</p>
770 kumaneko 17
771 kumaneko 22 <p>Note the <strong>read path="<code>/tmp/file1</code>"</strong> part of the entry. This indicates that this entry was generated by access request of opening <code>/tmp/file1</code> for reading.</p>
772 kumaneko 17
773     <h4><a name="3.3.3">3.3.3. Access requests which will be explicitly denied by CaitSith</a></h4>
774    
775     <p>Now, let's add a rule to explicitly deny this request.</p>
776    
777     <pre>
778     100 acl read path="/tmp/file1"
779     1000 deny
780     </pre>
781    
782 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>:</p>
783 kumaneko 17
784     <pre class="command">
785     # /usr/sbin/caitsith-loadpolicy
786     </pre>
787     <pre>
788     100 acl read path="/tmp/file1"
789     1000 deny
790     ^D
791     </pre>
792    
793 kumaneko 22 <p>Rules that have same priority (in this rule, 100) and same operation (in this rule, read) and same condition (in this rule, path="<code>/tmp/file1</code>") are automatically merged. Therefore, you will find</p>
794 kumaneko 17
795     <pre>
796     100 acl read path="/tmp/file1"
797     audit 1
798     1000 deny
799     </pre>
800    
801     <p>rather than</p>
802    
803     <pre>
804     100 acl read path="/tmp/file1"
805     audit 1
806    
807     100 acl read path="/tmp/file1"
808     1000 deny
809     </pre>
810    
811 kumaneko 22 <p>when you read <code>/proc/caitsith/policy</code>.</p>
812 kumaneko 17
813 kumaneko 22 <p>Then, open <code>/tmp/file1</code> for reading.</p>
814 kumaneko 17
815     <pre class="command">
816     # cat /tmp/file1
817     </pre>
818     <pre>
819     cat: /tmp/file1: Operation not permitted
820     </pre>
821    
822     <p>This time, access request was denied by CaitSith.</p>
823    
824 kumaneko 22 <p>Check <code>/var/log/caitsith/denied.log</code> for access denied log of this access request. You will find an entry like below:</p>
825 kumaneko 17
826     <pre class="command">
827     # grep /tmp/file1 /var/log/caitsith/denied.log
828     </pre>
829     <pre>
830     #2012/04/08 04:59:53# global-pid=3682 result=denied priority=100 / read path="/tmp/file1" task.pid=3682 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
831     </pre>
832    
833 kumaneko 19 <p>Note the <strong>result=denied</strong> part of the entry. This indicates that access request was checked and matched "deny" rule.</p>
834 kumaneko 17
835 kumaneko 22 <p>If <code>/usr/sbin/ccs-notifyd</code> is running, you will receive a notification mail. The content is same with access denied logs.</p>
836 kumaneko 17
837     <pre class="command">
838     # mail
839     </pre>
840     <pre>
841     Heirloom Mail version 12.4 7/29/08. Type ? for help.
842     "/var/spool/mail/root": 1 message 1 new
843     &gt;N 1 root Sun Apr 8 13:59 20/1231 "Notification from caitsith-notifyd"
844     &amp;
845     Message 1:
846     From root@ccsecurity.localdomain Sun Apr 8 13:59:53 2012
847     Return-Path: &lt;root@ccsecurity.localdomain&gt;
848     X-Original-To: root@localhost
849     Delivered-To: root@localhost.localdomain
850     Date: Sun, 08 Apr 2012 13:59:53 +0900
851     To: root@localhost.localdomain
852     Subject: Notification from caitsith-notifyd
853     User-Agent: Heirloom mailx 12.4 7/29/08
854     Content-Type: text/plain; charset=us-ascii
855     From: root@caitsith.localdomain (root)
856     Status: R
857    
858     Q0-0
859     #2012/04/08 04:59:53# global-pid=3682 result=denied priority=100 / read path="/tmp/file1" task.pid=3682 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
860     </pre>
861    
862     <p>Now, let's remove a rule to explicitly deny this request.</p>
863    
864     <pre>
865     100 acl read path="/tmp/file1"
866     delete 1000 deny
867     </pre>
868    
869 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>:</p>
870 kumaneko 17
871     <pre class="command">
872     # /usr/sbin/caitsith-loadpolicy
873     </pre>
874     <pre>
875     100 acl read path="/tmp/file1"
876     delete 1000 deny
877     ^D
878     </pre>
879    
880     <p>You will find</p>
881    
882     <pre>
883     100 acl read path="/tmp/file1"
884     audit 1
885     </pre>
886    
887     <p>rather than</p>
888    
889     <pre>
890     100 acl read path="/tmp/file1"
891     audit 1
892     1000 deny
893     delete 1000 deny
894     </pre>
895    
896 kumaneko 22 <p>when you read <code>/proc/caitsith/policy</code>.</p>
897 kumaneko 17
898     <h4><a name="3.3.4">3.3.4. Filtering audit logs</a></h4>
899    
900 kumaneko 22 <p>Now, open <code>/tmp/file1</code> for reading.</p>
901 kumaneko 17
902     <pre class="command">
903     # cat /tmp/file1
904     </pre>
905    
906 kumaneko 22 <p>Check <code>/var/log/caitsith/unmatched.log</code> for access unmatched log of this access request. You will find entries like below:</p>
907 kumaneko 17
908     <pre class="command">
909     # grep /tmp/file1 /var/log/caitsith/unmatched.log
910     </pre>
911     <pre>
912     #2012/04/08 04:58:40# global-pid=3678 result=unmatched priority=100 / read path="/tmp/file1" task.pid=3678 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
913     #2012/04/08 05:01:00# global-pid=3695 result=unmatched priority=100 / read path="/tmp/file1" task.pid=3695 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
914     </pre>
915    
916     <p>The former entry was generated before adding explicit "deny" rule. The latter entry was generated after removing explicit "deny" rule. You might want to filter the output using tail command:</p>
917    
918     <pre class="command">
919     # grep /tmp/file1 /var/log/caitsith/unmatched.log | tail -n 1
920     </pre>
921     <pre>
922     #2012/04/08 05:01:00# global-pid=3695 result=unmatched priority=100 / read path="/tmp/file1" task.pid=3695 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
923     </pre>
924    
925     <h4><a name="3.3.5">3.3.5. Access requests which will be explicitly allowed by CaitSith</a></h4>
926    
927     <p>Next, let's see audit logs with explicitly matching "allow" rules.</p>
928    
929     <p>By default CaitSith does not generate audit logs with explicitly matching "allow" rules. Change policy configuration to generate such logs.</p>
930    
931     <pre>
932     quota audit[1] allowed=1024
933     </pre>
934    
935 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>:</p>
936 kumaneko 17
937     <pre class="command">
938     # echo 'quota audit[1] allowed=1024' | /usr/sbin/caitsith-loadpolicy
939     </pre>
940    
941     <p>Preferences that have same name (in this rule, audit[1]) are automatically merged. Therefore, you will find</p>
942    
943     <pre>
944     quota audit[1] allowed=1024 denied=1024 unmatched=1024
945     </pre>
946    
947     <p>rather than</p>
948    
949     <pre>
950     quota audit[1] allowed=0 denied=1024 unmatched=1024
951     quota audit[1] allowed=1024
952     </pre>
953    
954 kumaneko 22 <p>when you read <code>/proc/caitsith/policy</code>.</p>
955 kumaneko 17
956     <pre>
957     100 acl read path="/tmp/file1"
958     1000 allow
959     </pre>
960    
961 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>:</p>
962 kumaneko 17
963     <pre class="command">
964     # /usr/sbin/caitsith-loadpolicy
965     </pre>
966     <pre>
967     100 acl read path="/tmp/file1"
968     1000 allow
969     ^D
970     </pre>
971    
972 kumaneko 22 <p>Since audit logs with explicitly matching "allow" rules tend to grow rapidly, by default <code>/usr/sbin/caitsith-auditd</code> discards such logs by writing to <code>/dev/null</code> (specified in <code>/etc/caitsith/tools/auditd.conf</code>).
973     Therefore, temporarily stop <code>/usr/sbin/caitsith-auditd</code> process in order to read audit logs from <code>/proc/caitsith/audit</code> interface.</p>
974 kumaneko 17
975     <pre class="command">
976     # killall -KILL caitsith-auditd
977     </pre>
978    
979 kumaneko 22 <p>Then, open <code>/tmp/file1</code> for reading.</p>
980 kumaneko 17
981     <pre class="command">
982     # cat /tmp/file1
983     </pre>
984    
985 kumaneko 22 <p>Check <code>/proc/caitsith/audit</code> for audit log of this access request. This time, you will find an entry like below:</p>
986 kumaneko 17
987     <pre class="command">
988     # cat -v /proc/caitsith/audit
989     </pre>
990     <pre>
991     #2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
992     ^@
993     </pre>
994    
995 kumaneko 19 <p>Note the <strong>result=allowed</strong> part of the entry. This indicates that access request was checked and matched "allow" rule.</p>
996 kumaneko 17
997 kumaneko 22 <p>Restart <code>/usr/sbin/caitsith-auditd</code> process.</p>
998 kumaneko 17
999     <pre class="command">
1000     # /usr/sbin/caitsith-auditd
1001     </pre>
1002    
1003     <p>Also, restore the audit logs configuration:</p>
1004    
1005     <pre>
1006     quota audit[1] allowed=0
1007     </pre>
1008    
1009 kumaneko 22 <p>Append above rule using <code>/usr/sbin/caitsith-loadpolicy</code>:</p>
1010 kumaneko 17
1011     <pre class="command">
1012     # echo 'quota audit[1] allowed=0' | /usr/sbin/caitsith-loadpolicy
1013     </pre>
1014    
1015 kumaneko 30 <hr>
1016 kumaneko 20 <h3><a name="3.4">3.4. Understanding two viewpoints</a></h3>
1017 kumaneko 18
1018 kumaneko 20 <p>CaitSith supports writing access restriction rules from two viewpoints. One is from the point of view of "subject" (a resource which requests access on object). The other is from the point of view of "object" (a resource which subject requests access).</p>
1019    
1020     <p>The advantage of the former approach is that the rules clearly explains and restricts what each subject is allowed to access which object.
1021     This approach is powerful when you can afford identifying all possible subjects and defining the rules for each subject.
1022     But the disadvantage is that it is difficult to identify all possible subjects and define the rules for each subject.
1023     Therefore, in reality, this approach tends to restrict only specific subjects.
1024     If one of subjects which is not restricted by this approach is cracked or misbehaved, nothing can protect objects you want to protect.</p>
1025    
1026     <p>The advantage of the latter approach is that the rules clearly explains and restricts what object might be accessed by which subject.
1027     This approach is powerful when you can afford identifying objects you want to protect and defining rules for each object.
1028     This approach can compensate for the disadvantage of the former approach because this approach can restrict access even it is difficult to
1029     identify all possible subjects and define the rules for each possible subjects.</p>
1030    
1031     <h4><a name="3.4.1">3.4.1. Writing access restriction rules from the point of view of "subject".</a></h4>
1032    
1033 kumaneko 22 <p>Below entry is an example of restricting programs which can be executed from <code>/usr/sbin/httpd</code> program.</p>
1034 kumaneko 20
1035     <pre>
1036     0 acl execute task.exe="/usr/sbin/httpd"
1037     audit 1
1038     1 allow path="/var/www/cgi-bin/counter.cgi"
1039     100 deny
1040     </pre>
1041    
1042 kumaneko 22 <p>The <strong>0 acl execute task.exe="<code>/usr/sbin/httpd</code>"</strong> line means check rules for executing programs from <code>/usr/sbin/httpd</code> program. Since <strong>task.exe="<code>/usr/sbin/httpd</code>"</strong> is specified in this line, this line tells CaitSith <strong>check rules for executing programs only if current thread's program name is <code>/usr/sbin/httpd</code></strong>.</p>
1043 kumaneko 20
1044 kumaneko 22 <p>The line <strong>1 allow path="<code>/var/www/cgi-bin/counter.cgi</code>"</strong> means that allow if the pathname of the program to execute is <code>/var/www/cgi-bin/counter.cgi</code>. This line tells CaitSith "allow execution of <code>/var/www/cgi-bin/counter.cgi</code>".</p>
1045 kumaneko 20
1046     <p>The line <strong>100 deny</strong> means deny unconditionally. This tells CaitSith "unconditionally deny execution of programs".</p>
1047    
1048 kumaneko 22 <p>Since the line starting with <strong>1 allow</strong> has higher priority than the line starting with <strong>100 deny</strong>, CaitSith will allow execution of <code>/var/www/cgi-bin/counter.cgi</code>.</p>
1049 kumaneko 20
1050 kumaneko 22 <p>To summarize this rule, <code>/usr/sbin/httpd</code> can execute <strong>only</strong> <code>/var/www/cgi-bin/counter.cgi</code>.</p>
1051 kumaneko 20
1052 kumaneko 22 <p>The line <strong>audit 1</strong> means that use audit rules defined in the <strong>quota audit[1]</strong> line. This line tells CaitSith generate audit logs up to entries defined in the <strong>quota audit[1]</strong> line. The default configuration generated by executing <code>/usr/lib/caitsith/init_policy</code> command is</p>
1053 kumaneko 20
1054     <pre>
1055     quota audit[1] allowed=0 denied=1024 unmatched=1024
1056     </pre>
1057    
1058 kumaneko 22 <p>which means do not generate audit logs if matched an "allow" line and generate audit logs up to 1024 entries if matched a "deny" line and generate audit logs up to 1024 lines if matched neither an "allow" line nor a "deny" line. Though, since the block starting with <strong>0 acl execute task.exe="<code>/usr/sbin/httpd</code>"</strong> is terminated with explicit <strong>100 deny</strong> line, this block shall match either an "allow" line or a "deny" line.</p>
1059 kumaneko 20
1060     <h4><a name="3.4.2">3.4.2. Writing access restriction rules from the point of view of "object".</a></h4>
1061    
1062 kumaneko 22 <p>Below entry is default configuration generated by executing <code>/usr/lib/caitsith/init_policy</code> command.</p>
1063 kumaneko 20
1064     <pre>
1065     0 acl modify_policy
1066     audit 1
1067     1 deny task.uid!=0
1068     1 deny task.euid!=0
1069     100 allow task.exe="/usr/sbin/caitsith-loadpolicy"
1070     100 allow task.exe="/usr/sbin/caitsith-queryd"
1071     10000 deny
1072     </pre>
1073    
1074 kumaneko 22 <p>The <strong>0 acl modify_policy</strong> line means check rules for modifying policy configuration via <code>/proc/caitsith/policy</code> interface. Since no additional conditions are specified in this line, this line tells CaitSith <strong>unconditionally check</strong> rules for modifying policy configuration via <code>/proc/caitsith/policy</code> interface.</p>
1075 kumaneko 20
1076 kumaneko 22 <p>The line <strong>1 deny task.uid!=0</strong> means that deny if current thread's user ID is not 0. This line tells CaitSith "deny modification of policy configuration via <code>/proc/caitsith/policy</code> interface if current thread's user ID is not 0".</p>
1077 kumaneko 20
1078 kumaneko 22 <p>The line <strong>1 deny task.euid!=0</strong> means that deny if current thread's effective user ID is not 0. This line tells CaitSith "deny modification of policy configuration via <code>/proc/caitsith/policy</code> interface if current thread's effective user ID is not 0".</p>
1079 kumaneko 20
1080     <p>Note the difference between</p>
1081    
1082     <pre>
1083     1 deny task.uid!=0
1084     1 deny task.euid!=0
1085     </pre>
1086    
1087     <p>and</p>
1088    
1089     <pre>
1090     1 deny task.uid!=0 task.euid!=0
1091     </pre>
1092    
1093     <p>. The former conditions tell CaitSith "deny if current thread's user ID is not 0 <strong>or</strong> current thread's effective user ID is not 0", while the latter conditions tell CaitSith "deny if current thread's user ID is not 0 <strong>and</strong> current thread's effective user ID is not 0".</p>
1094    
1095 kumaneko 22 <p>The line <strong>100 allow task.exe="<code>/usr/sbin/caitsith-loadpolicy</code>"</strong> means that allow if current thread's program name is <code>/usr/sbin/caitsith-loadpolicy</code>. This tells CaitSith finish evaluation of this block starting with the <strong>0 acl modify_policy</strong> line if current thread's program name is <code>/usr/sbin/caitsith-loadpolicy</code>. If there are more blocks, CaitSith will evaluate them. If there are no more blocks, CaitSith will allow modifying policy configuration via <code>/proc/caitsith/policy</code> interface.</p>
1096 kumaneko 20
1097 kumaneko 22 <p>The line <strong>100 allow task.exe="<code>/usr/sbin/caitsith-queryd</code>"</strong> means that allow if current thread's program name is <code>/usr/sbin/caitsith-queryd</code>. This tells CaitSith finish evaluation of this block starting with the <strong>0 acl modify_policy</strong> line if current thread's program name is <code>/usr/sbin/caitsith-queryd</code>. The usage of <code>/usr/sbin/caitsith-queryd</code> will be explained later.</p>
1098 kumaneko 20
1099 kumaneko 22 <p>The line <strong>10000 deny</strong> means deny unconditionally. This tells CaitSith "unconditionally deny modification of policy configuration via <code>/proc/caitsith/policy</code> interface".</p>
1100 kumaneko 20
1101 kumaneko 22 <p>Since lines starting with <strong>1 deny</strong> have higher priority than lines starting with <strong>100 allow</strong>, CaitSith will deny modifying policy configuration via <code>/proc/caitsith/policy</code> interface if current thread's user ID is not 0 or current thread's effective user ID is not 0. In other words, only root user (where current thread's user ID and effective user ID are both 0) can modify policy configuration via <code>/proc/caitsith/policy</code> interface.</p>
1102 kumaneko 20
1103 kumaneko 22 <p>Since lines starting with <strong>100 allow</strong> have higher priority than a line starting with <strong>10000 deny</strong>, CaitSith will allow modifying policy configuration via <code>/proc/caitsith/policy</code> interface if current thread's program name is <code>/usr/sbin/caitsith-loadpolicy</code> or current thread's program name is <code>/usr/sbin/caitsith-queryd</code>. In other words, other programs such as <code>/bin/sh</code>, <code>/bin/echo</code>, <code>/bin/cat</code> are not allowed to modify policy configuration via <code>/proc/caitsith/policy</code> interface.</p>
1104 kumaneko 20
1105 kumaneko 22 <p>To summarize this rule, only <code>/usr/sbin/caitsith-loadpolicy</code> or <code>/usr/sbin/caitsith-queryd</code> command running as root user can modify policy configuration via <code>/proc/caitsith/policy</code> interface.</p>
1106 kumaneko 20
1107     <p>Note the difference between</p>
1108    
1109     <pre>
1110     0 acl execute task.exe="/usr/sbin/httpd"
1111     audit 1
1112     1 allow path="/var/www/cgi-bin/counter.cgi"
1113     100 deny
1114     </pre>
1115    
1116     <p>and</p>
1117    
1118     <pre>
1119     0 acl execute path="/var/www/cgi-bin/counter.cgi"
1120     audit 1
1121     1 allow task.exe="/usr/sbin/httpd"
1122     100 deny
1123     </pre>
1124    
1125 kumaneko 22 <p>. The former means "<code>/usr/sbin/httpd</code> can execute <strong>only</strong> <code>/var/www/cgi-bin/counter.cgi</code>", while the latter means "<strong>only</strong> <code>/usr/sbin/httpd</code> can execute <code>/var/www/cgi-bin/counter.cgi</code>".</p>
1126 kumaneko 20
1127     <p>CaitSith supports restricting other arguments such as command line arguments and environment variables. Syntax for restricting other arguments will be explained later.</p>
1128    
1129     <h4><a name="3.4.3">3.4.3. Writing access restriction rules from the point of view of both "subject" and "object".</a></h4>
1130    
1131     <p>It is possible to write access restriction rules like</p>
1132    
1133     <pre>
1134     0 acl execute task.exe="/usr/sbin/httpd" path="/var/www/cgi-bin/counter.cgi"
1135     audit 1
1136     1 allow task.uid!=0
1137     100 deny
1138     </pre>
1139    
1140     <p>and</p>
1141    
1142     <pre>
1143     0 acl execute task.uid!=0
1144     audit 1
1145     1 allow task.exe="/usr/sbin/httpd" path="/var/www/cgi-bin/counter.cgi"
1146     100 deny
1147     </pre>
1148    
1149 kumaneko 22 <p>. The former means "<code>/usr/sbin/httpd</code> is allowed to execute <code>/var/www/cgi-bin/counter.cgi</code> only if current thread's user ID is not 0", while the latter means "only execution of <code>/var/www/cgi-bin/counter.cgi</code> from <code>/usr/sbin/httpd</code> is allowed if current thread's user ID is not 0".</p>
1150 kumaneko 20
1151     <p>Also, it is possible to write access restriction rules like</p>
1152    
1153     <pre>
1154     0 acl execute
1155     audit 1
1156     1 allow task.exe="/usr/sbin/httpd" path="/var/www/cgi-bin/counter.cgi"
1157     100 deny
1158     </pre>
1159    
1160 kumaneko 22 <p>which means "any execute requests other than execution of <code>/var/www/cgi-bin/counter.cgi</code> from <code>/usr/sbin/httpd</code> are denied" (DO NOT TRY THIS EXAMPLE, or you will no longer be able to run any commands).</p>
1161 kumaneko 20
1162 kumaneko 30 <hr>
1163 kumaneko 29 <h2><a name="condition_list">4. List of conditions</a></h2>
1164 kumaneko 20
1165 kumaneko 30 <hr>
1166 kumaneko 29 <h3><a name="4.1">4.1. Using string arguments in conditions</a></h3>
1167    
1168 kumaneko 18 <p>Arguments such as file's pathnames and command line arguments and environment variables are handled as string argument.</p>
1169    
1170 kumaneko 30 <h4><a name="4.1.1">4.1.1. About string argument representation rule</a></h4>
1171 kumaneko 18
1172     <p>All ASCII printable characters other than \ character (i.e. from 33 to 91 and from 93 to 126) are represented as is.</p>
1173    
1174     <p>All other characters (i.e. from 0 to 32, 92 and from 127 to 255) are represented using \ooo style octal form.</p>
1175    
1176     <table border="1">
1177     <tr>
1178     <td>
1179     <table><tr><td></td><td>Lower 4 bits</td></tr><tr><td>Upper 4 bits</td><td></td></tr></table>
1180     </td>
1181     <th><p>0x0</p></th>
1182     <th><p>0x1</p></th>
1183     <th><p>0x2</p></th>
1184     <th><p>0x3</p></th>
1185     <th><p>0x4</p></th>
1186     <th><p>0x5</p></th>
1187     <th><p>0x6</p></th>
1188     <th><p>0x7</p></th>
1189     <th><p>0x8</p></th>
1190     <th><p>0x9</p></th>
1191     <th><p>0xA</p></th>
1192     <th><p>0xB</p></th>
1193     <th><p>0xC</p></th>
1194     <th><p>0xD</p></th>
1195     <th><p>0xE</p></th>
1196     <th><p>0xF</p></th>
1197     </tr>
1198     <tr>
1199     <th><p>0x0</p></th>
1200     <td><p>\000</p></td>
1201     <td><p>\001</p></td>
1202     <td><p>\002</p></td>
1203     <td><p>\003</p></td>
1204     <td><p>\004</p></td>
1205     <td><p>\005</p></td>
1206     <td><p>\006</p></td>
1207     <td><p>\007</p></td>
1208     <td><p>\010</p></td>
1209     <td><p>\011</p></td>
1210     <td><p>\012</p></td>
1211     <td><p>\013</p></td>
1212     <td><p>\014</p></td>
1213     <td><p>\015</p></td>
1214     <td><p>\016</p></td>
1215     <td><p>\017</p></td>
1216     </tr>
1217     <tr>
1218     <th><p>0x1</p></th>
1219     <td><p>\020</p></td>
1220     <td><p>\021</p></td>
1221     <td><p>\022</p></td>
1222     <td><p>\023</p></td>
1223     <td><p>\024</p></td>
1224     <td><p>\025</p></td>
1225     <td><p>\026</p></td>
1226     <td><p>\027</p></td>
1227     <td><p>\030</p></td>
1228     <td><p>\031</p></td>
1229     <td><p>\032</p></td>
1230     <td><p>\033</p></td>
1231     <td><p>\034</p></td>
1232     <td><p>\035</p></td>
1233     <td><p>\036</p></td>
1234     <td><p>\037</p></td>
1235     </tr>
1236     <tr>
1237     <th><p>0x2</p></th>
1238     <td><p>\040</p></td>
1239     <td><p>!</p></td>
1240     <td><p>"</p></td>
1241     <td><p>#</p></td>
1242     <td><p>$</p></td>
1243     <td><p>%</p></td>
1244     <td><p>&amp;</p></td>
1245     <td><p>'</p></td>
1246     <td><p>(</p></td>
1247     <td><p>)</p></td>
1248     <td><p>*</p></td>
1249     <td><p>+</p></td>
1250     <td><p>,</p></td>
1251     <td><p>-</p></td>
1252     <td><p>.</p></td>
1253     <td><p>/</p></td>
1254     </tr>
1255     <tr>
1256     <th><p>0x3</p></th>
1257     <td><p>0</p></td>
1258     <td><p>1</p></td>
1259     <td><p>2</p></td>
1260     <td><p>3</p></td>
1261     <td><p>4</p></td>
1262     <td><p>5</p></td>
1263     <td><p>6</p></td>
1264     <td><p>7</p></td>
1265     <td><p>8</p></td>
1266     <td><p>9</p></td>
1267     <td><p>:</p></td>
1268     <td><p>;</p></td>
1269     <td><p>&lt;</p></td>
1270     <td><p>=</p></td>
1271     <td><p>&gt;</p></td>
1272     <td><p>?</p></td>
1273     </tr>
1274     <tr>
1275     <th><p>0x4</p></th>
1276     <td><p>@</p></td>
1277     <td><p>A</p></td>
1278     <td><p>B</p></td>
1279     <td><p>C</p></td>
1280     <td><p>D</p></td>
1281     <td><p>E</p></td>
1282     <td><p>F</p></td>
1283     <td><p>G</p></td>
1284     <td><p>H</p></td>
1285     <td><p>I</p></td>
1286     <td><p>J</p></td>
1287     <td><p>K</p></td>
1288     <td><p>L</p></td>
1289     <td><p>M</p></td>
1290     <td><p>N</p></td>
1291     <td><p>O</p></td>
1292     </tr>
1293     <tr>
1294     <th><p>0x5</p></th>
1295     <td><p>P</p></td>
1296     <td><p>Q</p></td>
1297     <td><p>R</p></td>
1298     <td><p>S</p></td>
1299     <td><p>T</p></td>
1300     <td><p>U</p></td>
1301     <td><p>V</p></td>
1302     <td><p>W</p></td>
1303     <td><p>X</p></td>
1304     <td><p>Y</p></td>
1305     <td><p>Z</p></td>
1306     <td><p>[</p></td>
1307     <td><p>\134</p></td>
1308     <td><p>]</p></td>
1309     <td><p>^</p></td>
1310     <td><p>_</p></td>
1311     </tr>
1312     <tr>
1313     <th><p>0x6</p></th>
1314     <td><p>`</p></td>
1315     <td><p>a</p></td>
1316     <td><p>b</p></td>
1317     <td><p>c</p></td>
1318     <td><p>d</p></td>
1319     <td><p>e</p></td>
1320     <td><p>f</p></td>
1321     <td><p>g</p></td>
1322     <td><p>h</p></td>
1323     <td><p>i</p></td>
1324     <td><p>j</p></td>
1325     <td><p>k</p></td>
1326     <td><p>l</p></td>
1327     <td><p>m</p></td>
1328     <td><p>n</p></td>
1329     <td><p>o</p></td>
1330     </tr>
1331     <tr>
1332     <th><p>0x7</p></th>
1333     <td><p>p</p></td>
1334     <td><p>q</p></td>
1335     <td><p>r</p></td>
1336     <td><p>s</p></td>
1337     <td><p>t</p></td>
1338     <td><p>u</p></td>
1339     <td><p>v</p></td>
1340     <td><p>w</p></td>
1341     <td><p>x</p></td>
1342     <td><p>y</p></td>
1343     <td><p>z</p></td>
1344     <td><p>{</p></td>
1345     <td><p>|</p></td>
1346     <td><p>}</p></td>
1347     <td><p>~</p></td>
1348     <td><p>\177</p></td>
1349     </tr>
1350     <tr>
1351     <th><p>0x8</p></th>
1352     <td><p>\200</p></td>
1353     <td><p>\201</p></td>
1354     <td><p>\202</p></td>
1355     <td><p>\203</p></td>
1356     <td><p>\204</p></td>
1357     <td><p>\205</p></td>
1358     <td><p>\206</p></td>
1359     <td><p>\207</p></td>
1360     <td><p>\210</p></td>
1361     <td><p>\211</p></td>
1362     <td><p>\212</p></td>
1363     <td><p>\213</p></td>
1364     <td><p>\214</p></td>
1365     <td><p>\215</p></td>
1366     <td><p>\216</p></td>
1367     <td><p>\217</p></td>
1368     </tr>
1369     <tr>
1370     <th><p>0x9</p></th>
1371     <td><p>\220</p></td>
1372     <td><p>\221</p></td>
1373     <td><p>\222</p></td>
1374     <td><p>\223</p></td>
1375     <td><p>\224</p></td>
1376     <td><p>\225</p></td>
1377     <td><p>\226</p></td>
1378     <td><p>\227</p></td>
1379     <td><p>\230</p></td>
1380     <td><p>\231</p></td>
1381     <td><p>\232</p></td>
1382     <td><p>\233</p></td>
1383     <td><p>\234</p></td>
1384     <td><p>\235</p></td>
1385     <td><p>\236</p></td>
1386     <td><p>\237</p></td>
1387     </tr>
1388     <tr>
1389     <th><p>0xA</p></th>
1390     <td><p>\240</p></td>
1391     <td><p>\241</p></td>
1392     <td><p>\242</p></td>
1393     <td><p>\243</p></td>
1394     <td><p>\244</p></td>
1395     <td><p>\245</p></td>
1396     <td><p>\246</p></td>
1397     <td><p>\247</p></td>
1398     <td><p>\250</p></td>
1399     <td><p>\251</p></td>
1400     <td><p>\252</p></td>
1401     <td><p>\253</p></td>
1402     <td><p>\254</p></td>
1403     <td><p>\255</p></td>
1404     <td><p>\256</p></td>
1405     <td><p>\257</p></td>
1406     </tr>
1407     <tr>
1408     <th><p>0xB</p></th>
1409     <td><p>\260</p></td>
1410     <td><p>\261</p></td>
1411     <td><p>\262</p></td>
1412     <td><p>\263</p></td>
1413     <td><p>\264</p></td>
1414     <td><p>\265</p></td>
1415     <td><p>\266</p></td>
1416     <td><p>\267</p></td>
1417     <td><p>\270</p></td>
1418     <td><p>\271</p></td>
1419     <td><p>\272</p></td>
1420     <td><p>\273</p></td>
1421     <td><p>\274</p></td>
1422     <td><p>\275</p></td>
1423     <td><p>\276</p></td>
1424     <td><p>\277</p></td>
1425     </tr>
1426     <tr>
1427     <th><p>0xC</p></th>
1428     <td><p>\300</p></td>
1429     <td><p>\301</p></td>
1430     <td><p>\302</p></td>
1431     <td><p>\303</p></td>
1432     <td><p>\304</p></td>
1433     <td><p>\305</p></td>
1434     <td><p>\306</p></td>
1435     <td><p>\307</p></td>
1436     <td><p>\310</p></td>
1437     <td><p>\311</p></td>
1438     <td><p>\312</p></td>
1439     <td><p>\313</p></td>
1440     <td><p>\314</p></td>
1441     <td><p>\315</p></td>
1442     <td><p>\316</p></td>
1443     <td><p>\317</p></td>
1444     </tr>
1445     <tr>
1446     <th><p>0xD</p></th>
1447     <td><p>\320</p></td>
1448     <td><p>\321</p></td>
1449     <td><p>\322</p></td>
1450     <td><p>\323</p></td>
1451     <td><p>\324</p></td>
1452     <td><p>\325</p></td>
1453     <td><p>\326</p></td>
1454     <td><p>\327</p></td>
1455     <td><p>\330</p></td>
1456     <td><p>\331</p></td>
1457     <td><p>\332</p></td>
1458     <td><p>\333</p></td>
1459     <td><p>\334</p></td>
1460     <td><p>\335</p></td>
1461     <td><p>\336</p></td>
1462     <td><p>\337</p></td>
1463     </tr>
1464     <tr>
1465     <th><p>0xE</p></th>
1466     <td><p>\340</p></td>
1467     <td><p>\341</p></td>
1468     <td><p>\342</p></td>
1469     <td><p>\343</p></td>
1470     <td><p>\344</p></td>
1471     <td><p>\345</p></td>
1472     <td><p>\346</p></td>
1473     <td><p>\347</p></td>
1474     <td><p>\350</p></td>
1475     <td><p>\351</p></td>
1476     <td><p>\352</p></td>
1477     <td><p>\353</p></td>
1478     <td><p>\354</p></td>
1479     <td><p>\355</p></td>
1480     <td><p>\356</p></td>
1481     <td><p>\357</p></td>
1482     </tr>
1483     <tr>
1484     <th><p>0xF</p></th>
1485     <td><p>\360</p></td>
1486     <td><p>\361</p></td>
1487     <td><p>\362</p></td>
1488     <td><p>\363</p></td>
1489     <td><p>\364</p></td>
1490     <td><p>\365</p></td>
1491     <td><p>\366</p></td>
1492     <td><p>\367</p></td>
1493     <td><p>\370</p></td>
1494     <td><p>\371</p></td>
1495     <td><p>\372</p></td>
1496     <td><p>\373</p></td>
1497     <td><p>\374</p></td>
1498     <td><p>\375</p></td>
1499     <td><p>\376</p></td>
1500     <td><p>\377</p></td>
1501     </tr>
1502     </table>
1503    
1504     <p>Some examples are shown below.</p>
1505    
1506     <pre>
1507     /bin/sh
1508     /home/demo/Documents\040and\040Settings
1509     </pre>
1510    
1511 kumaneko 30 <h4><a name="4.1.2">4.1.2. Grouping string arguments using wildcard expressions.</a></h4>
1512 kumaneko 18
1513     <p>It is possible to use wildcards listed below in order to match string patterns.</p>
1514    
1515     <table border="1">
1516     <tr>
1517     <th><p>Wildcard</p></th>
1518     <th><p>Pattern match</p></th>
1519     <th><p>Examples</p></th>
1520     </tr>
1521     <tr>
1522     <td><p>\*</p></td>
1523     <td><p>0 or more repetitions of characters other than "/"</p></td>
1524     <td><p>/var/log/samba/\*</p></td>
1525     </tr>
1526     <tr>
1527     <td><p>\@</p></td>
1528     <td><p>0 or more repetitions of characters other than "/" or "."</p></td>
1529     <td><p>/var/www/html/\@.html</p></td>
1530     </tr>
1531     <tr>
1532     <td><p>\?</p></td>
1533     <td><p>1 byte character other than "/"</p></td>
1534     <td><p>/tmp/mail.\?\?\?\?\?\?</p></td>
1535     </tr>
1536     <tr>
1537     <td><p>\$</p></td>
1538     <td><p>1 or more repetitions of decimal digits</p></td>
1539     <td><p>/proc/\$/cmdline</p></td>
1540     </tr>
1541     <tr>
1542     <td><p>\+</p></td>
1543     <td><p>1 decimal digit</p></td>
1544     <td><p>/var/tmp/my_work.\+</p></td>
1545     </tr>
1546     <tr>
1547     <td><p>\X</p></td>
1548     <td><p>1 or more repetitions of hexadecimal digits</p></td>
1549     <td><p>/var/tmp/my-work.\X</p></td>
1550     </tr>
1551     <tr>
1552     <td><p>\x</p></td>
1553     <td><p>1 hexadecimal digit</p></td>
1554     <td><p>/tmp/my-work.\x</p></td>
1555     </tr>
1556     <tr>
1557     <td><p>\A</p></td>
1558     <td><p>1 or more repetitions of alphabet characters</p></td>
1559     <td><p>/var/log/my-work/\$-\A-\$.log</p></td>
1560     </tr>
1561     <tr>
1562     <td><p>\a</p></td>
1563     <td><p>1 alphabet character</p></td>
1564     <td><p>/home/users/\a/\*/public_html/\*.html</p></td>
1565     </tr>
1566     <tr>
1567     <td><p>\-</p></td>
1568     <td><p>Pathname subtraction operator (negative match)</p></td>
1569     <td>
1570     <p>/\*\-proc\-sys</p>
1571     <p>This will match /\* except "/proc" and "/sys".</p>
1572     </td>
1573     </tr>
1574     <tr>
1575     <td><p>/\{dir\}/</p></td>
1576     <td><p>Recursive directory matching operator.</p>
1577     <p>Matches "/" and 1 or more repetitions of "dir/".</p></td>
1578     <td>
1579     <p>/var/www/html/\{\*\}/\*.html</p>
1580     <p>This will match all *.html files in subdirectories under /var/www/html/ directory. Note that /var/www/html/\*.html will not match.</p>
1581     </td>
1582     </tr>
1583     <tr>
1584     <td><p>/({dir\)/</p></td>
1585     <td><p>Recursive directory matching operator.</p>
1586     <p>Matches "/" and 0 or more repetitions of "dir/".</p></td>
1587     <td>
1588     <p>/var/www/html/\(\*\)/\*.html</p>
1589     <p>This will match all *.html files under /var/www/html/ directory. Note that /var/www/html/\*.html will match.</p>
1590     </td>
1591     </tr>
1592     </table>
1593    
1594 kumaneko 30 <h4><a name="4.1.3">4.1.3. Grouping string arguments using string_group keyword.</a></h4>
1595 kumaneko 18
1596     <p>It is possible to define groups of string arguments using string_group keyword followed by $string_group_name and $string_group_member.</p>
1597    
1598     <pre>
1599     string_group TMPDIR /tmp
1600     string_group TMPDIR /tmp/\(\*\)/\*
1601     </pre>
1602    
1603 kumaneko 30 <h4><a name="4.1.4">4.1.4. Example of conditions that use string arguments.</a></h4>
1604 kumaneko 18
1605     <p>When string argument is specified in condition part, it is quoted by " character in order to clarify that the argument is a string argument rather than name of variable.</p>
1606    
1607     <table border="1">
1608     <tr><td>Conditions example</td><td>Value of variable "path"</td><td>Comparison result</td></tr>
1609     <tr><td rowspan="5">path="/tmp/\*"</td>
1610     <td>/</td><td>Does not match</td></tr>
1611     <tr><td>/tmp</td><td>Does not match</td></tr>
1612     <tr><td>/tmp/</td><td>Matches</td></tr>
1613     <tr><td>/tmp/rt6bh84t</td><td>Matches</td></tr>
1614     <tr><td>/tmp/349gy08t/y8024fgf</td><td>Does not match</td></tr>
1615     <tr><td rowspan="5">path!="/tmp/\*"</td>
1616     <td>/</td><td>Matches</td></tr>
1617     <tr><td>/tmp</td><td>Matches</td></tr>
1618     <tr><td>/tmp/</td><td>Does not match</td></tr>
1619     <tr><td>/tmp/rt6bh84t</td><td>Does not match</td></tr>
1620     <tr><td>/tmp/349gy08t/y8024fgf</td><td>Matches</td></tr>
1621     </table>
1622    
1623     <p>When string_group argument is specified in condition part, it is prefixed by @ character in order to clarify that the argument is a string_group argument rather than name of variable.</p>
1624    
1625     <table border="1">
1626     <tr><td>Conditions example</td><td>Value of variable "path"</td><td>Values in TMPDIR group</td><td>Comparison result</td></tr>
1627     <tr><td rowspan="4">path=@TMPDIR</td>
1628     <td>/</td><td rowspan="4">/tmp<br>/tmp/\(\*\)/\*</td><td>Does not match</td></tr>
1629     <tr><td>/tmp</td><td>Matches</td></tr>
1630     <tr><td>/tmp/rt6bh84t</td><td>Matches</td></tr>
1631     <tr><td>/tmp/349gy08t/y8024fgf</td><td>Matches</td></tr>
1632     <tr><td rowspan="4">path!=@TMPDIR</td>
1633     <td>/</td><td rowspan="4">/tmp<br>/tmp/\(\*\)/\*</td><td>Matches</td></tr>
1634     <tr><td>/tmp</td><td>Does not match</td></tr>
1635     <tr><td>/tmp/rt6bh84t</td><td>Does not match</td></tr>
1636     <tr><td>/tmp/349gy08t/y8024fgf</td><td>Does not match</td></tr>
1637     </table>
1638    
1639     <p>List of name of variables which reference string data is explained later.</p>
1640    
1641 kumaneko 30 <hr>
1642 kumaneko 29 <h3><a name="4.2">4.2. Using numeric arguments in conditions</a></h3>
1643 kumaneko 18
1644     <p>Arguments such as user ID and process ID are handled as numeric argument.</p>
1645    
1646 kumaneko 30 <h4><a name="4.2.1">4.2.1. About numeric argument representation rule</a></h4>
1647 kumaneko 18
1648     <p>Decimal form, octal form and hexadecimal form are supported. Octal form is prefixed with 0 and Hexadecimal form is prefixed with 0x. For example, 010 in octal form is equivalent with 8 in decimal form, 0x10 in hexadecimal form is equivalent with 16 in decimal form.</p>
1649    
1650     <p>Since numeric data is handled using C language's "unsigned long" type, minimal value is 0 and maximal value is 0xFFFFFFFF (for 32 bit environments) or 0xFFFFFFFFFFFFFFFF (for 64 bit environments).</p>
1651    
1652     <p>It is possible to specify numeric data ranges in $min_value-$max_value form. If specifying in range, $min_value has to be smaller or equals to $max_value. For example, 0-100 is valid but 100-0 is invalid.</p>
1653    
1654     <p>Some examples are shown below.</p>
1655    
1656     <pre>
1657     0
1658     100
1659     0xFFFF
1660     0777
1661     500-1000
1662     0x0-0xFFFFFFFF
1663     00-07777
1664     </pre>
1665    
1666 kumaneko 30 <h4><a name="4.2.2">4.2.2. Grouping numeric arguments using number_group keyword.</a></h4>
1667 kumaneko 18
1668     <p>It is possible to define groups of numeric arguments using number_group keyword followed by $number_group_name and $number_group_member.</p>
1669    
1670     <pre>
1671     number_group ID_GROUP 100
1672     number_group ID_GROUP 200-500
1673     </pre>
1674    
1675 kumaneko 30 <h4><a name="4.2.3">4.2.3. Example of conditions that use numeric arguments.</a></h4>
1676 kumaneko 18
1677     <p>Comparison with numeric value is defined as below.</p>
1678    
1679     <table border="1">
1680     <tr><td>Conditions example</td><td>Value of variable "task.uid"</td><td>Comparison result</td></tr>
1681     <tr><td rowspan="3">task.uid=0</td>
1682     <td>0</td><td>Matches</td></tr>
1683     <tr><td>100</td><td>Does not match</td></tr>
1684     <tr><td>500</td><td>Does not match</td></tr>
1685     <tr><td rowspan="3">task.uid!=0</td>
1686     <td>0</td><td>Does not match</td></tr>
1687     <tr><td>100</td><td>Matches</td></tr>
1688     <tr><td>500</td><td>Matches</td></tr>
1689     </table>
1690    
1691     <p>Comparison with numeric value range is defined as below.</p>
1692    
1693     <table border="1">
1694     <tr><td>Conditions example</td><td>Value of variable "task.gid"</td><td>Comparison result</td></tr>
1695     <tr><td rowspan="3">task.gid=0-100</td>
1696     <td>0</td><td>Matches</td></tr>
1697     <tr><td>100</td><td>Matches</td></tr>
1698     <tr><td>500</td><td>Does not match</td></tr>
1699     <tr><td rowspan="3">task.gid!=0-100</td><td>0</td><td>Does not match</td></tr>
1700     <tr><td>100</td><td>Does not match</td></tr>
1701     <tr><td>500</td><td>Matches</td></tr>
1702     </table>
1703    
1704     <p>It is possible to compare one variable which references numeric value with another variable which references numeric value.</p>
1705    
1706     <table border="1">
1707     <tr><td>Conditions example</td><td>Value of variable "task.uid"</td><td>Value of variable "task.gid"</td><td>Comparison result</td></tr>
1708     <tr><td rowspan="4">task.uid=task.gid</td>
1709     <td>0</td><td>0</td><td>Matches</td></tr>
1710     <tr><td>0</td><td>100</td><td>Does not match</td></tr>
1711     <tr><td>100</td><td>0</td><td>Does not match</td></tr>
1712     <tr><td>100</td><td>100</td><td>Matches</td></tr>
1713     <tr><td rowspan="4">task.uid!=task.gid</td>
1714     <td>0</td><td>0</td><td>Does not match</td></tr>
1715     <tr><td>0</td><td>100</td><td>Matches</td></tr>
1716     <tr><td>100</td><td>0</td><td>Matches</td></tr>
1717     <tr><td>100</td><td>100</td><td>Does not match</td></tr>
1718     </table>
1719    
1720     <p>When number_group argument is specified in condition part, it is prefixed by @ character in order to clarify that the argument is a number_group argument rather than name of variable.</p>
1721    
1722     <table border="1">
1723     <tr><td>Conditions example</td><td>Value of variable "task.uid"</td><td>Values in ID_GROUP group</td><td>Comparison result</td></tr>
1724     <tr><td rowspan="4">task.uid=@ID_GROUP</td>
1725     <td>0</td><td rowspan="4">100<br>200-500</td><td>Does not match</td></tr>
1726     <tr><td>100</td><td>Matches</td></tr>
1727     <tr><td>500</td><td>Matches</td></tr>
1728     <tr><td>1000</td><td>Does not match</td></tr>
1729     <tr><td rowspan="4">task.uid!=@ID_GROUP</td>
1730     <td>0</td><td rowspan="4">100<br>200-500</td><td>Matches</td></tr>
1731     <tr><td>100</td><td>Does not match</td></tr>
1732     <tr><td>500</td><td>Does not match</td></tr>
1733     <tr><td>1000</td><td>Matches</td></tr>
1734     </table>
1735    
1736     <p>List of name of variables which reference numeric data is explained later.</p>
1737    
1738 kumaneko 30 <hr>
1739 kumaneko 29 <h3><a name="4.3">4.3. Using process's information in conditions</a></h3>
1740 kumaneko 18
1741 kumaneko 19 <p>By using current thread's attributes as part of conditions, you can write complicated access restriction rules.</p>
1742 kumaneko 18
1743 kumaneko 30 <h4><a name="4.3.1">4.3.1. About available variables</a></h4>
1744 kumaneko 18
1745 kumaneko 19 <p>Below variables are available for referring current thread's attributes.</p>
1746 kumaneko 18
1747 kumaneko 19 <table border="1">
1748     <tr><td>Variable's name</td><td>Comparison method</td><td>Meaning</td><td></td></tr>
1749 kumaneko 29 <tr><td>task.uid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's user ID</td></tr>
1750     <tr><td>task.gid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's group ID</td></tr>
1751     <tr><td>task.euid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's effective user ID</td></tr>
1752     <tr><td>task.egid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's effective group ID</td></tr>
1753     <tr><td>task.suid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's saved user ID</td></tr>
1754     <tr><td>task.sgid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's saved group ID</td></tr>
1755     <tr><td>task.fsuid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's filesystem user ID</td></tr>
1756     <tr><td>task.fsgid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's filesystem group ID</td></tr>
1757     <tr><td>task.pid</td><td><a href="#4.2">Numeric</a></td><td>Current thread's process ID </td></tr>
1758     <tr><td>task.ppid</td><td><a href="#4.2">Numeric</a></td><td>Process ID of current thread's parent process</td></tr>
1759     <tr><td>task.exe</td><td><a href="#4.1">String</a></td><td>Current thread's program name (the content of <code>/proc/self/exe</code>)</td></tr>
1760     <tr><td>task.domain</td><td><a href="#4.1">String</a></td><td>Current thread's domainname (the content of <code>/proc/caitsith/self_domain</code>)</td></tr>
1761 kumaneko 19 <tr><td>task.type</td><td>Literal</td><td>Matches execute_handler if running as an execute handler, does not match execute_handler otherwise</td></tr>
1762     </table>
1763    
1764     <p>Details of task.domain and task.type are explained later.</p>
1765    
1766 kumaneko 30 <hr>
1767 kumaneko 29 <h3><a name="4.4">4.4. Using IP address arguments in conditions</a></h3>
1768 kumaneko 19
1769 kumaneko 18 <p>Any operation which handles IPv4/IPv6 network address can check IP address.</p>
1770    
1771 kumaneko 30 <h4><a name="4.4.1">4.4.1. About IP address argument representation rule</a></h4>
1772 kumaneko 18
1773     <p>It is possible to handle IPv4 address and IPv6 address. IPv4 address (32 bit) is represented using dot separated decimal form. and IPv6 address (128 bit) is represented using forms defined in RFC 2373.</p>
1774    
1775     <p>It is possible to specify IP address ranges in $min_address-$max_address form. If specifying in range, $min_address has to be smaller or equals to $max_address. For example, 1.2.3.4-5.6.7.8 is valid but 5.6.7.8-1.2.3.4 is invalid.</p>
1776    
1777     <p>Some examples are shown below.</p>
1778    
1779     <pre>
1780     127.0.0.1
1781     10.0.0.0-10.255.255.255
1782     ::1
1783     fd00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
1784     </pre>
1785    
1786 kumaneko 30 <h4><a name="4.4.2">4.4.2. Grouping IP address arguments using ip_group keyword.</a></h4>
1787 kumaneko 18
1788     <p>It is possible to define groups of IP address arguments using ip_group keyword followed by $ip_group_name and $ip_group_member.</p>
1789    
1790     <pre>
1791     ip_group PRIVATE_ADDRESS 10.0.0.0-10.255.255.255
1792     ip_group PRIVATE_ADDRESS 172.16.0.0-172.31.255.255
1793     ip_group PRIVATE_ADDRESS 192.168.0.0-192.168.255.255
1794     ip_group PRIVATE_ADDRESS fd00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
1795     </pre>
1796    
1797 kumaneko 30 <h4><a name="4.4.3">4.4.3. Example of conditions that use IP address arguments.</a></h4>
1798 kumaneko 18
1799     <p>Comparison with IP address value is defined as below. Note that comparison between an IPv4 address and an IPv6 address does not match.</p>
1800    
1801     <table border="1">
1802     <tr><td>Conditions example</td><td>Value of variable "ip"</td><td>Comparison result</td></tr>
1803     <tr><td rowspan="4">ip=127.0.0.1</td><td>127.0.0.1</td><td>Matches</td></tr>
1804     <tr><td>0.0.0.0</td><td>Does not match</td></tr>
1805     <tr><td>::1</td><td>Does not match</td></tr>
1806     <tr><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1807     <tr><td rowspan="4">ip!=127.0.0.1</td><td>127.0.0.1</td><td>Does not match</td></tr>
1808     <tr><td>0.0.0.0</td><td>Matches</td></tr>
1809     <tr><td>::1</td><td>Does not match</td></tr>
1810     <tr><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1811     <tr><td rowspan="4">ip=::1</td><td>127.0.0.1</td><td>Does not match</td></tr>
1812     <tr><td>0.0.0.0</td><td>Does not match</td></tr>
1813     <tr><td>::1</td><td>Matches</td></tr>
1814     <tr><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1815     <tr><td rowspan="4">ip!=::1</td><td>127.0.0.1</td><td>Does not match</td></tr>
1816     <tr><td>0.0.0.0</td><td>Does not match</td></tr>
1817     <tr><td>::1</td><td>Does not match</td></tr>
1818     <tr><td>::ffff:127.0.0.1</td><td>Matches</td></tr>
1819     </table>
1820    
1821     <p>Comparison with IP address range is defined as below.</p>
1822    
1823     <table border="1">
1824     <tr><td>Conditions example</td><td>Value of variable "ip"</td><td>Comparison result</td></tr>
1825     <tr><td rowspan="3">ip=127.0.0.0-127.255.255.255</td>
1826     <td>127.0.0.1</td><td>Matches</td></tr>
1827     <tr><td>10.0.0.1</td><td>Does not match</td></tr>
1828     <tr><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1829     <tr><td rowspan="3">ip!=127.0.0.0-127.255.255.255</td>
1830     <td>127.0.0.1</td><td>Does not match</td></tr>
1831     <tr><td>10.0.0.1</td><td>Matches</td></tr>
1832     <tr><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1833     <tr><td rowspan="3">ip=::-::1</td><td>::ffff:127.0.0.1</td><td>Does not match</td></tr>
1834     <tr><td>127.0.0.1</td><td>Does not match</td></tr>
1835     <tr><td>::1</td><td>Matches</td></tr>
1836     <tr><td rowspan="3">ip!=::-::1</td><td>::ffff:127.0.0.1</td><td>Matches</td></tr>
1837     <tr><td>127.0.0.1</td><td>Does not match</td></tr>
1838     <tr><td>::1</td><td>Does not match</td></tr>
1839     </table>
1840    
1841     <p>When ip_group argument is specified in condition part, it is prefixed by @ character in order to clarify that the argument is an ip_group argument rather than name of variable.</p>
1842    
1843     <table border="1">
1844     <tr><td>Conditions example</td><td>Value of variable "ip"</td><td>Values in PRIVATE_ADDRESS group</td><td>Comparison result</td></tr>
1845     <tr><td rowspan="5">ip=@PRIVATE_ADDRESS</td>
1846     <td>127.0.0.1</td><td rowspan="5">10.0.0.0-10.255.255.255<br>172.16.0.0-172.31.255.255<br>192.168.0.0-192.168.255.255<br>fd00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff</td><td>Does not match</td></tr>
1847     <tr><td>10.0.0.1</td><td>Matches</td></tr>
1848     <tr><td>192.168.0.1</td><td>Matches</td></tr>
1849     <tr><td>::ffff:172.16.0.1</td><td>Does not match</td></tr>
1850     <tr><td>fd01::</td><td>Matches</td></tr>
1851     <tr><td rowspan="5">ip!=@PRIVATE_ADDRESS</td><td>127.0.0.1</td><td rowspan="5">10.0.0.0-10.255.255.255<br>172.16.0.0-172.31.255.255<br>192.168.0.0-192.168.255.255<br>fd00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff</td><td>Matches</td></tr>
1852     <tr><td>10.0.0.1</td><td>Does not match</td></tr>
1853     <tr><td>::ffff:192.168.0.1</td><td>Matches</td></tr>
1854     <tr><td>::ffff:127.0.0.1</td><td>Matches</td></tr>
1855     <tr><td>fd01::</td><td>Does not match</td></tr>
1856     </table>
1857    
1858     <p>List of operations which handles IP address is explained later.</p>
1859    
1860 kumaneko 30 <hr>
1861 kumaneko 29 <h3><a name="4.5">4.5. Using command line arguments in conditions</a></h3>
1862 kumaneko 16
1863 kumaneko 10 <p>It is possible to check command line arguments (a.k.a. argv[]) when checking permissions for program execution.</p>
1864    
1865     <table border="1">
1866     <tr><td>Conditions example</td><td>Comparison method</td><td>Meaning</td><td></td></tr>
1867 kumaneko 29 <tr><td>argv[0]="true"</td><td><a href="#4.1">String</a></td><td>argv[0] matches "true"</td></tr>
1868     <tr><td>argv[0]!="false"</td><td><a href="#4.1">String</a></td><td>argv[0] does not match "false"</td></tr>
1869     <tr><td>argv[1]=@ARGV1_GROUPS</td><td><a href="#4.1">String</a></td><td>argv[0] matches one of strings in string_group ARGV1_GROUPS group</td></tr>
1870     <tr><td>argv[1]!=@ARGV1_GROUPS</td><td><a href="#4.1">String</a></td><td>argv[0] matches none of strings in string_group ARGV1_GROUPS group</td></tr>
1871 kumaneko 10 </table>
1872    
1873     <p>Applications can pass a string data up to 32 * PAGE_SIZE bytes to each argv[]. But due to difficulty of allocating contiguous memory in the kernel, only up to 4085 bytes can be checked using variable "argv[$index]". If you want to check strictly, please consider using handler= argument of "allow " lines in "acl execute" block.</p>
1874    
1875 kumaneko 30 <hr>
1876 kumaneko 29 <h3><a name="4.6">4.6. Using environment variable arguments in conditions</a></h3>
1877 kumaneko 10
1878     <p>It is possible to check environment variables (a.k.a. envp[]) when checking permissions for program execution.</p>
1879    
1880     <table border="1">
1881     <tr><td>Conditions example</td><td>Comparison method</td><td>Meaning</td><td></td></tr>
1882 kumaneko 29 <tr><td>envp["PATH"]="/"</td><td><a href="#4.1">String</a></td><td>Environment variable PATH is defined and its value is "/"</td></tr>
1883     <tr><td>envp["PATH"]!="/"</td><td><a href="#4.1">String</a></td><td>Either<br>&nbsp;&nbsp;&nbsp;&nbsp;Environment variable PATH is not defined<br>or<br>&nbsp;&nbsp;&nbsp;&nbsp;Environment variable PATH is defined but its value is not "/"</td></tr>
1884     <tr><td>envp["PATH"]=@ENV_PATH_VALUES</td><td><a href="#4.1">String</a></td><td>Environment variable PATH is defined and its value matches one of strings in string_group ENVP_PATH_VALUES group</td></tr>
1885     <tr><td>envp["PATH"]!=@ENV_PATH_VALUES</td><td><a href="#4.1">String</a></td><td>Either<br>&nbsp;&nbsp;&nbsp;&nbsp;Environment variable PATH is not defined<br>or<br>&nbsp;&nbsp;&nbsp;&nbsp;Environment variable PATH is defined but its value matches none of strings in string_group ENVP_PATH_VALUES group</td></tr>
1886 kumaneko 10 <tr><td>envp["PATH"]=NULL</td><td>None</td><td>Environment variable PATH is not defined</td></tr>
1887 kumaneko 52 <tr><td>envp["PATH"]!=NULL</td><td>None</td><td>Environment variable PATH is defined</td></tr>
1888 kumaneko 10 </table>
1889    
1890     <p>Applications can pass a string data up to 32 * PAGE_SIZE bytes to each envp[]. But due to difficulty of allocating contiguous memory in the kernel, only up to 4085 bytes can be checked using variable "envp["$name"]". If you want to check strictly, please consider using handler= argument of "allow " lines in "acl execute" block.</p>
1891    
1892 kumaneko 30 <hr>
1893 kumaneko 29 <h3><a name="4.7">4.7. Using file's DAC permissions in conditions</a></h3>
1894 kumaneko 10
1895     <p>When checking permissions for file related operations, it is possible to check its DAC permissions if the file already exists as of permission check.
1896     Below table assumes that the variable name for referencing the requested pathname is "path".</p>
1897    
1898 kumaneko 29 <p>Value of DAC permissions can be referenced using variable "path.perm", and its value is between 0 and 07777. Although it is possible to do normal <a href="#4.2">numeric comparison</a>, below constants are provided in order to make it easier to compare whether specific bit is set or not.</p>
1899 kumaneko 10
1900     <table border="1">
1901     <tr><td>Constant</td><td>Value ranges that match </td></tr>
1902     <tr><td>setuid</td><td>Values where bitwise AND between path.perm and 04000 are 04000. (i.e. 04000-07777)</td></tr>
1903     <tr><td>setgid</td><td>Values where bitwise AND between path.perm and 02000 are 02000. (i.e. 02000-03777 06000-07777)</td></tr>
1904     <tr><td>sticky</td><td>Values where bitwise AND between path.perm and 01000 are 01000. (i.e. 01000-01777 03000-03777 05000-05777 07000-07777)</td></tr>
1905     <tr><td>owner_read</td><td>Values where bitwise AND between path.perm and 00400 are 00400. (e.g. 00400-00777 01400-01777 02400-02777)</td></tr>
1906     <tr><td>owner_write</td><td>Values where bitwise AND between path.perm and 00200 are 00200. (e.g. 00200-00377 00600-00777 01200-01377)</td></tr>
1907     <tr><td>owner_execute</td><td>Values where bitwise AND between path.perm and 00100 are 00100. (e.g. 00100-00177 00300-00377 00500-00577)</td></tr>
1908     <tr><td>group_read</td><td>Values where bitwise AND between path.perm and 00040 are 00040. (e.g. 00040-00077 00140-00177 00240-00277)</td></tr>
1909     <tr><td>group_write</td><td>Values where bitwise AND between path.perm and 00020 are 00020. (e.g. 00020-00037 00060-00077 00120-00137)</td></tr>
1910     <tr><td>group_execute</td><td>Values where bitwise AND between path.perm and 00010 are 00010. (e.g. 00010-00017 00030-00037 00050-00057)</td></tr>
1911     <tr><td>others_read</td><td>Values where bitwise AND between path.perm and 00004 are 00004. (e.g. 00004-00007 00014-00017 00024-00027)</td></tr>
1912     <tr><td>others_write</td><td>Values where bitwise AND between path.perm and 00002 are 00002. (e.g. 00002-00003 00006-00007 00012-00013)</td></tr>
1913     <tr><td>others_execute</td><td>Values where bitwise AND between path.perm and 00001 are 00001. (e.g. 00001 00003 00005 00007 00011 00013)</td></tr>
1914     </table>
1915    
1916     <p>Below are some examples that use constants.</p>
1917    
1918     <table border="1">
1919     <tr><td>Conditions example</td><td>Permissions of file referenced by variable "path"</td><td>Comparison result</td></tr>
1920     <tr><td>path.perm=setuid</td><td>04755</td><td>Matches</td></tr>
1921     <tr><td>path.perm!=setuid</td><td>04755</td><td>Does not match</td></tr>
1922     <tr><td>path.perm=setuid path.perm=setgid path.perm=sticky</td><td>0755</td><td>Does not match</td></tr>
1923     <tr><td>path.perm!=setuid path.perm!=setgid path.perm!=sticky</td><td>0755</td><td>Matches</td></tr>
1924     </table>
1925    
1926 kumaneko 30 <hr>
1927 kumaneko 29 <h3><a name="4.8">4.8. Using handle file's type in conditions</a></h3>
1928 kumaneko 10
1929     <p>When checking permissions for file related operations, it is possible to check its type if the file already exists as of permission check.
1930     Below table assumes that the variable name for referencing the requested pathname is "path".</p>
1931    
1932     <p>Type of a file can be referenced using variable "path.type", and its value takes one of "file", "directory", "socket", "fifo", "block", "char", "symlink".</p>
1933    
1934     <table border="1">
1935     <tr><td>Possible conditions</td><td>Type of file referenced by variable "path"</td><td>Comparison result</td></tr>
1936     <tr><td>path.type=file</td><td>Regular file</td><td>Matches</td></tr>
1937     <tr><td>path.type!=file</td><td>Other than regular file</td><td>Matches</td></tr>
1938     <tr><td>path.type=directory</td><td>Directory</td><td>Matches</td></tr>
1939     <tr><td>path.type!=directory</td><td>Other than directory</td><td>Matches</td></tr>
1940     <tr><td>path.type=socket</td><td>Unix domain socket</td><td>Matches</td></tr>
1941     <tr><td>path.type!=socket</td><td>Other than Unix domain socket</td><td>Matches</td></tr>
1942     <tr><td>path.type=fifo</td><td>FIFO</td><td>Matches</td></tr>
1943     <tr><td>path.type!=fifo</td><td>Other than FIFO</td><td>Matches</td></tr>
1944     <tr><td>path.type=block</td><td>Block device file</td><td>Matches</td></tr>
1945     <tr><td>path.type!=block</td><td>Other than block device file</td><td>Matches</td></tr>
1946     <tr><td>path.type=char</td><td>Character device file</td><td>Matches</td></tr>
1947     <tr><td>path.type!=char</td><td>Other than character device file</td><td>Matches</td></tr>
1948     <tr><td>path.type=symlink</td><td>Symbolic link</td><td>Matches</td></tr>
1949     <tr><td>path.type!=symlink</td><td>Other than symbolic link</td><td>Matches</td></tr>
1950     </table>
1951    
1952 kumaneko 30 <hr>
1953 kumaneko 29 <h3><a name="4.9">4.9. Using file's attributes in conditions</a></h3>
1954 kumaneko 10
1955     <p>When checking permissions for file related operations, it is possible to check its attributes if the file already exists as of permission check.
1956     Below table assumes that the variable name for referencing the requested pathname is "path".</p>
1957    
1958     <table border="1">
1959     <tr><td>Variable's name</td><td>Comparison method</td><td>Meaning</td></tr>
1960 kumaneko 29 <tr><td>path.uid</td><td><a href="#4.2">Numeric</a></td><td>Owner ID</td></tr>
1961     <tr><td>path.gid</td><td><a href="#4.2">Numeric</a></td><td>Group ID</td></tr>
1962     <tr><td>path.ino</td><td><a href="#4.2">Numeric</a></td><td>i-node number on the filesystem</td></tr>
1963     <tr><td>path.major</td><td><a href="#4.2">Numeric</a></td><td>Device major number on the filesystem</td></tr>
1964     <tr><td>path.minor</td><td><a href="#4.2">Numeric</a></td><td>Device minor number on the filesystem</td></tr>
1965     <tr><td>path.perm</td><td><a href="#4.7">Permission</a></td><td>DAC permissions</td></tr>
1966     <tr><td>path.type</td><td><a href="#4.8">File's type</a></td><td>Type of the file</td></tr>
1967     <tr><td>path.dev_major</td><td><a href="#4.2">Numeric</a></td><td>Device major number of the file if path.type=block or path.type=char</td></tr>
1968     <tr><td>path.dev_minor</td><td><a href="#4.2">Numeric</a></td><td>Device minor number of the file if path.type=block or path.type=char</td></tr>
1969     <tr><td>path.fsmagic</td><td><a href="#4.2">Numeric</a></td><td>Magic number of filesystem</td></tr>
1970 kumaneko 10 </table>
1971    
1972     <p>When checking permissions for file related operations, it is possible to also check its parent directory's attributes.
1973     Below table assumes that the variable name for referencing the requested pathname is "path".</p>
1974    
1975     <table border="1">
1976     <tr><td>Variable's name</td><td>Comparison method</td><td>Meaning</td></tr>
1977 kumaneko 29 <tr><td>path.parent.uid</td><td><a href="#4.2">Numeric</a></td><td>Owner ID</td></tr>
1978     <tr><td>path.parent.gid</td><td><a href="#4.2">Numeric</a></td><td>Group ID</td></tr>
1979     <tr><td>path.parent.ino</td><td><a href="#4.2">Numeric</a></td><td>i-node number on the filesystem</td></tr>
1980     <tr><td>path.parent.major</td><td><a href="#4.2">Numeric</a></td><td>Device major number on the filesystem</td></tr>
1981     <tr><td>path.parent.minor</td><td><a href="#4.2">Numeric</a></td><td>Device minor number on the filesystem</td></tr>
1982     <tr><td>path.parent.perm</td><td><a href="#4.7">Permission</a></td><td>DAC permissions</td></tr>
1983     <tr><td>path.parent.fsmagic</td><td><a href="#4.2">Numeric</a></td><td>Magic number of filesystem</td></tr>
1984 kumaneko 10 </table>
1985    
1986     <p>It does not make sense to use path.parent.type path.parent.dev_major path.parent.dev_minor because path.parent is always a directory.</p>
1987    
1988     <p>If path refers a mount point (root of directory entry tree within that partition), path.parent refers the same path rather than referring mount point's parent.</p>
1989    
1990 kumaneko 30 <hr>
1991     <h2><a name="syntax_list">5. List of syntaxes</a></h2>
1992 kumaneko 10
1993 kumaneko 30 <hr>
1994     <h3><a name="5.1">5.1. execute</a></h3>
1995    
1996     <h4><a name="5.1.1">5.1.1. Description</a></h4>
1997    
1998     <p>Execute a program</p>
1999