Page 1 of 1

Invalid memory access, from faulty ELF loader

Posted: Sun May 09, 2021 2:47 pm
by austanss
Note: I have been locked out of my account for months: I tried to reset my password and I forgot to click the link to activate the new password! Oh my am I a special case.

I have been attempting to write an ELF loader. I have written a simple little shell, dubbed "mnsh", and at first it was integrated into the kernel binary. Then, I shoved it into userspace and isolated it from the rest of the kernel. Now, I am attempting to load a separate executable via stivale modules and ELF loading. (The next step up is writing a proper FAT32 driver and a VFS, I'm a little stumped on that at the moment however and an ELF loader seemed to be the best option to work on at the moment.)

[ELF Loader Source Code: ... scheduling]
[MNSH Source Code: ... alpha/mnsh]

However, I printed the entry point address I am returning, and it seems to point to the correct code. However, when I actually do return the address, and call into it in the userspace entry, I page fault.
In particular, a faulty read that violated page protections during an instruction fetch for userspace code.

All the ELF headers/values seem to be correct, I've printed them out and objdump'd them a few times, just to cross-check. I originally believed that the loading executable was relocatable, but it is not: my memory has failed me.

So I am unsure if I lost the value in the long road from loading to executing, if the program segments are incorrectly loaded, or if I mapped the pages incorrectly.

Thank you in advance for your support.

Re: Invalid memory access, from faulty ELF loader

Posted: Sun May 09, 2021 3:07 pm
by austanss
Well all bugs come from simple mistakes.

I did indeed lose the value, from an incorrect asm statement.

mov rax, rdi
instead of
mov rdi, rax

I feel incredibly accomplished.