selinux与kernel 0day

kernel NULL pointer的利用需要把shellcode映射到内存0处, 大家在测试exp的时候,总能发现一个规律, 开着selinux就能溢出成功, 关闭就不能溢出成功了。 看了下内核源码,终于搞清楚了: mmap在做匿名映射的时候,会经过LSM层来做安全验证, LSM初始化的时候,会将selinux作为它的第一验证模块, capablity作为它的第2验证模块。这2个模块在做mmap映射的时候,都指向了dummy_file_mmap_addr这个函数:
usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/security/dummy.c:

static int dummy_file_mmap_addr (struct file *file, unsigned long reqprot,
unsigned long prot,
unsigned long flags,
unsigned long addr,
unsigned long addr_only)
{
if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
return -EACCES;
return 0;
}
mmap_min_addr代表了用户能映射的最小内存地址, 它在/proc/sys/vm/mmap_min_addr进行设置。这里还要对当前进程的CAP_SYS_RAWIO能力做个判断, 就是说如果进程有这个能力的话, 不管mmap_min_addr的值是多大,都可以满足用户的需求, 当然就可以映射0地址了。 那么这跟selinux有什么关系呢?  进程在被执行的时候,尤其是调用了execve这个函数, 进程的权能是需要重新来计算的,在selinux开启的时候, selinux是LSM的第一验证模块, 看下它是怎么计算进程在被execve后的权能的:
void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
{
/* Derived from fs/exec.c:compute_creds. */
kernel_cap_t new_permitted, working;

new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
working = cap_intersect (bprm->cap_inheritable,
current->cap_inheritable);
new_permitted = cap_combine (new_permitted, working);

if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
!cap_issubset (new_permitted, current->cap_permitted)) {
current->mm->dumpable = suid_dumpable;

if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
if (!capable(CAP_SETUID)) {
bprm->e_uid = current->uid;
bprm->e_gid = current->gid;
}
if (!capable (CAP_SETPCAP)) {
new_permitted = cap_intersect (new_permitted,
current->cap_permitted);
}
}
}

current->suid = current->euid = current->fsuid = bprm->e_uid;
current->sgid = current->egid = current->fsgid = bprm->e_gid;

/* For init, we want to retain the capabilities set
* in the init_task struct. Thus we skip the usual
* capability rules */
if (current->pid != 1) {
current->cap_permitted = new_permitted;
current->cap_effective =
cap_intersect (new_permitted, bprm->cap_effective);
}

/* AUD: Audit candidate if current->cap_effective is set */

current->keep_capabilities = 0;
}
我们看到如果当前进程不是init进程的话, 权能还是会被继承下来的。

在selinux关闭的时候, capabiliy模块成为了LSM的第一验证模块, 看下它是怎么计算的:
static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
{
if (bprm->e_uid != current->uid || bprm->e_gid != current->gid) {
current->mm->dumpable = suid_dumpable;

if ((unsafe & ~LSM_UNSAFE_PTRACE_CAP) && !capable(CAP_SETUID)) {
bprm->e_uid = current->uid;
bprm->e_gid = current->gid;
}
}

current->suid = current->euid = current->fsuid = bprm->e_uid;
current->sgid = current->egid = current->fsgid = bprm->e_gid;

dummy_capget(current, &current->cap_effective, &current->cap_inheritable, &current->cap_permitted);
}

static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
kernel_cap_t * inheritable, kernel_cap_t * permitted)
{
*effective = *inheritable = *permitted = 0;
if (!issecure(SECURE_NOROOT)) {
if (target->euid == 0) {
*permitted |= (~0 & ~CAP_FS_MASK);
*effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
}
if (target->fsuid == 0) {
*permitted |= CAP_FS_MASK;
*effective |= CAP_FS_MASK;
}
}
return 0;
}
注意看这行:
*effective = *inheritable = *permitted = 0;
selinux将当前进程的权能全部清0了, 所以excve后的普通进程是没有任何权能的。 也就没有了CAP_SYS_RAWIO权能,也就不能映射0内存了。 所以想阻止NULL pointer kernel 0day的攻击,最好把selinux关掉,或升级到最新的内核版本。 同时把mmap_min_addr的值设为大于4096。

selinux与kernel 0day的更多相关文章

  1. SELinux深入理解

    ps:今天在远程给服务器配置https的时候,一直乱码,以前做系统的系统第一件事情,就是关闭selinx,今天忘记了,然后就悲剧了... 弄了半天才弄好,镇定思痛,好好的来看下selinux 1. 简 ...

  2. 深入理解SELinux

      目录(?)[+]   1. 简介 SELinux带给Linux的主要价值是:提供了一个灵活的,可配置的MAC机制. Security-Enhanced Linux (SELinux)由以下两部分组 ...

  3. SElinux解决web网站无法访问

    SElinux解决web网站无法访问工具/原料centos 6.5系统httpd web服务器 SELinux 设置为enforcing:强制模式,代表 SELinux 运作中 方法/步骤1. 1se ...

  4. SELINUX工作原理

    SELinux工作原理 1. 简介 SELinux带给Linux的主要价值是:提供了一个灵活的,可配置的MAC机制. Security-Enhanced Linux (SELinux)由以下两部分组成 ...

  5. selinux权限问题【转】

    本文转载自:https://blog.csdn.net/u011386173/article/details/83339770 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  6. SELinux简介

    Security-Enhanced Linux (SELinux)由以下两部分组成: 1) Kernel SELinux模块(/kernel/security/selinux) 2) 用户态工具 SE ...

  7. 零基础学习云计算及大数据DBA集群架构师【Linux系统配置及网络配置2015年12月30日周三】

    /Mon *************摘要************** 计划任务 )一次性计划任务 服务:atd 命令:at 服务存放文件:/etc/init.d/atd 系统配置文件:/etc/at. ...

  8. Linux进程管理(3):总结

    7. exit与_exit的差异    为了理解这两个系统调用的差异,先来讨论文件内存缓存区的问题. 在linux中,标准输入输出(I/O)函数都是作为文件来处理.对应于打开的每个文件,在内存中都有对 ...

  9. ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728)

    ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728) By Perception Point Resear ...

随机推荐

  1. C++中函数调用操作符的重载

    1,本博文讲述函数对象问题: 2,客户需求: 1,编写一个函数: 1,函数可以获得斐波那契数列每项的值: 2,每调用一次返回一个值: 3,函数可根据需要重复使用: 4,代码示例: ; i<; i ...

  2. min-element & max_element

    C++ STL之min_element()与max_element()(取容器中的最大最小值) min_element()和max_element 头文件:#include<algorithm& ...

  3. Head First Java 读书笔记(完整)

    第0章:学习方法建议 该如何学习Java? 1.慢慢来.理解的越多,就越不需要死记硬背.时常停下来思考. 2.勤作笔记,勤做习题. 3.动手编写程序并执行,把代码改到出错为止. 需要哪些环境和工具? ...

  4. 页面跳转到Area区域连接

    @Html.ActionLink("主页", "Index", new { controller = "Test", Action = &q ...

  5. ingress-nginx配置https文件访问

    1.先将证书文件上传至服务器特定目录.比如:/root/ssl 假设证书名称为:server.crt和server.key 2.现在主节点后台创建私密文件. kubectl create secret ...

  6. 小程序中使用async函数 会报 regeneratorRuntime is not defined的问题

    async await比Promise更好的解决异步操作问题,但是在小程序中直接使用会出现以下的错误提示 是因为缺少了regeneratorRuntime这个模块,需要从外部引入 1.在新建的文件夹中 ...

  7. Es学习第四课, 倒排索引

    大家知道,ES的发明者初衷是想做一个搜索引擎给自己老婆用来搜菜谱,所以ES的核心工作就是做搜索,下面我们就开始讲关于搜索方面的知识点. DOC的概念我们第一课就讲过,它是ES存储数据的最小单元,我们再 ...

  8. C语言——enum

    #include<stdio.h> enum Season { spring, summer=100, fall=96, winter }; typedef enum { Monday, ...

  9. leetcode-165周赛-1275-找出井字棋的获胜者

    题目描述: 自己的提交: class Solution: def tictactoe(self, moves: List[List[int]]) -> str: p = [[0] * 3 for ...

  10. ALAsset和ALAssetRepresentation详解

    ALAsset类代表相册中的每个资源文件,可以通过它获取资源文件的相关信息还能修改和新建资源文件,ALAssetRepresentation类代表相册中每个资源文件的详细信息,可以通过它获取资源的大小 ...