When I debug my linux kernel module using gdb and qemu I get unconsistency results. When I put a breakpoint or disassemble my own fucntion, Sometimes I get "Cannot access memory at address: {function_address}" and sometimes I get the disassembled code
I have built an automation script which raises a linux vm using qemu. The script transfers my kernel module files to the vm, builds the kernel module and loads it. The script retrieves the loaded sections addresses from "/sys/module/{ko name}/sections/" ".text" ".bss" ".data" and then loads the ko file with the retrieved addresses of the sections to gdb.
I have to mention that I disable kaslr and compile the LKM with debug symbols.
Then I try to "disas" my own function and its fail sometimes.
Qemu cmdline: sudo qemu-system-x86_64 -enable-kvm -hda ~/ubuntu.qcow -m 4096 -kernel /boot/vmlinuz-5.0.0-23-generic -append "root=/dev/sda1 nokaslr" -net user,hostfwd=tcp::10022-:22 -net nic -snapshot -s
LKM symbols loading cmdline: add-symbol-file ${module_path} ${text} -s .data ${data} -s .bss ${bss}
I expect the output of "disas" command to be the disassembled code, but for example the actual result sometimes is: Dump of assembler code for function : 0xffffffffc0344000 <+0>: Cannot access memory at address 0xffffffffc0344000