Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to write in /dev/mem

The issue that I am experimenting is not related with open() or mmap() function, which are executed properly. I have disabled CONFIG_STRICT_DEVMEM in the kernel so I can read from /dev/mem without problems. Actually, I can do the following:

const char *path = "/dev/mem"
int fd = open(path, O_RDWR); /* read and write flags*/
p  = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE_ADDR); /* read and write flags*/

And the code does not fail. Nonetheless, I am using this code to write in the PCI address space. So, basically the BASE_ADDR is 0xc000000, and the size is 256 MiB (0x10000000, all the PCI address space).

Said that, when I try to write on these positions (with a specific offset, BDF format), nothing is written; again the code does not fail, it just does not write anything.

In case my code was wrong, I tried BusyBox, with the following parameters:

[horro@ ~]$ sudo busybox devmem 0xc00b0a8c w 0xffffffff
[horro@ ~]$ sudo busybox devmem 0xc00b0a8c             
0x00000000

So, basically it is not writing anything.

like image 523
horro Avatar asked Jan 29 '26 20:01

horro


1 Answers

There is a CONFIG_STRICT_DEVMEM kernel config option. My understanding is that it must be set at compile-time as CONFIG_STRICT_DEVMEM=n. This is a security reasons.

like image 98
Dsrivast Avatar answered Feb 01 '26 09:02

Dsrivast



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!