Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何执行流程,在缺少基于文件系统的功能的情况下保留功能?_Linux_Execve_Linux Capabilities - Fatal编程技术网

Linux 如何执行流程,在缺少基于文件系统的功能的情况下保留功能?

Linux 如何执行流程,在缺少基于文件系统的功能的情况下保留功能?,linux,execve,linux-capabilities,Linux,Execve,Linux Capabilities,我想使系统在没有setuid、文件“+p”功能的情况下可用,并且通常不需要设置时禁用的东西 使用这种方法(initSETPR\u SET\u NO\u NEW\u PRIVS和基于文件系统的功能提升不再可能),您无法“重新填充”您的功能,只需小心不要“飞溅”它们 如何execve执行一些其他进程而不“飞溅”任何授予的功能(例如,如果新程序的文件是setcap=ei)?只是“我信任这个新过程,就像我信任自己一样”。例如,一个功能被赋予了用户(用户希望在他启动的任何程序中使用它) 我是否可以使整个文

我想使系统在没有
setuid
、文件“+p”功能的情况下可用,并且通常不需要设置时禁用的东西

使用这种方法(
init
SET
PR\u SET\u NO\u NEW\u PRIVS
和基于文件系统的功能提升不再可能),您无法“重新填充”您的功能,只需小心不要“飞溅”它们

如何
execve
执行一些其他进程而不“飞溅”任何授予的功能(例如,如果新程序的文件是
setcap=ei
)?只是“我信任这个新过程,就像我信任自己一样”。例如,一个功能被赋予了用户(用户希望在他启动的任何程序中使用它)


我是否可以使整个文件系统永久
=ei
?我希望保持文件系统不干扰方案,不能够授予或撤销功能;通过父对象->子对象控制所有内容。

如果您参考功能手册页,目前没有简单的方法可以做到这一点:

During an execve(2), the kernel calculates the new capabilities of the process
using the following algorithm:

P'(permitted) = (P(inheritable) & F(inheritable)) | (F(permitted) & cap_bset)

P'(effective) = F(effective) ? P'(permitted) : 0 

P'(inheritable) = P(inheritable)    [i.e., unchanged]

where:

P        denotes the value of a thread capability set before the execve(2)
P'       denotes the value of a capability set after the execve(2)
F        denotes a file capability set
cap_bset is the value of the capability bounding set 
如果要执行的文件未设置fP位,或者未设置fI位,则进程将没有允许的功能,因此没有有效的功能

设置整个文件系统的允许位和继承位在技术上是可行的,但这没有多大意义,因为这会严重降低系统的安全性(编辑:正如您提到的,这对新的可执行文件不起作用)

您确实可以为使用pam_cap的用户提供一些功能,但您不能让他们执行刚刚使用pam_cap编译的任何文件。功能的设计旨在为程序而非用户提供电源,您可以阅读:

一个关键的洞察是观察到程序而不是人在锻炼 特权也就是说,在计算机中所做的一切都是通过 代理程序,并且仅当这些程序知道如何处理时 可以信任他们可以使用特权

另请参见定义POSIX功能的1003.1e,第310页:

也不适合为流程链(a)建立 单个进程中的程序序列)一组功能 在该链的整个生命周期中保持固定和活动。[...] 这是最小特权原则的应用,而且 同样适用于用户和流程

最近(2012年12月),有人要求在Linux内核邮件列表中介绍您想做什么,这里给出了一些非常有趣的答案。有些人认为,在继承规则中跨
exec
删除文件功能会带来一些安全问题,而且这些功能不是为这样的功能设计的,尽管wrt没有解释它会带来哪些安全问题:

目前唯一的方法是修改Linux内核中继承功能的方式(要修改2个文件,我在3.7内核上成功地测试了它),但不清楚这是否是安全的,如上所述


在旧内核(2.6.33之前)上,有一个选项可以在没有文件功能的情况下编译(
CONFIG\u SECURITY\u file\u capabilities
),但我怀疑使用这样一个旧内核对您来说是一个选项。

我不是说我建议您这样做,而是在这里

从手册中摘录,有一些变化。根据它:
fork
不会改变功能。现在Linux内核4.3中添加了一个环境设置,似乎这就是您想要做的

   Ambient (since Linux 4.3):
          This is a set of capabilities that are preserved across an execve(2) of a program that is not privileged.  The ambient capability set obeys the invariant that no capability can ever
          be ambient if it is not both permitted and inheritable.

          The ambient capability set can be directly modified using
          prctl(2).  Ambient capabilities are automatically lowered if
          either of the corresponding permitted or inheritable
          capabilities is lowered.

          Executing a program that changes UID or GID due to the set-
          user-ID or set-group-ID bits or executing a program that has
          any file capabilities set will clear the ambient set.  Ambient
          capabilities are added to the permitted set and assigned to
          the effective set when execve(2) is called.

   A child created via fork(2) inherits copies of its parent's
   capability sets.  See below for a discussion of the treatment of
   capabilities during execve(2).

Transformation of capabilities during execve()
   During an execve(2), the kernel calculates the new capabilities of
   the process using the following algorithm:

       P'(ambient) = (file is privileged) ? 0 : P(ambient)

       P'(permitted) = (P(inheritable) & F(inheritable)) |
                       (F(permitted) & cap_bset) | P'(ambient)

       P'(effective) = F(effective) ? P'(permitted) : P'(ambient)

       P'(inheritable) = P(inheritable)    [i.e., unchanged]

   where:

       P         denotes the value of a thread capability set before the
                 execve(2)

       P'        denotes the value of a thread capability set after the
                 execve(2)

       F         denotes a file capability set

       cap_bset  is the value of the capability bounding set (described
                 below).

   A privileged file is one that has capabilities or has the set-user-ID
   or set-group-ID bit set.
我认为(我的理解),使用功能的最佳方式是:

  • 对于需要功能且受信任的程序,包括受信任的不泄漏功能:例如wire shark的数据包嗅探部分,需要在端口80上侦听的web服务器。
    • 新程序、功能感知:允许设置
    • 遗留程序,不了解功能:设置允许且有效
  • 对于将泄漏功能的程序,以及可能(有时)使用功能的代码:set inherited
    • e、 g.对于
      chmod
      set-inherit-CAP\u-FOWNER,如果用户需要超级权限(通常由root持有),那么他们需要使用
      setpriv
      (或者等效的,这可以滚动到
      sudo
      ),否则它可以在非特权模式下工作
  • 当一个流程需要分叉和共享一些功能时,然后并且只有在那时才使用环境。可能是同一个可执行文件;如果是另一个,那么这个新的将允许或继承文件上的集合。[编辑:我刚刚意识到,如果您不执行,就不需要环境。如果我想到了环境的一个用例,在一个设置良好的系统中,那么我将在这里添加它。环境可以用作一种过渡机制,如果没有在可以使用它的文件上设置继承机制。]
环境空气污染物的用途:

  • 在文件没有正确功能的系统上。(过渡技术)
  • 对于shell脚本,除了在脚本上具有固定且随后允许setuid的系统上,它们不能具有功能(因为它们不能具有setuid)
  • 在这里添加更多
想象一下,我以某种方式运行了一个具有有效权限的程序(shell)。我可以让它动态加载库并执行任何代码。但是,除了动态库(只是普通程序)之外,还可以方便地加载其他东西。有了PR_SET_NO_NEW priv,你就无法获得新的priv。但是我需要一个工具来防止“丢失”已经存在的priv。
设置整个文件系统的有效位
->或者将其设置为/lib/ld linux*<代码>强烈降低系统上的安全性->如果您监督进程获得+i,则不应这样做。它将“向程序授予权限”转换为“向用户授予权限”(即用户ca