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. BZOJ 4765(分块+树状数组)

    题面 传送门 "奋战三星期,造台计算机".小G响应号召,花了三小时造了台普通计算姬.普通计算姬比普通计算机要厉害一些 .普通计算机能计算数列区间和,而普通计算姬能计算树中子树和.更 ...

  2. Linux中通过grep命令检索文件内容和指定内容前后几行

    原文链接: https://www.linuxidc.com/Linux/2017-11/148390.htm Linux系统中搜索.查找文件中的内容,一般最常用的是grep命令,另外还有egrep命 ...

  3. 2019-4-8 zookeeper集群介绍学习笔记2

    构建高可用ZooKeeper集群原理介绍 ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/ ...

  4. Echart报 [MODULE_MISS]"echarts/config的错

    echarts插件的引入有两种方式 项目用到Echarts插件,时下比较流行的是模块化包引入,但是很悲催的是楼主用的是标签式引入,所以从官网copy来的代码总是报一个 [MODULE_MISS]&qu ...

  5. js高级编程思想

    js惰性思想: 能够执行一次就搞定绝对不会执行第二次 function createXHR(){ var xhr=null, falg=false, ary=[ function(){ return ...

  6. .net Core在过滤器中获取 系统接口方法(以IMemoryCache 为例) 及HttpContext 获取系统接口

    public   Class  SysActionAttribute :Attribute, IActionFilter      //  Attribute  用于控制器中 特性控制,当在控制器或控 ...

  7. Video Mode Timings

    A monitor draws an image on the screen by using an electron beam (3 electron beams for color models, ...

  8. Git--将已有的项目添加到github(转)

    转自:https://blog.csdn.net/north1989/article/details/53471439 1. 目标: 把本地已经存在的项目,推送到github服务端,实现共享. 2. ...

  9. zabbix自带database monitor

    1. 在zabbix服务器上安装一下两个包: # yum -y install unixODBC mysql-connector-odbc 2. 修改zabbix服务器上ODBC配置: 2.1 Vim ...

  10. mybatis generator 使用方法

    环境: ubuntu   eclipse maven 一. 简介 mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,快速生成mapper和xml文件以及pojo 二. ...