TOMOYO Linuxによるアクセス解析手順

Last modified: $Date: 2007-02-16 21:33:28 +0900 (Fri, 16 Feb 2007) $

TOMOYO Linux のポリシーはパス名で表現されるため、ファイルのアクセスを追跡するためにも利用できます。
特定のプログラムがどのようなファイルにアクセスしているかを知りたい場合や、特定のディレクトリにファイルを作成しているプログラムを知りたい場合に利用できます。

準備

TOMOYO Linux カーネルのインストール

TOMOYO Linux では、いくつかのコンパイル済みのカーネルをパッケージにして提供しています。コンパイル済みのカーネルを利用する場合は、以下のファイルをダウンロードしてインストールしてください。

RedHat Linux 9 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.4.20-46.9.legacy_tomoyo_1.3.2.i386.rpm
Fedora Core 3 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.12-2.3.legacy_FC3_tomoyo_1.3.2.i586.rpm
Fedora Core 4 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.17-1.2142_FC4_tomoyo_1.3.2.i586.rpm
Fedora Core 5 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.19-1.2288.fc5_tomoyo_1.3.2.i586.rpm
Fedora Core 6 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.19-1.2911.fc6_tomoyo_1.3.2.i586.rpm
CentOS 4.4 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.9-42.0.8.EL_tomoyo_1.3.2.i586.rpm
Debian Sarge (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-image-2.4.27-10sarge5-ccs-i586_1.3.2_i386.deb
http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-image-2.6.8-16sarge6-ccs-i586_1.3.2_i386.deb
Debian Etch (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/linux-image-2.6.18-9-ccs-i586_1.3.2_i386.deb
OpenSUSE 10.1 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-default-2.6.16.27-0.6_tomoyo_1.3.2.i586.rpm
OpenSUSE 10.2 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-default-2.6.18.2-34_tomoyo_1.3.2.i586.rpm
Asianux 2.0 (80686以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/kernel-2.6.9-34.28AX_tomoyo_1.3.2.i686.rpm
Ubuntu 6.10 (80586以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/linux-image-2.6.17.14-ubuntu1-ccs-i586_1.3.2_i386.deb

アーキテクチャが異なる場合やカスタマイズしたい場合には、カーネルをコンパイルする必要があります。カーネルをコンパイルする方法については、TOMOYO Linuxカーネルの作成手順を参照してください。

SELinux をサポートするディストリビューションでは、 SELinux が無効になっていないとインストール時にエラーが発生する場合があります。インストール時に以下のようなエラーメッセージが表示される場合は、 SELinux を無効にしてからインストールしてください。 /etc/selinux/config の SELINUX= の行を SELINUX=disabled に書き換えてからシステムを再起動するか、あるいは、カーネル起動時のコマンドラインに selinux=0 というオプションを渡すことで SELinux を無効にできます。

[root@localhost ~]# rpm -ihv kernel-2.6.9-42.0.8.EL_tomoyo_1.3.2.i586.rpm
Preparing...                ########################################### [100%]
Error: %pre(kernel-2.6.9-42.0.8.EL_tomoyo_1.3.2.i586) scriptlet failed, exit status 255
Error:   install: %pre scriptlet failed (2), skipping kernel-2.6.9-42.0.8.EL_tomoyo_1.3.2

なお、 TOMOYO Linux 自身は SELinux と同時に使用することができます。以下の操作では SELinux を有効にした状態でも構いません。

rpm の場合、インストールに成功すると /boot/grub/grub.conf に以下のような記述が追加されているはずです。

title CentOS (2.6.9-42.0.8.EL_tomoyo_1.3.2)
    root (hd0,0)
    kernel /vmlinuz-2.6.9-42.0.8.EL_tomoyo_1.3.2 ro root=/dev/VolGroup00/LogVol00
    initrd /initrd-2.6.9-42.0.8.EL_tomoyo_1.3.2.img

ここで、 kernel の行の末尾に init=/.init を追加します。

title CentOS (2.6.9-42.0.8.EL_tomoyo_1.3.2)
    root (hd0,0)
    kernel /vmlinuz-2.6.9-42.0.8.EL_tomoyo_1.3.2 ro root=/dev/VolGroup00/LogVol00 init=/.init
    initrd /initrd-2.6.9-42.0.8.EL_tomoyo_1.3.2.img

deb の場合、インストールに成功すると /boot/grub/menu.lst に以下のような記述が追加されているはずです。

title Debian GNU/Linux, kernel 2.6.8-16sarge6-ccs
root (hd0,0)
kernel /boot/vmlinuz-2.6.8-16sarge6-ccs root=/dev/sda1 ro
initrd /boot/initrd.img-2.6.8-16sarge6-ccs
savedefault
boot

ここで、 kernel の行の末尾に init=/.init を追加します。

title Debian GNU/Linux, kernel 2.6.8-16sarge6-ccs
root (hd0,0)
kernel /boot/vmlinuz-2.6.8-16sarge6-ccs root=/dev/sda1 ro init=/.init
initrd /boot/initrd.img-2.6.8-16sarge6-ccs
savedefault
boot

/.init は TOMOYO Linux のポリシーをカーネルに読み込むためのスクリプトで、 /sbin/init の開始前に実行されます。
/.init は次の手順でインストールするツールの中に含まれています。

TOMOYO Linux ツールのインストール

TOMOYO Linux では、いくつかのコンパイル済みのツールを提供しています。コンパイル済みのツールを利用する場合は、以下のファイルをダウンロードして /root/ ディレクトリの下に展開してください。

RedHat Linux 9 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-RHL9.tar.gz
Fedora Core 3 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-FC3.tar.gz
Fedora Core 4 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-FC4.tar.gz
Fedora Core 5 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-FC5.tar.gz
Fedora Core 6 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-FC6.tar.gz
CentOS 4.4 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-CentOS4.4.tar.gz
Debian Sarge (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-Sarge.tar.gz
Debian Etch (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-Etch.tar.gz
OpenSUSE 10.1 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-SUSE10.1.tar.gz
OpenSUSE 10.2 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-SUSE10.2.tar.gz
Asianux 2.0 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-AX2.tar.gz
Ubuntu 6.10 (80386以降用) http://osdn.dl.sourceforge.jp/tomoyo/23851/ccs-tools-1.3.2-i386-Ubuntu6.10.tar.gz

展開された .init (ポリシーローダー)を / へ移動してください。

mv ccstools/.init /

アーキテクチャが異なる場合には、ツールをコンパイルする必要があります。ツールをコンパイルするには、以下のコマンドを実行してください。

cd /root/
# TOMOYO Linux ツールのソースをダウンロードする。
wget http://osdn.dl.sourceforge.jp/tomoyo/23850/ccs-tools-1.3.2-20070214.tar.gz
# 展開する。
tar -zxf ccs-tools-1.3.2-20070214.tar.gz
# コンパイルする。
make -sC ccstools/
# ポリシーローダーを / へ移動する。
mv ccstools/.init /

ポリシーの作成

/etc/ccs/manager.txt を作成し、以下の内容を指定します。

/root/ccstools/editpolicy

/etc/ccs/status.txt を作成し、以下の内容を指定します。

MAC_FOR_FILE=1
MAX_ACCEPT_FILES=1048576
MAX_GRANT_LOG=0
MAX_REJECT_LOG=0
TOMOYO_VERBOSE=0

以下のコマンドを実行した結果を /etc/ccs/exception_policy.txt として保存してください。

/root/ccstools/make_exception.sh | grep ^file_pattern | sort | uniq

解析

TOMOYO Linuxカーネルで起動します。

/.init の実行に成功すると、以下のようなメッセージが表示されますので、そのまま Enter を押してください。

Press 'Enter' or wait for 10 seconds to use default status.
You may input 'disabled' and press 'Enter' to disable MAC in case of emergency.
>

プロファイルの読み込みが成功すると、 /sbin/init が開始されてシステムが起動します。
失敗した場合は、以下のようにメッセージが表示されて停止します。

No profiles loaded. Run policy loader using 'init=' option.

失敗した場合は以下の点を確認してください。

解析したいアプリケーションを動作させます。

/root/ccstools/editpolicy を実行すると、現在に至るまでに実行されたプログラムの一覧を表示できます。プログラムを選択して Enter を押すと、そのプログラムがアクセスしたファイルの一覧が表示されます。ポリシーエディタの使い方については、ポリシーエディタの使い方を参照してください。

/root/ccstools/savepolicy を実行すると、現在に至るまでにアクセスされたファイルの一覧を /etc/ccs/domain_policy.txt に保存することができます。