免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3589 | 回复: 9
打印 上一主题 下一主题

ulk3关于中断门、异常门的dpl字段疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-07 20:46 |只看该作者 |倒序浏览
ulk讲:linux用dpl=0的陷阱门实现了大多数的异常处理。并且说了dpl=0的意思是不能被用户态访问。那么不是矛盾了么?用户态还怎么访问异常处理呢?

ulk又讲到中断异常处理的硬件过程:
在验证中断是否授权时,如果是编程异常(比如int指令,但是一般的异常处理应该不是)则要拿idt的dpl和当前的cpl进行比较,如果cpl=3,而dpl=0则产生一个generation protection异常。防止用户态通过int 0x1之类的指令访问非授权的中断描述符。这里对于普通的异常处理好像没有进行dpl的检测,刚好回答了上面的疑问。

总之,好像有点自相矛盾了。我的理解是下面一种才是正确的。上面说的dpl=0就是不能被用户态访问这句话是错误的。还请高手们指点。。。

论坛徽章:
0
2 [报告]
发表于 2011-11-08 10:35 |只看该作者
ulk讲:linux用dpl=0的陷阱门实现了大多数的异常处理。并且说了dpl=0的意思是不能被用户态访问。那么不是矛盾了么?用户态还怎么访问异常处理呢?


用户需要访问使用System Gate(DPL=3)实现的系统调用即可:int 0x80;用户为什么要处理Trap Gate呢?

For programmed exceptions, makes a further security check:


我想,这个further不用多说了吧;

个人理解,ULK3里面说的previlidge check有两步:
1.
Makes sure the interrupt was issued by an authorized source. First, it compares the Current Privilege Level (CPL), which is stored in the two least significant bits of the cs register, with the Descriptor Privilege Level (DPL ) of the Segment Descriptor included in the GDT. Raises a "General protection " exception if the CPL is lower than the DPL, because the interrupt handler cannot have a lower privilege than the program that caused the interrupt.


保证中断处理程序的权限大于产生中断的程序的权限,禁止中断调用用户程序,防止恶意用户程序,而又不妨碍用户态和内核态产生中断;

2.
For programmed exceptions, makes a further security check: compares the CPL with the DPL of the gate descriptor included in the IDT and raises a "General protection" exception if the DPL is lower than the CPL. This last check makes it possible to prevent access by user applications to specific trap or interrupt gates.


针对编程异常,执行进一步检查,防止用户态程序调用不该他产生的异常;
From Intel Manual volume 3a-3b: 6.12.1.1 Protection of Exception- and Interrupt-Handler Procedures
The processor checks the DPL of the interrupt or trap gate only if an exception or
interrupt is generated with an INT n, INT 3, or INTO instruction. Here, the CPL
must be less than or equal to the DPL of the gate. This restriction prevents
application programs or procedures running at privilege level 3 from using a
software interrupt to access critical exception handlers, such as the page-fault
handler, providing that those handlers are placed in more privileged code
segments (numerically lower privilege level). For hardware-generated interrupts
and processor-detected exceptions, the processor ignores the DPL of interrupt
and trap gates.

论坛徽章:
0
3 [报告]
发表于 2011-11-08 11:26 |只看该作者
本帖最后由 ruslin 于 2011-11-08 11:32 编辑

回复 2# wangjianchangdx


    ulk3有一个概念:dpl=0的idt用户态不能访问。我的问题就是对这句话的正确性怀疑。


   比如在用户态 执行 100 / 0 导致的除0异常,相应的idt是dpl=0的intel陷阱门。然后ulk3说,用户态不能访问dpl=0的intel陷阱门。既然不能访问,那么这个异常怎么处理呢,现在就是在用户态啊?

    后来在中断异常硬件处理过程中的解释,对于普通的异常,并没有检测idt的dpl和当前cpl(只有编程异常比如int指令才会进一步检测)。通过这里的解释可以猜测,dpl=0的idt用户态不能访问时错误的结论。

    不过不知道是不是翻译的问题。我看的中文版。

论坛徽章:
0
4 [报告]
发表于 2011-11-08 11:30 |只看该作者
另外,突然想起一个问题,就是说ulk说了,在内核态正常情况下只会发生缺页异常。
然后我考虑了一下,突然不能想起来在内核态能发生缺页异常的case。内核访问的地址都是分配过的,比如alloc_page,kmalloc,vmlloac,但是这些函数调用时就已经像伙伴系统分配了物理内存建好了页表,何来发生缺页异常呢。
还请指教了。。。

论坛徽章:
0
5 [报告]
发表于 2011-11-08 12:40 |只看该作者
回复 3# ruslin

ULK3描述确有不妥,应该是不能通过软中断指令蓄意触发:

The processor checks the DPL of the interrupt or trap gate only if an exception or
interrupt is generated with an INT n, INT 3, or INTO instruction.

论坛徽章:
0
6 [报告]
发表于 2011-11-08 12:44 |只看该作者
回复 4# ruslin

已分配的页可以被换出,参见ULK3 CHAP15.

论坛徽章:
0
7 [报告]
发表于 2011-11-08 12:57 |只看该作者
回复 6# wangjianchangdx


    对了,想起来咯。谢谢

论坛徽章:
0
8 [报告]
发表于 2011-11-09 23:26 |只看该作者
在中断的时候会有特权级变化的啊

论坛徽章:
0
9 [报告]
发表于 2011-11-09 23:28 |只看该作者
中断结束 特权级会再切换回来的 这些都是保护模式的内容 你好好看看保护模式

论坛徽章:
0
10 [报告]
发表于 2011-11-10 16:00 |只看该作者
回复 9# LZ杀手


    这个谁不知道,仔细一点看书可能你就会有疑问了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP