Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

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 ドメイン内で実行されます。これはあくまで例であり、本番環境では用いないでください。ここでは httpdwgetdbusaudit パッケージがインストールされ、SELinux ターゲットポリシーが使われ、SELinux が enforcing モードで実行されていることを前提としています。
  1. 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:        targeted
    SELinux が有効だと、SELinux status: enabled が返されます。SELinux が enforcing モードで実行中だと、Current mode: enforcing が返されます。SELinux ターゲットポリシーが使用されていると、Policy from config file: targeted が返されます。
  2. Linux root ユーザーで、touch /var/www/html/testfile コマンドを実行してファイルを作成します。
  3. 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/testfile
    Red Hat Enterprise Linux ではデフォルトで、Linux ユーザーは制限なしで実行します。そのため、testfile ファイルに SELinux unconfined_u ユーザーのラベルが付けられてます。RBAC はファイルでなくプロセスに使用されます。ロールはファイルにとって意味がありません。object_r ロールは、ファイルに使われる一般的なロールです (永続的なストレージおよびネットワークファイルシステム)。/proc/ ディレクトリー下では、プロセスに関連するファイルは system_r ロールを使用する場合があります。[7] httpd_sys_content_t タイプは、httpd プロセスがこのファイルにアクセスすることを許可します。
  4. chcon コマンドはラベルを張り替えますが、このラベル変更は、ファイルシステムのラベルが張り替えられると残りません。ファイルシステムのラベル張り替え後にも変更が残るようにするには、semanage コマンドを使います。これは後で説明します。Linux root ユーザーで以下のコマンドを実行し、タイプを Samba が使用するタイプに変更します。
    ~]# chcon -t samba_share_t /var/www/html/testfile
    ls -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/testfile
  5. service httpd status コマンドを実行し、httpd プロセスが稼働していないことを確認します。
    ~]$ service httpd status
    httpd is stopped
    出力が異なる場合は、Linux root ユーザーで service httpd stop コマンドを実行し、httpd プロセスを停止します。
    ~]# service httpd stop
    Stopping httpd:                                            [  OK  ]
  6. httpd プロセスを制限なしで実行するには、Linux root ユーザーで以下のコマンドを実行し、/usr/sbin/httpd のタイプを制限のある ドメインに移行しないタイプに変更します。
    ~]# chcon -t unconfined_exec_t /usr/sbin/httpd
  7. ls -Z /usr/sbin/httpd コマンドを実行し、/usr/sbin/httpdunconfined_exec_t タイプでラベル付けられていることを確認します。
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x  root root system_u:object_r:unconfined_exec_t:s0 /usr/sbin/httpd
  8. Linux root ユーザーで service httpd start コマンドを実行し、httpd プロセスを開始します。httpd が正常にスタートすると、出力は以下のようになります。
    ~]# service httpd start
    Starting httpd:                                            [  OK  ]
  9. ps -eZ | grep httpd コマンドを実行し、httpdunconfined_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
  10. 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 コマンドは失敗していたでしょう。
  11. 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:s0
    
    ls -Z /usr/sbin/httpd コマンドを実行し、/usr/sbin/httpdhttpd_exec_t タイプでラベル付けられていることを確認します。
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x  root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
  12. 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
  13. 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
  14. httpd の実行が不要ならば、Linux root ユーザーで service httpd stop コマンドを実行し、httpd を停止します。
    ~]# service httpd stop
    Stopping httpd:                                            [  OK  ]
このセクションの例は、危険にさらされた制限のあるプロセスからデータがどのように保護されるか (SELinux で保護)、また危険にさらされた制限のないプロセスから攻撃者がよりデータにアクセスしやすいか (SELinux で保護されていない) を示しています。


[7] MLS のような他のポリシーを使用している場合、secadm_r のような他のロールが使われることがあります。