@lofty @eniko Loading a static PIE executable (no dynamic library dependencies) isn’t actually that much code
Conversation
Notices
-
Embed this notice
Erin 💽✨ (erincandescent@akko.erincandescent.net)'s status on Sunday, 22-Sep-2024 20:52:08 JST Erin 💽✨ - Haelwenn /элвэн/ :triskell: likes this.
-
Embed this notice
Eniko | Kitsune Tails out now! (eniko@peoplemaking.games)'s status on Sunday, 22-Sep-2024 20:52:05 JST Eniko | Kitsune Tails out now! @erincandescent @lofty i'm not really intimidated by reading binary formats, i'm intimidated by the lack of information on how to support running a PIE on a custom kernel >_> like i get the theory and i can parse a binary format but that doesn't mean i understand what a kernel needs to be able to successfully run a PIE
meanwhile there's lots of information available on MMUs. it looks like a pain in the ass to implement, but at least there's enough information out there that i understand what's required
Haelwenn /элвэн/ :triskell: likes this. -
Embed this notice
Erin 💽✨ (erincandescent@akko.erincandescent.net)'s status on Sunday, 22-Sep-2024 20:52:07 JST Erin 💽✨ @lofty @eniko Binary formats look intimidating but they are designed so you can basically dump them in RAM
-
Embed this notice
Erin 💽✨ (erincandescent@akko.erincandescent.net)'s status on Sunday, 22-Sep-2024 20:52:54 JST Erin 💽✨ @eniko @lofty For ELF PIE executables, take the highest value of ph.p_vaddr + ph.p_memsz from the PT_LOAD segments in the file
(This assumes that the PIE executable was linked at 0 but that’s the most common case; if it wasn’t, then subtract the lowest value of ph.p_vaddr from the previous)
Haelwenn /элвэн/ :triskell: likes this. -
Embed this notice
Eniko | Kitsune Tails out now! (eniko@peoplemaking.games)'s status on Sunday, 22-Sep-2024 20:52:55 JST Eniko | Kitsune Tails out now! @erincandescent @lofty how do you figure out how much memory to allocate for the executable? since without paging it has to all be in one contiguous block of memory
or are you just supposed to guess?
-
Embed this notice
Erin 💽✨ (erincandescent@akko.erincandescent.net)'s status on Sunday, 22-Sep-2024 20:52:56 JST Erin 💽✨ @eniko @lofty yeah, its not well documented from a “this is how you implement a loader” POV (I guess people expect that every loader you will ever need has been written…)
For ELF PIE its just
- Read the header
- Read the program headers, which tell you what to load (and at what relative offsets to each other)
- Find the relocation information (in REL or RELA formats) in the DYNamic table
- Apply said relocation information to the binary
- Jump to the entry point with whatever parameters you want setup