我正在尝试编写一个简单的应用程序,可以读取msr寄存器,并从用户空间运行此应用程序。
我已经加载了msr模块,并为每个人提供了对/dev/cpu/*/msr的读取权限。但是用户仍然不能访问这些文件,但是根用户可以。
权限如下所示:
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。
发布于 2013-09-20 04:02:45
主线Linux内核从3.7开始的变化现在要求可执行文件具有打开MSR设备文件的功能CAP_SYS_RAWIO 2。除了加载MSR内核模块和设置msr设备文件上的适当文件权限外,还必须使用以下命令将CAP_SYS_RAWIO能力授予需要访问MSR驱动程序的任何用户可执行文件:
sudo setcap cap_sys_rawio=ep <user_executable>发布于 2021-03-27 05:26:59
对于我(在debian上)来说,它有助于在加载msr模块后设置设备权限。在PaulUTK的答案中添加,作为根用户:
setcap cap_sys_rawio=ep <user_executable>设置设备权限(检查前):
ls -l /dev/cpu/*/msr
crw------- ... /dev/cpu/0/msr我添加了一个组msr并对其进行了分配。以root用户身份:
chgrp msr /dev/cpu/*/msr
chmod g+rw /dev/cpu/*/msr
ls -l /dev/cpu/*/msr
crw-rw---- ... /dev/cpu/0/msr将组分配给用户:
usermod -aG msr hardworkinguser奖励提示:
在无需重新登录的情况下将组应用为hardworkinguser:
newgrp msr我还听说必须禁用安全引导。
发布于 2017-06-28 14:00:10
你可以看到vfs_read:
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ret = rw_verify_area(READ, file, pos, count);
if (ret >= 0) {
...
if (file->f_op->read) // your driver read .
ret = file->f_op->read(file, buf, count, pos);
else
ret = do_sync_read(file, buf, count, pos);
....
}
// here, if the ret is 13. your error will be occur.
return ret;
}https://stackoverflow.com/questions/18661976
复制相似问题