Root Has Segfault Executing RDMSR Assembly Code

五迷三道 提交于 2020-06-18 12:12:28

问题


I would like to read msr 0x19a (IA32_CLOCK_MODULATIOn) directly from C code WITH root privilege. However, I get the following segfault error.

a.out[27843] general protection ip:40053b sp:7fffefc38020 error:0 in a.out[400000+1000]

Does anyone know whether this way of calling rdmsr is a viable option?

Thanks in advance!

#include <stdio.h>
#define __init

typedef unsigned uint32_t;
static int __init test3_init(void)
{
     uint32_t hi,lo;
     hi=0x0; lo=0x0;
     asm volatile("mov $0x19a,%ecx");
     asm volatile("rdmsr":"=a"(lo),"=d"(hi));
     printf("exit_readmsr: hi=%08x lo=%08x\n",hi,lo);
     return 0;
 }

 int main(void)
 {                                          
      return test3_init();                      
 }

BTW, the code is extract from this answer.


回答1:


This instruction must be executed at privilege level 0. In other words, you must be inside the kernel.



来源:https://stackoverflow.com/questions/26331730/root-has-segfault-executing-rdmsr-assembly-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!