Greetings,
I'm doing some work on payloads, chaining, and returning from an elf image and have run into an 'interesting' problem.
Currently, when elfload sees that an image will overwrite LinuxBIOS, it moves everything (including the stack) up into high memory. So far, so good.
However, in the case where it will not overwrite, it leaves things alone. The problem comes in where the payload then loads an image over the stack. So, for example, LinuxBIOS loads payload at 0x1000-0x4000, payload loads image at 0x5000-0x10000 and BOOM.
The best bet is to have the first payload move the stack to the top of ram under the 4GB mark and somehow mark that memory as 'pre-boot reserved', meaning that bootloaders should leave it alone, but a final boot target such as Linux may use it after moving the stack.
The idea is to allow for chaining by having each stage reserve it's chunk of memory (including bounce buffer) at top of ram-reserved, then move reserved down. jmp_to_elf_entry then just worries about IP and leaves ESP and EBP alone.
Ideally, LinuxBIOS itself would create the stack high in the first place, but we are near the freeze, and the first stage payload can easily enough handle the ugliness and set a flag within baremetal to deal with this.
Any thoughts?
G'day, sjames
-- -------------------------steven james, director of research, linux labs ... ........ ..... .... 230 peachtree st nw ste 2701 the original linux labs atlanta.ga.us 30303 -since 1995 http://www.linuxlabs.com office 404.577.7747 fax 404.577.7743 -----------------------------------------------------------------------
What if there were and elf section for the stack? then elfboot would know to avoid that too.
ron
Greetings,
I'm not sure how that would work?!? The problem only happens when the first payload doesn't conflict with anything and the second one conflicts with the LinuxBIOS stack. By that time, the only thing the running code knows is where ESP was when it started (but not where the top of the stack is).
I did a test in bootselect where I just move the stack then. That plus a quick hack to the elf loader (the private copy in baremetal) to allocate the bounce buffer below the stack helps a lot.
G'day, sjames
On Fri, 2 May 2003, ron minnich wrote:
What if there were and elf section for the stack? then elfboot would know to avoid that too.
ron