Page 1 of 1
Is it possible to make ELF binaries work without paging?
Posted: Thu Dec 22, 2016 1:26 pm
by osdever
I've decided to get minimal ELF support in my OS. However I will make paging later, not today. I want to know can ELFs work without paging at all. Do you know that?
Re: Is it possible to make ELF binaries work without paging?
Posted: Thu Dec 22, 2016 1:49 pm
by alexfru
Sure, why not. But you may need to support some form of relocation, either the standard relocations in the executable or segments with nonzero bases.
Re: Is it possible to make ELF binaries work without paging?
Posted: Thu Dec 22, 2016 7:52 pm
by irvanherz
Maybe, you can start by generating executable as PIC. So, you can place it anywhere.
Re: Is it possible to make ELF binaries work without paging?
Posted: Sat Dec 24, 2016 12:51 pm
by bzt
Yes, you can. ELF are designed to store code and data for many systems; among them are ones without paging.
Make sure you use a proper address in your linker script (the one where you're going to load the ELF) and you won't need any position independent code at all.
Re: Is it possible to make ELF binaries work without paging?
Posted: Sat Dec 24, 2016 4:36 pm
by alexfru
bzt wrote:Make sure you use a proper address in your linker script (the one where you're going to load the ELF) and you won't need any position independent code at all.
How would you run two instances of a program? Or two different programs compiled with the same linker script?
Your options really are:
- PIC
- relocations (a bit complicated in ELF's compared with PE's or a.out's)
- separate address spaces (the OP doesn't have that yet)
- segmentation (will complicate things)
- swapping out the entire program in order to run another (inefficient, can't swap out until/unless all program's system calls completed or their results are buffered)
Re: Is it possible to make ELF binaries work without paging?
Posted: Sat Dec 24, 2016 6:18 pm
by Ch4ozz
PIC or relocating will work just fine.
I had both in my OS and relocating is worth implementing anyways for the sake of ASLR
Re: Is it possible to make ELF binaries work without paging?
Posted: Sun Dec 25, 2016 4:02 am
by bzt
Ch4ozz wrote:PIC or relocating will work just fine.
I had both in my OS and relocating is worth implementing anyways for the sake of ASLR
Well, maybe it's just me, but I think PIC in protected mode (at least the code gcc generates) is suboptimal. On the other hand in long mode is better, but there relocation has a significant overhead compared to protmode.
The second part, PIC worth it I couldn't agree more. But not only for the sake of ASLR
(Btw it's quite easy to bypass it, you'll only need one reference to a library from your code, and there you go (I mean you target a library which has a sechole but you don't know it's address. So you dynamically link your exploit with that library, and the run time linker will kindly put the randomized address in GOT for you. You read it, subtract it's relative position and you got the load address of the target library whatever that address is). I think the benefit that ASLR gives you does not compare to the effort and the overhead, you should protect your libraries a different way. But if you already have it, good for you!)
Re: Is it possible to make ELF binaries work without paging?
Posted: Sun Dec 25, 2016 4:05 am
by bzt
alexfru wrote:How would you run two instances of a program? Or two different programs compiled with the same linker script?
Your options really are:
- PIC
- relocations (a bit complicated in ELF's compared with PE's or a.out's)
- separate address spaces (the OP doesn't have that yet)
- segmentation (will complicate things)
- swapping out the entire program in order to run another (inefficient, can't swap out until/unless all program's system calls completed or their results are buffered)
You already answered your question
My point is, he can use ELF binaries without paging and PIC as a start. When it's working properly, he can go further (either with segmentation or paging or relocation or whatever he chooses).
Re: Is it possible to make ELF binaries work without paging?
Posted: Sun Dec 25, 2016 7:46 am
by osdever
alexfru wrote:bzt wrote:Make sure you use a proper address in your linker script (the one where you're going to load the ELF) and you won't need any position independent code at all.
How would you run two instances of a program?[/list]
I want to just properly run ELFs first.