- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的印象是,Linux 内核保护自身的尝试围绕着不让恶意代码在内核空间中运行。特别是,如果加载了恶意内核模块,从安全角度来看,它将“游戏结束”。然而,我最近遇到了a post这与这种信念相矛盾,并表示内核可以通过某种方式保护自身的某些部分免受自身其他部分的影响:
There is plenty of mechanisms to protect you against malicious modules. I write kernel code for fun so I have some experience in the field; it's basically a flag in the pagetable.
What's there to stop any kernel module from changing that flag in the pagetable back? The only protection against malicious modules is keeping them from loading at all. Once one loads, it's game over.
Make the pagetable readonly. Done.
Kernel modules can just make it read-write again, the same way your code made it read-only, then carry on with their changes.
You can actually lock this down so that kernel mode cannot modify the page table until an interrupt occurs. If your IDT is read-only as well there is no way for the module to do anything about it.
这对我来说没有任何意义。我错过了关于内核内存如何工作的重要信息吗?内核空间代码可以限制自己修改页表吗?这真的能防止内核 rootkit 吗?如果是这样,那么为什么 Linux 内核今天不这样做以结束所有内核 rootkit?
最佳答案
如果恶意内核代码以受信任的方式加载(例如加载内核模块而不是利用漏洞),则否:内核代码就是内核代码。
Intel CPU 确实有一系列机制来禁用对内核内存的读/写访问:
CR0.WP
如果设置为不允许对用户和内核只读页面进行写访问。用于检测内核代码中的错误。CR4.PKE
如果设置(必须启用 4 级分页,在 64 位模式下是强制的)不允许内核访问(不包括取指令)用户页面模式,除非这些被标记使用正确的 key (标记其 RW 权限)。用于允许内核写入 VSDO 和 KUSER_SHARED_DATA
等结构,但不允许写入其他用户模式结构。 key 权限在 MSR 中,而不是在内存中;键本身在页表条目中。CR4.SMEP
如果设置为不允许从用户模式页面获取内核指令。用于防止将内核函数指针重定向到用户模式分配页面的攻击(例如 nelson.c
特权升级漏洞利用)。CR4.SMAP
如果设置为在隐式 访问或任何类型(隐式或显式)访问期间不允许内核访问用户模式页面(如果 EFLAGS. AC=0
,从而覆盖保护 key )。用于执行更严格的无用户模式访问政策。R/W
和 U/S
位控制项目是只读/读写还是分配给用户或内核.您可以在 Intel 手册中阅读如何为 supervisor-mode access 应用权限:
Data writes to supervisor-mode addresses.
Access rights depend on the value of CR0.WP:
- If CR0.WP = 0, data may be written to any supervisor-mode address.
- If CR0.WP = 1, data may be written to any supervisor-mode address with a translation for which the R/W flag (bit 1) is 1 in every paging-structure entry controlling the translation; data may not be written to any supervisor-mode address with a translation for which the R/W flag is 0 in any paging-structure entry controlling the translation.
因此,即使内核将页面 X
保护为只读,然后将页面结构本身保护为只读,恶意模块也可以简单地清除 CR0.WP
.
它还可以更改 CR3
并使用自己的分页结构。
请注意,英特尔开发了 SGX 来解决内核本身是邪恶的威胁模型。
然而,以安全的方式(即没有单点故障)将内核组件运行到 enclaves 中可能并非易事。
另一种方法是使用 VMX 扩展对内核进行虚拟化,尽管实现起来绝非易事。
最后,CPU在segmentation层有四个保护级别,而paging只有两个:supervisor(CPL = 0)和user(CPL > 0)。
理论上可以在“Ring 1”中运行内核组件,但随后您需要创建一个接口(interface)(例如调用门或 syscall
之类的东西)才能访问其他内核函数。
完全在用户模式下运行它更容易(因为您首先不信任该模块)。
我不知道这是什么意思:
You can actually lock this down so that kernel mode cannot modify the page table until an interrupt occurs.
我不记得中断处理将锁定/解锁任何东西的任何机制。不过我很好奇,如果有人可以提供一些信息,欢迎他们。
x86 CPU 中的安全性(但这可能是普遍的)一直等级:先来的人为后来的人设置约束。
在同一层级的非隔离组件之间通常几乎没有保护。
关于security - 内核代码能否以其他内核代码无法撤消的方式将内容设置为只读?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61397730/
我在不同的硬件上测试 Cassandra 已经有一段时间了。 首先我有 2 个 CPU 和 6 GB RAM 然后我更改为 16 个 CPU 和 16 GB RAM(其中只有 6 GB 可供我的测试使
我只是想从二进制文件中读/写。我一直在关注 this教程,它的工作原理......除了它似乎正在将内容写入 txt 文件。我在测试的时候把文件命名为test.bin,但是记事本可以打开并正常显示,所以
我编写了一些简单的 Java 代码来从文本文件中读取字符串,将它们组合起来,然后将它们写回。 (有关输出没有变化的简化版本,请参见下面的片段) 问题是输入文件和输出文件中的特定字符(- 和 ...)是
我真的很感兴趣——你为什么要放 readln; 从键盘读取一些值到变量后的行?例如, repeat writeln('Make your choise'); read(CH); if (CH = '1
只要程序不允许同时写入存储在模块中的共享数据结构的相同元素,它是线程安全的吗?我知道这是一个菜鸟问题,但在任何地方都找不到明确解决的问题。情况如下: 在程序开始时,数据被初始化并存储在模块级可分配数组
我有一个数据结构,其操作可以归类为读取操作(例如查找)和写入操作(例如插入、删除)。这些操作应该同步,以便: 读操作不能在写操作执行时执行(除非在同一线程上),但是读操作可以与其他读操作并发执行。 在
我在Java套接字编程中有几个问题。 在读取客户端套接字中的输入流时,如果抛出IO异常;那么我们是否需要重新连接服务器套接字/再次初始化客户端套接字? 如果我们关闭输出流,它将关闭客户端套接字吗? 如
我正在尝试从客户端将结构写入带有套接字的服务器。 结构是: typedef struct R { int a; int b; double c; double d; double result[4];
我想知道是否可以通过 Javascript 从/向 Azure Active Directory 广告读取/写入数据。我读到 Azure 上有 REST 服务,但主要问题是生成与之通信的 token
我希望有人能提供完整的工作代码,允许在 Haskell 中执行以下操作: Read a very large sequence (more than 1 billion elements) of 32
我有一个任务是制作考试模拟器。我的意思是,在老师输入某些科目的分数后,学生输入他的名字、姓氏和出生,然后他决定学生是否通过科目。所以,我有一个问题,如何用新行写入文件文本并通过重写该文件来读取(逐行读
我需要编写巨大的文件(超过 100 万行)并将文件发送到另一台机器,我需要使用 Java BufferedReader 一次读取一行。 我使用的是 indetned Json 格式,但结果不太方便,
我在 Android 应用程序中有一个读写操作。在 onCreate 上,将读取文件并将其显示为编辑文本并且可以进行编辑。当按下保存按钮时,数据将被写入 onCreate 上读取的同一文件中。但我得到
我正在编写一个程序,该程序从一个文件读取输入,然后该程序将格式化数据并将其写入另一个文件。 输入文件: Christopher kardaras,10 N Brainard,Naperville,IL
我有一个 SCALA(+ JAVA) 代码,它以一定的速率读写。分析可以告诉我代码中每个方法的执行时间。如何衡量我的程序是否达到了最大效率?为了使我的代码优化,以便它以给定配置可能的最大速度读取。我知
嗨,我想知道如何访问 java/maven 中项目文件夹中的文件,我考虑过使用 src/main/resources,但有人告诉我,写入此目录中的文件是一个坏主意,并且应该只在项目的配置中使用,所以我
我想读\写一个具有以下结构的二进制文件: 该文件由“RECORDS”组成。每个“RECORD”具有以下结构:我将以第一条记录为例 (红色)起始字节:0x5A(始终为 1 字节,固定值 0x5A) (绿
我想制作一个C程序,它将用一些参数来调用;每个参数将代表一个文件名,我想在每个参数中写一些东西。 FILE * h0; h0 = fopen(argv[0],"w"); char buff
我有一个包含团队详细信息的文件。我需要代码来读取文件,并将获胜百分比写入第二个文件。我还需要使用指示的搜索功能来搜索团队的具体信息。该代码未写入百分比文件。当菜单显示时,第一个文件的内容被打印,但代码
我正在使用 read() 和 write() 函数来处理我的类,并且我正在尝试使用一个函数来写入它所读取的内容以及我作为参数给出的前面的内容。 例如,我想给出 10 作为我的程序的参数 int mai
我是一名优秀的程序员,十分优秀!