検索

2.3. 制限のないプロセス

download PDF
制限のないプロセスは制限のないドメインで実行されます。例えば、init プログラムは制限のない initrc_t ドメインで実行され、制限のないカーネルプロセスは kernel_t ドメインで、制限のない Linux ユーザーは unconfined_t ドメインで実行されます。制限のないプロセスの場合でも SELinux ポリシールールは適用されます。ただし、既存のポリシールールは制限のないドメイン内で実行中のプロセスにほとんどすべてのアクセスを許可します。このため、制限のないドメイン内で実行中のプロセスは、もっぱら DAC ルールに依存することになります。制限のないプロセスが攻撃された場合、攻撃者によってシステムリソースやデータへのアクセス権が奪われても SELinux ではそれを阻止しませんが、 DAC ルールは常に適用されます。SELinux は DAC ルールに加えて使用することで二重のセキュリティ強化を施行するものであり、DAC ルールの代替として使用するものではありません。
以下の例では、 Apache HTTP Server (httpd) を制限なしで実行している場合、 Samba 向けのデータにApache HTTP Server をどのようにしてアクセスさせることができるかを示します。Red Hat Enterprise Linux では、httpd プロセスはデフォルトで制限のある httpd_t ドメイン内で実行されます。次の例はあくまで例であり、実稼働環境では使用しないでください。httpdwgetdbusaudit パッケージがインストールされていること、 SELinux targeted ポリシーが使われていること、 またモードは enforcing で実行されていることを前提としています。
  1. sestatus コマンドを実行し、 SELinux が有効になっていること、 enforcing モードで実行していること、 targeted ポリシーが使われていることを確認します。
    $ /usr/sbin/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 targeted ポリシーが使用されていると、 Policy from config file: targeted が返されます。
  2. root ユーザーになり、 touch /var/www/html/test2file コマンドを実行してファイルを作成します。
  3. ls -Z /var/www/html/test2file コマンドを実行して SELinux のコンテキストを表示します。
    -rw-r--r--  root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/test2file
    
    test2file には SELinux unconfined_u ユーザーのラベルが付けられています。 unconfined_u SELinux ユーザーにマッピングされた Linux ユーザーによってこのファイルが作成されたためです。 ファイルではなくプロセスの場合には、 ロールベースのアクセス制御 (RBAC) が使用されます。 ファイルの場合、 ロールの使用は意味がありません。 object_r ロールはファイルに使用される汎用ロールになります (永続的なストレージおよびネットワークファイルシステム上)。 /proc/ ディレクトリ配下では、 プロセスに関連するファイルは system_r ロールを使用することができます。 [4]httpd_sys_content_t タイプを使用すると、 httpd プロセスにこのファイルへのアクセスを許可することになります。
  4. chcon コマンドでファイルのラベルを付け換えます。ただし、ファイルシステムのラベルが付け換えられると、 この変更は失われます。ファイルシステムのラベルが付け換えられた場合でも、 こうした変更を永続的に維持するには、semanage コマンドを使用します。このコマンドについてはのちほど説明していきます。 root ユーザーになり、次のコマンドを実行してタイプを Samba で使用されるタイプに変更します。
    chcon -t samba_share_t /var/www/html/test2file
    ls -Z /var/www/html/test2file コマンドを実行して変更を表示します。
    -rw-r--r--  root root unconfined_u:object_r:samba_share_t:s0 /var/www/html/test2file
    
  5. service httpd status コマンドを実行し、 httpd プロセスが実行していないことを確認します。
    $ /sbin/service httpd status
    httpd is stopped
    
    出力が異なる場合は、 root ユーザーで service httpd stop コマンドを実行し、 httpd プロセスを停止します。
    # /sbin/service httpd stop
    Stopping httpd:                                            [  OK  ]
    
  6. httpd プロセスを制限なしで実行する場合は、 root ユーザーで以下のコマンドを実行し、 /usr/sbin/httpd のタイプを制限のあるドメインに遷移しないタイプに変更します。
    chcon -t unconfined_exec_t /usr/sbin/httpd
  7. ls -Z /usr/sbin/httpd コマンドを実行し、 /usr/sbin/httpdunconfined_exec_t タイプでラベル付けされていることを確認します。
    -rwxr-xr-x  root root system_u:object_r:unconfined_exec_t /usr/sbin/httpd
    
  8. root ユーザーになり、 service httpd start コマンドを使って httpd プロセスを開始します。 httpd が正常に起動すると以下のような出力が表示されます。
    # /sbin/service httpd start
    Starting httpd:                                            [  OK  ]
    
  9. ps -eZ | grep httpd コマンドを実行し、 httpd プロセスが unconfined_t ドメイン内で実行していることを表示します。
    $ ps -eZ | grep httpd
    unconfined_u:system_r:unconfined_t 7721 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7723 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7724 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7725 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7726 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7727 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7728 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7729 ?      00:00:00 httpd
    unconfined_u:system_r:unconfined_t 7730 ?      00:00:00 httpd
    
  10. Linux ユーザーでの書き込みアクセスがあるディレクトリに移動し、 wget http://localhost/test2file コマンドを実行します。 デフォルト設定に変更がなければ、 このコマンドは成功します。
    --2009-12-01 11:55:47--  http://localhost/test2file
    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: `test2file.1'
    
    [ <=>                            ]--.-K/s   in 0s      
    	
    2009-12-01 11:55:47 (0.00 B/s) - `test2file.1' saved [0/0]
    
    httpd プロセスには samba_share_t タイプのラベルが付けられたファイルへのアクセス権はありませんが、 httpd は制限のない unconfined_t ドメイン内で実行しているため、 DAC ルールの使用に依存しています。 したがって、 wget コマンドは成功します。 もし httpd が制限のある httpd_t ドメインで実行していたなら、 wget コマンドは失敗していたでしょう。
  11. restorecon コマンドは、 ファイルのデフォルト SELinux コンテキストを復元します。 root ユーザーになり、 restorecon -v /usr/sbin/httpd コマンドを実行して、 /usr/sbin/httpd のデフォルトの SELinux コンテキストを復元します。
    # /sbin/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   /usr/sbin/httpd
    
  12. root ユーザーになり、 /sbin/service httpd restart コマンドを実行し、 httpd を再起動します。 再起動したら、 ps -eZ | grep httpd コマンドを実行して httpd が制限のある httpd_t ドメイン内で実行していることを確認します。
    # /sbin/service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
    # ps -eZ | grep httpd
    unconfined_u:system_r:httpd_t    8880 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8882 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8883 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8884 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8885 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8886 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8887 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8888 ?        00:00:00 httpd
    unconfined_u:system_r:httpd_t    8889 ?        00:00:00 httpd
    
  13. root ユーザーになり、 rm /var/www/html/test2file コマンドを実行し test2file を削除します。
  14. httpd を実行しておく必要がない場合は、 root ユーザーになり service httpd stop コマンドを実行し httpd を停止します。
    # /sbin/service httpd stop
    Stopping httpd:                                            [  OK  ]
    
このセクションでは、 制限のあるプロセスが攻撃を受けた場合、データはどのように保護されるのか (SELinux で保護)、また制限のないプロセスが攻撃を受けた場合、攻撃者にとっていかにデータにアクセスしやすいか (SELinux で保護されていない) を例を使って説明しました。


[4] MLS など他のポリシーを使用する場合は secadm_r など別のロールを使用する場合があります。
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.