从用户模式进入ring 0
大多数现代操作系统都在保护模式下运行。现在用户程序是否可以通过直接设置一些控制寄存器中的相应位来进入“环0”?或者它是否必须经过一些系统调用。
我相信要访问硬件我们需要通过操作系统。但是,如果我们知道硬件设备的地址,我们就可以根据设备的位置编写一些汇编语言代码并访问它。当我们在汇编语言代码中给出某些硬件设备的地址时会发生什么。
谢谢。
Most modern operating systems run in the protected mode. Now is it possible for the user programs to enter the "ring 0" by directly setting the corresponding bits in some control registers. Or does it have to go through some syscall.
I believe to access the hardware we need to go through the operating system. But if we know the address of the hardware device can we just write some assembly language code with reference to the location of the device and access it. What happens when we give the address of some hardware device in the assembly language code.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要进入 Ring 0,您必须执行系统调用,从本质上讲,系统控制您的去向,因为对于调用,您只需向 CPU 提供一个索引,CPU 会查看表内部以了解要调用什么。您无法真正绕过安全方面(显然)去做其他事情,但也许这个链接会有帮助。
To enter Ring 0, you must perform a system call, and by its nature, the system controls where you go, because for the call you simply give an index to the CPU, and the CPU looks inside a table to know what to call. You can't really get around the security aspect (obviously) to do something else, but maybe this link will help.
你可以要求操作系统将硬件设备的内存映射到你的程序的内存空间中。完成后,您就可以从环 3 读取和写入该内存。是否可以执行此操作或如何执行此操作取决于操作系统或设备。
You can ask the operating system to map the memory of the hardware device into the memory space of your program. Once that's done, you can just read and write that memory from ring 3. Whether that's possible to do, or how to do that, depends on the operating system or the device.
摘自维基百科。
基本思想是将cr0控制寄存器中的0th位设置为1。
但是,如果您已经处于保护模式(即您在 Windows/Linux 中),安全性会限制您执行此操作(您处于环 3 - 最低信任度)。
因此,成为第一个进入保护模式的人。
Taken from Wikipedia.
Basic idea is to set (to 1) 0th bit in cr0 control register.
But if you are already in protected mode (i.e. you are in windows/linux), security restricts you to do it (you are in ring 3 - lowest trust).
So be the first one to get into protected mode.