MIPS 安全相关paper阅读笔记

前言

论文来自

https://cyber-itl.org/2018/12/07/a-look-at-home-routers-and-linux-mips.html

Linux_MIPS_missing_foundations

这篇论文主要讨论了 MIPS 架构下的 Linux 实现 DEP 的时间线。

Linux 在 16年才通过软件实现了 不可执行栈的特性。所以在此之前的 mips 下的程序的栈其实都是可以执行的。

但是由于要模拟 mips 下的 浮点数计算,所以在实现栈不可执行的情况下,需要 mmap 一块 rwx 的内存用来模拟浮点数计算。但是这块 rwx 的内存的地址实际上是固定的。

32位进程: 0x7ffff000
64位进程: 0xfffffff000

32位进程

一份测试代码(用 clang 编译)

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <unistd.h>
int main(void) {
    // set a pointer to the vfpu emulation page address 
    void* p = (void *)0x7ffff000; printf("%p
", (void*)p);
    // construct a function pointer from p 
    void (*func_ptr)(void) = p;
    // 'jr $ra' mips32el instruction bytes 
    char code[] = {0x08, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00};
    // copy the instruction to the vfpu page 
    memcpy(p, code, 8);
    // call the function pointer, this should then directly return back 
    (*func_ptr)();
    // print out the current maps of the process 
    char cmd[200];
    sprintf(cmd, "cat /proc/%d/maps", getpid()); system(cmd);
    return 0; 
}

编译运行环境

mipsel Debian 9.4

运行结果

原文地址:https://www.cnblogs.com/hac425/p/10131350.html