AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 628344
Accepted
rekado
rekado
Asked: 2014-09-14 11:10:27 +0800 CST2014-09-14 11:10:27 +0800 CST 2014-09-14 11:10:27 +0800 CST

SELinux:无法将 Firefox 进程限制在 mozilla_t 域

  • 772

我的目标是在mozilla_t域中执行 Firefox 而不是unconfined_t. 这台机器在强制模式下运行带有 SELinux 的 Fedora 20。

不幸的是,我似乎无法做到这一点。无论我做什么,该过程总是在unconfined_t域中执行。

我知道要满足三个条件:

  1. 目标文件上下文 ( mozilla_exec_t) 必须对源域 (unconfined_t或bin_t)是可执行的
  2. 目标文件上下文 ( mozilla_exec_t) 必须标记为目标域 ( mozilla_t)的入口点
  3. 必须允许源域 (unconfined_t或) 转换到目标域 ( )bin_tmozilla_t

/usr/bin/firefox目标文件是调用的 firefox 脚本/usr/lib64/firefox/run-mozilla.run,它再次运行二进制文件/usr/lib64/firefox/firefox。这是ls -Z这些文件的输出:

-rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/bin/firefox
-rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/lib64/firefox/run-mozilla.sh
-rwxr-xr-x. root root system_u:object_r:mozilla_exec_t:s0 /usr/lib64/firefox/firefox

满足第一个条件,unconfined_t允许执行目标文件上下文mozilla_exec_t。

$ sesearch -s unconfined_t -t mozilla_exec_t -c file -p execute -Ad
Found 1 semantic av rules:
   allow unconfined_t mozilla_exec_t : file { ioctl read getattr lock execute execute_no_trans entrypoint open } ; 

满足第二个条件,mozilla_exec_t定义为mozilla_t域的入口点。

$ sesearch -s mozilla_t -t mozilla_exec_t -c file -p entrypoint -Ad
Found 1 semantic av rules:
   allow mozilla_t mozilla_exec_t : file { ioctl read getattr lock execute execute_no_trans entrypoint open } ; 

根据 Fedora 20 中的默认配置,不满足第三个条件,因为无法转换到.unconfined_tmozilla_t

$ sesearch -s unconfined_t -t mozilla_t -c process -p transition -Ad
(no output)

为了解决这个问题,我编写了一个简短的策略模块,该模块授予unconfined_t进程转换到mozilla_t.

module rekado 1.0;

require {
  type unconfined_t;
  type mozilla_t;
  class process transition;
}

allow unconfined_t mozilla_t : process transition ; 

现在我应该能够mozilla_t通过直接运行可执行文件在域中运行 Firefox 进程/usr/lib64/firefox/firefox,但该进程仍保留在域中unconfined_t。

这里发生了什么?为什么不是进程上下文mozilla_t?

fedora
  • 1 1 个回答
  • 1714 Views

1 个回答

  • Voted
  1. Best Answer
    Mike
    2015-08-21T11:21:28+08:002015-08-21T11:21:28+08:00

    你几乎拥有它。问题是允许规则

    允许 unconfined_t mozilla_t :进程转换;

    允许过渡发生,但不会导致它发生。为此,您需要一个 type_transition 规则:

    type_transition unconfined_t mozilla_exec_t : 进程 mozilla_t;

    这会导致在 unconfined_t 进程执行 mozilla_exec_t 文件时发生转换。

    完成后,Firefox 将无法运行。我使用 audit2allow 来追踪允许 Firefox 管理临时文件和套接字所需的附加规则。

    这是适用于我基于 CentOS 6 的 VM 的策略。它需要启用 selinux 布尔 mozilla_read_content(通过:)setsebool -P mozilla_read_content 1。

    module mozilla 1.0;
    
    require {
      role unconfined_r;
      type unconfined_t;
      type mozilla_t;
      type mozilla_exec_t;
      type tmp_t;
      type user_tmp_t;
      type fs_t;
      class process transition;
      class file { ioctl getattr setattr create read write unlink open relabelto };
      class dir { ioctl getattr setattr create read write unlink add_name remove_name };
      class filesystem getattr;
      class sock_file { getattr setattr create read write unlink };
      class unix_stream_socket connectto;
    }
    
    role unconfined_r types mozilla_t;
    
    allow unconfined_t self:file relabelto;
    allow unconfined_t mozilla_t : process transition ; 
    
    type_transition unconfined_t mozilla_exec_t : process mozilla_t;
    
    allow mozilla_t fs_t:filesystem getattr;
    allow mozilla_t tmp_t:file { ioctl getattr setattr create write unlink open };
    allow mozilla_t tmp_t:dir  { ioctl getattr setattr create read write add_name remove_name };
    allow mozilla_t user_tmp_t:dir { ioctl create write add_name setattr remove_name };
    allow mozilla_t user_tmp_t:sock_file { getattr setattr create read write unlink };
    allow mozilla_t unconfined_t:unix_stream_socket connectto;  
    

    要编译和安装它:

    # checkmodule -M -m -o mozilla.mod mozilla.te
    checkmodule:从 rekado.te 加载策略配置 checkmodule:加载策略配置
    checkmodule
    :将二进制表示(版本 10)写入 mozilla.mod
    # semodule_package -o mozilla.pp -m mozilla.mod
    # sudo semodule -i mozilla.pp

    • 4

相关问题

  • 将 Fedora 用于服务器有什么问题?

  • /usr/bin/ld: 找不到 -lssl

  • Ubuntu、Fedora、openSUSE 对比

  • Fedora 11 上的 DNS 服务器

  • 在 VM 中运行 Fedora 目录服务器

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve