
自内核 2.2 版本开始,Linux 将传统上与超级用户关联的特权分为几个单元,称为 capabilities (权能),它们可以被独立的启用或禁用。权能是每个线程的属性。
下面的列表展示了 Linux 上实现的权能,以及每种权能允许的 *** 作或行为:
权能的完整实现需要:
在内核 2.6.24 之前,只有前两个要求能够满足;自内核 2.6.24 开始,所有三个要求都能满足。
每个线程具有三个包含零个或多个上面的权能的权能集合:
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).
Using capset(2), a thread may manipulate its own capability sets (see below).
Since Linux 3.2, the file /proc/sys/kernel/cap_last_cap exposes the numerical value of the highest capability supported by the running kernelthis can be used to determine the highest bit that may be set in a capability set.
Since kernel 2.6.24, the kernel supports associating capability sets with an executable file using setcap(8). The file capability sets are stored in an extended attribute (see setxattr(2)) named security.capability. Writing to this extended attribute requires the CAP_SETFCAP capability. The file capability sets, in conjunction with the capability sets of the thread, determine the capabilities of a thread after an execve(2).
The three file capability sets are:
During an execve(2), the kernel calculates the new capabilities of the process using the following algorithm:
其中:
A privileged file is one that has capabilities or has the set-user-ID or set-group-ID bit set.
In order to provide an all-powerful root using capability sets, during an execve(2):
The upshot of the above rules, combined with the capabilities transformations described above, is that when a process execve(2)s a set-user-ID-root program, or when a process with an effective UID of 0 execve(2)s a program, it gains all capabilities in its permitted and effective capability sets, except those masked out by the capability bounding set. This provides semantics that are the same as those provided by traditional UNIX systems.
The capability bounding set is a security mechanism that can be used to limit the capabilities that can be gained during an execve(2). The bounding set is used in the following ways:
Note that the bounding set masks the file permitted capabilities, but not the inherited capabilities. If a thread maintains a capability in its inherited set that is not in its bounding set, then it can still gain that capability in its permitted set by executing a file that has the capability in its inherited set.
Depending on the kernel version, the capability bounding set is either a system-wide attribute, or a per-process attribute.
In kernels before 2.6.25, the capability bounding set is a system-wide attribute that affects all threads on the system. The bounding set is accessible via the file /proc/sys/kernel/cap-bound. (Confusingly, this bit mask parameter is expressed as a signed decimal number in /proc/sys/kernel/capbound.)
Only the init process may set capabilities in the capability bounding setother than that, the superuser (more precisely: programs with the CAP_SYS_MODULE capability) may only clear capabilities from this set.
On a standard system the capability bounding set always masks out the CAP_SETPCAP capability. To remove this restriction (dangerous!), modify the definition of CAP_INIT_EFF_SET in include/linux/capability.h and rebuild the kernel.
The system-wide capability bounding set feature was added to Linux starting with kernel version 2.2.11.
From Linux 2.6.25, the capability bounding set is a per-thread attribute. (There is no longer a systemwide capability bounding set.)
The bounding set is inherited at fork(2) from the thread's parent, and is preserved across an execve(2).
A thread may remove capabilities from its capability bounding set using the prctl(2) PR_CAPBSET_DROP operation, provided it has the CAP_SETPCAP capability. Once a capability has been dropped from the bounding set, it cannot be restored to that set. A thread can determine if a capability is in its bounding set using the prctl(2) PR_CAPBSET_READ operation.
Removing capabilities from the bounding set is supported only if file capabilities are compiled into the kernel. In kernels before Linux 2.6.33, file capabilities were an optional feature configurable via the CONFIG_SECURITY_FILE_CAPABILITIES option. Since Linux 2.6.33, the configuration option has been removed and file capabilities are always part of the kernel. When file capabilities are compiled into the kernel, the init process (the ancestor of all processes) begins with a full bounding set. If file capabilities are not compiled into the kernel, then init begins with a full bounding set minus CAP_SETPCAP, because this capability has a different meaning when there are no file capabilities.
Removing a capability from the bounding set does not remove it from the thread's inherited set. However it does prevent the capability from being added back into the thread's inherited set in the future.
To preserve the traditional semantics for transitions between 0 and nonzero user IDs, the kernel makes the following changes to a thread's capability sets on changes to the thread's real, effective, saved set, and filesystem user IDs (using setuid(2), setresuid(2), or similar):
If a thread that has a 0 value for one or more of its user IDs wants to prevent its permitted capability set being cleared when it resets all of its user IDs to nonzero values, it can do so using the prctl(2) PR_SET_KEEPCAPS operation or the SECBIT_KEEP_CAPS securebits flag described below.
A thread can retrieve and change its capability sets using the capget(2) and capset(2) system calls. However, the use of cap_get_proc(3) and cap_set_proc(3), both provided in the libcap package, is preferred for this purpose. The following rules govern changes to the thread capability sets:
Starting with kernel 2.6.26, and with a kernel in which file capabilities are enabled, Linux implements a set of per-thread securebits flags that can be used to disable special handling of capabilities for UID 0 (root). These flags are as follows:
Each of the above "base" flags has a companion "locked" flag. Setting any of the "locked" flags is irreversible, and has the effect of preventing further changes to the corresponding "base" flag. The locked flags are: SECBIT_KEEP_CAPS_LOCKED, SECBIT_NO_SETUID_FIXUP_LOCKED, SECBIT_NOROOT_LOCKED, and SECBIT_NO_CAP_AMBIENT_RAISE.
The securebits flags can be modified and retrieved using the prctl(2) PR_SET_SECUREBITS and PR_GET_SECUREBITS operations. The CAP_SETPCAP capability is required to modify the flags.
The securebits flags are inherited by child processes. During an execve(2), all of the flags are preserved, except SECBIT_KEEP_CAPS which is always cleared.
An application can use the following call to lock itself, and all of its descendants, into an environment where the only way of gaining capabilities is by executing a program with associated file capabilities:
For a discussion of the interaction of capabilities and user namespaces, see user_namespaces(7).
No standards govern capabilities, but the Linux capability implementation is based on the withdrawn POSIX.1e draft standardsee ⟨ http://wt.tuxomania.net/publications/posix.1e/ ⟩.
From kernel 2.5.27 to kernel 2.6.26, capabilities were an optional kernel component, and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES kernel configuration option.
The /proc/PID/task/TID/status file can be used to view the capability sets of a thread. The /proc/PID/status file shows the capability sets of a process's main thread. Before Linux 3.8, nonexistent capabilities were shown as being enabled (1) in these sets. Since Linux 3.8, all nonexistent capabilities (above CAP_LAST_CAP) are shown as disabled (0).
The libcap package provides a suite of routines for setting and getting capabilities that is more comfortable and less likely to change than the interface provided by capset(2) and capget(2). This package also provides the setcap(8) and getcap(8) programs. It can be found at ⟨ http://www.kernel.org/pub/linux/libs/security/linux-privs ⟩.
Before kernel 2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if file capabilities are not enabled, a thread with the CAP_SETPCAP capability can manipulate the capabilities of threads other than itself. However, this is only theoretically possible, since no thread ever has CAP_SETPCAP in either of these cases:
capsh(1), setpriv(1), prctl(2), setfsuid(2), cap_clear(3), cap_copy_ext(3), cap_from_text(3), cap_get_file(3), cap_get_proc(3), cap_init(3), capgetp(3), capsetp(3), libcap(3), credentials(7), user_namespaces(7), pthreads(7), getcap(8), setcap(8)
include/linux/capability.h in the Linux kernel source tree
This page is part of release 4.04 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/ .
查看内核版本命令:
1) [root@localhost~]# cat /proc/version
Linux version 2.6.18-238.el5 ([mockbuild@x86-012.build.bos.redhat.com](mailto:mockbuild@x86-012.build.bos.redhat.com)) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Sun Dec 19 14:22:44 EST 2010
2)[root@localhost~]# uname -r
2.6.18-238.el5
3)[root@localhost~]# uname -a
Linux SOR_SYS.99bill.com 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
查看linux版本:
1) 登录到服务器执行 lsb_release -a ,即可列出所有版本信息,例如:
[root@localhost~]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: RedHatEnterpriseAS
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 4)
Release: 4
Codename: NahantUpdate4
注:这个命令适用于所有的linux,包括Redhat、SuSE、Debian等发行版。
2) 登录到linux执行cat /etc/issue,例如如下:
[root@localhost~]# cat /etc/issue
Red Hat Enterprise Linux Server release 5.6 (Tikanga)
Kernel \r on an \m
- 3) 登录到linux执行cat /etc/redhat-release ,例如如下:
- [root@localhost~]# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 4)
- 注:这种方式下可以直接看到具体的版本号,比如 AS4 Update 1
另:第3)、4)两种方法只对Redhat Linux有效
5) [root@localhost~]# file /bin/bash
/bin/bash: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
6) [root@localhost~]# file /bin/cat
/bin/cat: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
linux版本信息说明
Linux内核版本有两种:稳定版和开发版 ,Linux内核版本号由3个数字组成:r.x.y
r:目前发布的内核主版本。
x:偶数表示稳定版本;奇数表示开发中版本。
y:错误修补的次数。
内核版本号每位都代表什么 ?
•以版本号为例: 2.6.18-128.ELsmp ,
•r: 2 , 主版本号
•x: 6 , 次版本号,表示稳定版本
•y: 18 , 修订版本号 , 表示修改的次数,头两个数字合在一齐可以描述内核系列。如稳定版的2.6.0,它是2.6版内核系列。
•128: 表示这个当前版本的第5次微调patch , 而ELsmp指出了当前内核是为ELsmp特别调校的
•EL : Enterprise Linux ; smp : 表示支持多处理器 , 表示该内核版本支持多处理器
amd和intel
amd和Intel这俩公司的渊源很深,早期时Intel先是自己搞了个x86架构,然后amd拿到了x86的授权也可以自己做x86了。接着intel向64位过渡的时候自己搞了个ia64(x64架构)但是因为和x86架构不兼容市场反应极差,amd率先搞了x86的64位兼容(32和64的混合架构)也就是后来的x86-64,后来Intel也拿到了生产这货的授权(i和a两家专利交叉的很严重),也搞了x86-64,因为amd先搞出来的所以x86-64也叫amd64
目前amd和Intel是世界上最大的两家x86和x86-64的cpu厂家(intel比较给力,四分天下有其三)。除了这两家还有几家小的公司也有x86的授权,比如via,不过技术水平真的很一般
x86
x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为“IA-32”
早期的x86是cisc的代表,后来的发展中逐步引入了risc的部分理念,将内部指令的实现大量模块化,准确来说是一个cisc外加risc部分技术的架构。目前x86的主要产品有Intel的至强,酷睿,奔腾,赛扬和凌动;amd的锐龙,apu等。上文提到的x64架构目前只有intel 安腾而且已经放弃了产品线。
到目前为止intel和amd的x86架构cpu虽然指令集上有很大差别了但是还是相互兼容的,所以软件可以直接用。'
x84_64 与amd64
x84_64是x86 CPU开始迈向64位的时候,有2选择:1、向下兼容x86。2、完全重新设计指令集,不兼容x86。AMD抢跑了,比Intel率先制造出了商用的兼容x86的CPU,AMD称之为AMD64,抢了64位PC的第一桶金,得到了用户的认同。而Intel选择了设计一种不兼容x86的全新64为指令集,称之为IA-64(这玩意似乎就是安腾),但是比amd晚了一步,而且IA-64也挺惨淡的,因为是全新设计的CPU,没有编译器,也不支持windows(微软把intel给忽悠了,承诺了会出安腾版windows server版,但是迟迟拿不出东西)。。。后来不得不在时机落后的情况下也开始支持AMD64的指令集,但是换了个名字,叫x86_64,表示是x86指令集的64扩展,大概是不愿意承认这玩意是AMD设计出来的。
也就是说实际上,x86_64,x64,AMD64基本上是同一个东西,我们现在用的intel/amd的桌面级CPU基本上都是x86_64,与之相对的arm,ppc等都不是x86_64。
arm与mips
arm是risc的典型代表,不过在arm的发展过程中引入了部分复杂指令(完全没有复杂指令的话 *** 作系统跑起来异常艰难),所以是一个risc基础外加cisc技术的cpu。
arm的主要专利技术在arm公司手中,像高通,三星,苹果这些公司需要拿到arm的授权。
另一个risc的典型处理器就是mips。mips是一个学院派的cpu,授权门槛极低,因此很多厂家都做mips或者mips衍生架构。我们平时接触到的mips架构cpu主要用在嵌入式领域,比如路由器。
目前最活跃的mips是中国的龙芯,其loongisa架构其实是mips的扩展。
mips mipsel mips64el 区别
- Debian目前提供3个端口,'mips','mipsel'和'mips64el'。 'mips'和'mipsel'端口分别是大端和小端变体,使用O32 ABI和硬件浮点。他们在Jessie中使用MIPS II ISA,在Stretch中使用MIPS32R2 ISA。 'mips64el'端口是一个64位小端端口,使用N64 ABI,硬件浮点和MIPS64R2 ISA。
- mips 是32位大端字节序
- mipsel 是32位小端字节序
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)