c - SIDT 操作码返回地址到格式错误的 IDT 结构

标签 c macos assembly virtualization xnu

我的目标是从 MacOS 内核模块访问 IDT。

我在 VMFusion 10.0.1 下运行 macOS 10.13.2,似乎 sidt 汇编命令指向损坏的表结构。

此操作码应将地址返回到“中断描述符表”,其中包含每个中断的描述符。

每个中断都包含回调函数的指针,在调用特定中断时应调用该回调函数。

例如,这里有 2 个中断描述符指向来自先前旧版本内核 __TEXT 部分的有效回调。

  • int3 指向 idt64_int3
  • int80 指向 idt64_unix_scall

等...

出于某种原因,从 high Sierra 10.13.2 开始,sidt 返回不包含有效指针的内存范围(全部在内核 __TEXT 的边界之外) > 节)。也许还有另一种获取表指针的方法?

这是我寻找 idt 指针的源代码:

unsigned char idt_out[10];
__asm__ volatile ("sidt %0": "=m" (idt_out));

// skip the first 2 bytes as they are not part of the address
uint64_t idt_address = *((unsigned long long *)(idt_out+2));
printf("idt address is %llx \n",  idt_address);

int80_desc = (struct descriptor_idt*)(idt_address + sizeof(struct idt_desc)*0x80);
int80_address = (mach_vm_address_t)(((unsigned long)int80_desc->offset_high << 32) + ((unsigned int)int80_desc->offset_middle << 16) + int80_descriptor->offset_low); // this should point to idt64_unix_scall

最佳答案

显然,sidt 停止工作的原因是故意的,并且是 Meltdown 修复的一部分。

目前我所了解的就这些,如果有哪位 friend 有更多的推理线索,请赐教。

关于c - SIDT 操作码返回地址到格式错误的 IDT 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47910789/

相关文章:

在 GNU 汇编中使用重复 block 或宏调用函数表

assembly - 如何使用 SSE 计算模数/余数?

c - 取消引用指向 pcap_t 结构的不完整类型的指针

c - 如何使用c中的指针指向总行或总列

c - 为什么输入缓冲区中只有一个(二分之一)空格被视为字符?

c - 在循环中使用 scanf() 扫描 CSV 文件在第一行和第二行开始后停止

c++ - 如何在基于 C++/QT 的安装程序中检测互联网断开连接

java - 使用 Java 打开 Photoshop 等应用程序

macos - 我可以更改 NSBundle 文件夹中的 plist 文件吗?

c - 通过内联汇编操作 c 变量