Skip to content

Cannot get I/O access to '/dev/mem' #855

Description

Hello. My attempt to get I/O access to '/dev/mem' fails. May the details provided be somehow useful to investigate what prevents it.

$ hostnamectl | sed -n '8p;12p' | awk '$1=$1'
Operating System: Fedora Linux 44 (Workstation Edition)
Kernel: Linux 7.1.7-200.fc44.x86_64

Parameters the kernel was compiled with that are relevant for this report:

$ grep _STRICT_DEVMEM /boot/config-$(uname -r)
CONFIG_STRICT_DEVMEM=y
CONFIG_IO_STRICT_DEVMEM=y

I learned that the main kernel configuration option for controlling I/O access to '/dev/mem' is 'CONFIG_STRICT_DEVMEM'. Lacking knowledge to recompile the kernel, thus my alternative was to add the parameter/key 'strict-devmem=0' to my kernel cmdline:

$ cat /etc/kernel/cmdline
root=UUID=(...) ro rootflags=subvol=root rhgb quiet strict-devmem=0

Test

$ sudo dd if=/dev/mem of=/dev/null
dd: error reading '/dev/mem': Operation not permitted
2048+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0943418 s, 11.1 MB/s

This program

$ file -b avml
ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, BuildID[sha1]=669c613fbe2bc57310816a6071922ee2203ed86f, stripped
$ stat avml | sed -n '3,4p'
Device: 0,53	Inode: 831989      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (1000/...)   Gid: (1000/...)

No permission correlated

$ ./avml acquire --source /dev/mem mem_dump
Error: error: unable to parse /proc/iomem
caused by:
    0: need CAP_SYS_ADMIN to read /proc/iomem

Expected!

$ sudo !!
sudo ./avml acquire --source /dev/mem mem_dump
Error: error: unable to read memory
caused by:
    0: unable to create memory snapshot from source: /dev/mem
    1: unable to create memory snapshot
    2: write block failed: 1048576..2483167231
    3: io error: unable to read memory page
    4: Operation not permitted (os error 1)

I cannot say whether the layout that is presented in 'cat /proc/iomem' represents what is readable within that limit. That seems to me out of topic though.

So, I thought I could expect that the operation would be at last permitted. Since it is not, it's still limited to the first megabyte, which is as expected on a recent Linux kernel. May I ask, do you happen to have a suggestion on this matter?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions