Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/htdocs/index.html

Parent Directory Parent Directory | Revision Log Revision Log


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