4.2. 制限のないプロセス
制限のないプロセスは、制限のないドメインで実行されます。例えば、init プログラムは制限のない
initrc_t ドメインで、制限のないカーネルプロセスはkernel_t ドメインで、制限のない Linux ユーザーは unconfined_t ドメインで実行されます。制限のないプロセスでは、SELinux ポリシールールは適用されますが、既存のポリシールールは制限のないドメイン内で実行中のプロセスにほとんどすべてのアクセスを許可します。制限のないドメイン内で実行中のプロセスは、もっぱら DAC ルールにフォールバックします。制限のないプロセスが危険にさらされても、SELinux は攻撃者によるシステムリソースやデータへのアクセス獲得を阻止しません。しかし、もちろん DAC ルールは常に使われます。SELinux は DAC ルールの上に加わるもので、DAC ルールに取って代わるものではありません。
以下の例では、制限なしで実行中の場合、Apache HTTP Server (
httpd) が Samba 向けのデータにアクセスできる様子を示します。注記: Red Hat Enterprise Linux ではデフォルトで、httpd プロセスは制限のある httpd_t ドメイン内で実行されます。これはあくまで例であり、本番環境では用いないでください。ここでは httpd、wget、dbus、audit パッケージがインストールされ、SELinux ターゲットポリシーが使われ、SELinux が enforcing モードで実行されていることを前提としています。
sestatusコマンドを実行し、SELinux が有効になっていること、 enforcing モードで実行中であること、ターゲットポリシーが使われていること、を確認します。~]$ sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targetedSELinux が有効だと、SELinux status: enabledが返されます。SELinux が enforcing モードで実行中だと、Current mode: enforcingが返されます。SELinux ターゲットポリシーが使用されていると、Policy from config file: targetedが返されます。- Linux root ユーザーで、
touch /var/www/html/testfileコマンドを実行してファイルを作成します。 ls -Z /var/www/html/testfileコマンドを実行し、SELinux コンテキストを表示します。~]$ ls -Z /var/www/html/testfile -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/testfileRed Hat Enterprise Linux ではデフォルトで、Linux ユーザーは制限なしで実行します。そのため、testfileファイルに SELinuxunconfined_uユーザーのラベルが付けられてます。RBAC はファイルでなくプロセスに使用されます。ロールはファイルにとって意味がありません。object_rロールは、ファイルに使われる一般的なロールです (永続的なストレージおよびネットワークファイルシステム)。/proc/ディレクトリー下では、プロセスに関連するファイルはsystem_rロールを使用する場合があります。[7]httpd_sys_content_tタイプは、httpdプロセスがこのファイルにアクセスすることを許可します。chconコマンドはラベルを張り替えますが、このラベル変更は、ファイルシステムのラベルが張り替えられると残りません。ファイルシステムのラベル張り替え後にも変更が残るようにするには、semanageコマンドを使います。これは後で説明します。Linux root ユーザーで以下のコマンドを実行し、タイプを Samba が使用するタイプに変更します。~]# chcon -t samba_share_t /var/www/html/testfilels -Z /var/www/html/testfileコマンドを実行し、変更を表示します。~]$ ls -Z /var/www/html/testfile -rw-r--r-- root root unconfined_u:object_r:samba_share_t:s0 /var/www/html/testfileservice httpd statusコマンドを実行し、httpdプロセスが稼働していないことを確認します。~]$ service httpd status httpd is stopped出力が異なる場合は、Linux root ユーザーでservice httpd stopコマンドを実行し、httpdプロセスを停止します。~]# service httpd stop Stopping httpd: [ OK ]httpdプロセスを制限なしで実行するには、Linux root ユーザーで以下のコマンドを実行し、/usr/sbin/httpdのタイプを制限のある ドメインに移行しないタイプに変更します。~]# chcon -t unconfined_exec_t /usr/sbin/httpdls -Z /usr/sbin/httpdコマンドを実行し、/usr/sbin/httpdがunconfined_exec_tタイプでラベル付けられていることを確認します。~]$ ls -Z /usr/sbin/httpd -rwxr-xr-x root root system_u:object_r:unconfined_exec_t:s0 /usr/sbin/httpd- Linux root ユーザーで
service httpd startコマンドを実行し、httpdプロセスを開始します。httpdが正常にスタートすると、出力は以下のようになります。~]# service httpd start Starting httpd: [ OK ] ps -eZ | grep httpdコマンドを実行し、httpdがunconfined_tドメインで実行していることを表示します。~]$ ps -eZ | grep httpd unconfined_u:unconfined_r:unconfined_t:s0 7721 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7723 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7724 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7725 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7726 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7727 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7728 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7729 ? 00:00:00 httpd unconfined_u:unconfined_r:unconfined_t:s0 7730 ? 00:00:00 httpd- Linux ユーザーでの書き込みアクセスがあるディレクトリーに切り替え、
wget http://localhost/testfileコマンドを実行します。デフォルト設定に変更がなければ、このコマンドは成功します。~]$ wget http://localhost/testfile --2009-05-07 01:41:10-- http://localhost/testfile Resolving localhost... 127.0.0.1 Connecting to localhost|127.0.0.1|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 0 [text/plain] Saving to: `testfile.1' [ <=> ]--.-K/s in 0s 2009-05-07 01:41:10 (0.00 B/s) - `testfile.1' saved [0/0]httpdプロセスにはsamba_share_tタイプのラベルが付けられたファイルへのアクセス権はありませんが、httpdは制限のないunconfined_tドメインで実行しており、DAC ルールの使用にフォールバックします。このため、wgetコマンドは成功します。もしhttpdが制限のあるhttpd_tドメインで実行していたなら、wgetコマンドは失敗していたでしょう。 restoreconコマンドは、デフォルトのファイル向け SELinux コンテキストを復元します。Linux root ユーザーでrestorecon -v /usr/sbin/httpdコマンドを実行し、/usr/sbin/httpdのデフォルトの SELinux コンテキストを復元します。~]# restorecon -v /usr/sbin/httpd restorecon reset /usr/sbin/httpd context system_u:object_r:unconfined_exec_t:s0->system_u:object_r:httpd_exec_t:s0ls -Z /usr/sbin/httpdコマンドを実行し、/usr/sbin/httpdがhttpd_exec_tタイプでラベル付けられていることを確認します。~]$ ls -Z /usr/sbin/httpd -rwxr-xr-x root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd- Linux root ユーザーで
service httpd restartコマンドを実行し、httpdを再スタートさせます。再スタート後にps -eZ | grep httpdコマンドを実行し、httpdが制限のあるhttpd_tドメインで実行中であることを確認します。~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] ~]# ps -eZ | grep httpd unconfined_u:system_r:httpd_t:s0 8880 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8882 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8883 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8884 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8885 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8886 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8887 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8888 ? 00:00:00 httpd unconfined_u:system_r:httpd_t:s0 8889 ? 00:00:00 httpd - Linux root ユーザーで
rm -i /var/www/html/testfileコマンドを実行し、testfileを削除します。~]# rm -i /var/www/html/testfile rm: remove regular empty file `/var/www/html/testfile'? y httpdの実行が不要ならば、Linux root ユーザーでservice httpd stopコマンドを実行し、httpdを停止します。~]# service httpd stop Stopping httpd: [ OK ]
このセクションの例は、危険にさらされた制限のあるプロセスからデータがどのように保護されるか (SELinux で保護)、また危険にさらされた制限のないプロセスから攻撃者がよりデータにアクセスしやすいか (SELinux で保護されていない) を示しています。