linux能力集机制,Linux能力(capability)机制的继承

xlzh@cmos:~/code/capability$ gcc child.c -o child

xlzh@cmos:~/code/capability$ gcc father.c -o father -lcap

xlzh@cmos:~/code/capability$ sudo setcap cap_dac_override,cap_sys_time+ei child

xlzh@cmos:~/code/capability$ sudo setcap cap_dac_override,cap_sys_time+ip father

/* 单独执行,child文件有E(effective)I(inheritable)的能力,执行child的终端没有任何能力, 套用公式(cap_bset默认全1)

* P'(permitted) = (P(inheritable) & F(inheritable)) | (F(permitted) & cap_bset)  // P'(permitted) = (0x0 & 0x2000002) | (0x0 & 全1),结果为0

* P'(effective) = F(effective) ? P'(permitted) : 0                               // P'(effective) = 1 ? P'(permitted) : 0, 结果为P'(permitted),即0

* P'(inheritable) = P(inheritable)                                               // P'(inheritable) = 0

* 执行结果如下所示

*/

xlzh@cmos:~/code/capability$ ./child

child Cap data permitted: 0x0, effective: 0x0, inheritable 0x0

/* 单独执行,child文件有E(effective)I(inheritable)的能力,执行child的father文件有E(inheritable)和P(permitted)能力, 套用公式

* P'(permitted) = (P(inheritable) & F(inheritable)) | (F(permitted) & cap_bset)  // P'(permitted) = (0x2000002 & 0x2000002) | (0x2000002 & 全1),结果为0

* P'(effective) = F(effective) ? P'(permitted) : 0                               // P'(effective) = 1 ? P'(permitted) : 0, 结果为P'(permitted),即0x2000002

* P'(inheritable) = P(inheritable)                                               // P'(inheritable) = 0x2000002

* 执行结果如下所示

*/

xlzh@cmos:~/code/capability$ ./father

father Cap data permitted: 0x2000002, effective: 0x0, inheritable: 0x2000002

child Cap data permitted: 0x2000002, effective: 0x2000002, inheritable 0x2000002

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值