简体   繁体   中英

open /dev/mem - Operation not permitted

I am working on ubuntu.

I am trying to open /dev/mem and i am getting permission denied

int32_t open_memdev()
{
        int32_t fd;

        fd = open("/dev/mem", O_RDONLY);
        if (fd < 0) {
                printf("Failed to open /dev/mem : %s\n", strerror(errno));
                return-EINVAL;
        }

        return fd;
}

This code always prints "Failed to open /dev/mem : Operation not permitted"

I have searched for this on SO

  1. access-permissions-of-dev-mem

  2. accessing-mmaped-dev-mem

These q's seem to discuss the issue of not being able to access above 1 MB, but my problem is that i am unable to open even once.

Addtitional details if they help:

1) I checked my configuration that CONFIG_STRICT_DEVMEM is enabled.

2) ls -l /dev/mem
crw-r----- 1 root kmem 1, 1 2014-03-13 13:57 /dev/mem

Please let me know if additional information is required.

You cannot read /dev/mem if you are not root .

There is no reason for an ordinary application to access /dev/mem , ie the physical RAM, since applications are running in virtual memory !

If you change the permission of /dev/mem to enable that (you should not), you will open a huge security hole in your system. Only trusted root processes should access /dev/mem . See mem(4)

(you could use setuid techniques if so wanted, or run your program with sudo )

If you need to access virtual memory in the address space of some other process , consider proc(5) eg /proc/1234/mem for process of pid 1234.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM