从用户空间读取/dev/cpu/*/msr:不允许操作 [英] Reading /dev/cpu/*/msr from userspace: operation not permitted
问题描述
我正在尝试编写一个可以读取msr寄存器的简单应用程序,并正在从用户空间运行此应用程序.
I am trying to write a simple application that can read msr registers, and am running this application from userspace.
我已经加载了msr模块,并向每个人授予了对/dev/cpu/*/msr的读取权限.但是仍然用户无法访问这些文件,但root可以.
I have loaded the msr module and given read permissions for everyone to /dev/cpu/*/msr. But still the user is not able to access these files but the root can.
权限如下:
crw-r--r-- 1 root root 202, 0 sep 6 17:55 /dev/cpu/0/msr
crw-r--r-- 1 root root 202, 1 sep 6 17:55 /dev/cpu/1/msr
crw-r--r-- 1 root root 202, 2 sep 6 17:55 /dev/cpu/2/msr
crw-r--r-- 1 root root 202, 3 sep 6 17:55 /dev/cpu/3/msr
当我尝试从用户空间读取这些文件时,我一直收到不允许操作"错误消息,但是当root试图访问它们时,它仍然可以正常工作.我究竟做错了什么?我在内核版本为3.11.0的Ubuntu 13.04上.
I keep getting "Operation not permitted" error message when I try to read these files from userspace but works fine when root tries to access them. What am I doing wrong? I am on Ubuntu 13.04 with kernel version 3.11.0.
推荐答案
Linux主流版本中的更改(自3.7版本开始)要求可执行文件具有CAP_SYS_RAWIO功能,以打开MSR设备文件[2].除了加载MSR内核模块并在msr设备文件上设置适当的文件许可权外,还必须使用以下命令将CAP_SYS_RAWIO功能授予需要访问MSR驱动程序的任何用户可执行文件:
Changes in the mainline Linux kernel since around 3.7 now require an executable to have capability CAP_SYS_RAWIO to open the MSR device file [2]. Besides loading the MSR kernel module and setting the appropriate file permissions on the msr device file, one must grant the CAP_SYS_RAWIO capability to any user executable that needs access to the MSR driver, using the command below:
sudo setcap cap_sys_rawio=ep <user_executable>
这篇关于从用户空间读取/dev/cpu/*/msr:不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!