/dev/mem 权限问题
普通用户可以打开/dev/mem并mmap吗?
网上看了一些朋友的文章,他们通过修改内核能够实现,大致的做法是修改内核:
Processor type and features --> []X86 PAT support
kernel hacking --> []Filter access to /dev/mem
编译安装内核后,重启,使用普通用户登录,终端使用超级用户修改了/dev/mem的权限后,执行测试代码
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
void main()
{
int fd;
void * mmp=NULL;
fd = open("/dev/mem",O_RDONLY);
if(fd == -1)
{
perror("open device");
return;
}
mmp=mmap(0,100,PROT_READ,MAP_SHARED,fd,0);
if(mmp ==(void *) -1)
perror("mmap");
else
printf("mmap info=%s\n",(char *)mmp);
close(fd);
}
提示open device:operation not permitted
如何解决?
没有分了,请客好了