Invalid memory access, from faulty ELF loader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
austanss
Member
Member
Posts: 374
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Invalid memory access, from faulty ELF loader

Post 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: https://github.com/rizet/micron/tree/wa ... scheduling]
[MNSH Source Code: https://github.com/rizet/micron/tree/wa ... 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.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
User avatar
austanss
Member
Member
Posts: 374
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: Invalid memory access, from faulty ELF loader

Post 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.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Post Reply