Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/htdocs/index.html

Parent Directory Parent Directory | Revision Log Revision Log


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