Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/htdocs/index.html

Parent Directory Parent Directory | Revision Log Revision Log


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