open /dev/mem fail even with root and without SELINUX

Viewed 129

Just show my code.

root@MSI:/tmp# cat main.c 
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
    int fd = open("/dev/mem", O_RDONLY);
    printf("Result: %d\n", fd);
    if (fd != -1) {
        close(fd);
    } else {
        perror("Failed:");
    }
}
root@MSI:/tmp# gcc main.c 
root@MSI:/tmp# ./a.out 
Result: -1
Failed:: Operation not permitted

Root, without SELINUX, /dev/mem with crw-r----- permission, but open failed. kernel version 5.4.0-49-generic #53-Ubuntu.

0 Answers
Related