微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

fork和execveinheritance父进程的function

在linux系统中,非root用户简单地创build程序/进程。 这个过程有“CAP_NET_RAW”,“CAP_NET_ADMIN”,模式为“有效,允许,可inheritance”。 这个过程通过调用fork和execv调用一个程序“udhcpc”来创buildsubprocess。 但subprocess没有按预期inheritance“CAP_NET_RAW”,“CAP_NET_ADMIN”function。 甚至在设置function之前,我称之为“prctl(PR_SET_KEEPCAPS,1)”。 任何build议fork和execveinheritance非根父进程的能力。

感谢Eswar

带有setuid /function的stdbuf

删除根UID,同时保留CAP_SYS_NICE

如何执行进程,尽pipe缺less基于文件系统的function,仍然保留了function?

制作一个设置POSIX文件function的RPM

在cordova项目中为windows平台添加function

execve() ,正在执行的文件(在本例中为udhcpc )的文件功能集将被检查并与线程的功能集相结合。 特别是,文件的Inheritable集与线程的Inheritable集进行AND运算,以确定新的Permitted集,并且必须设置文件的Effective位才能从Permitted集中复制新的Effective集。

这意味着在你的情况下,你必须使用setcap cap_net_raw,cap_net_admin=ei /path/to/udhcpc来获得你想要的效果(除了在父进程中设置能力 – prctl()不是必需的)。

根据Michael Kerrisk的“The Linux Programming Interface”(No Starch Press,2010):

由于内核2.6.24,可以将功能附加到文件。 内核2.6.25和2.6.26中添加了各种其他功能,以完成功能实现。

sucap和execcap工具是你应该查找的。 但是,如果我记得限于限制,而不是授予能力。 看着 :

http://www.linuxjournal.com/article/5737

http://lkml.indiana.edu/hypermail/linux/kernel/0503.1/2540.html

从手册中提取出来,有一些变化。 根据它fork不改变的能力。 现在有一个环境设置,这似乎是你正在尝试做什么。

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).

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) [ie,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).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐