Is it possible to make ELF binaries work without paging?

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
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Is it possible to make ELF binaries work without paging?

Post 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?
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Is it possible to make ELF binaries work without paging?

Post 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.
irvanherz
Member
Member
Posts: 27
Joined: Mon Sep 19, 2016 5:34 am

Re: Is it possible to make ELF binaries work without paging?

Post by irvanherz »

Maybe, you can start by generating executable as PIC. So, you can place it anywhere.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Is it possible to make ELF binaries work without paging?

Post 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.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Is it possible to make ELF binaries work without paging?

Post 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)
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Is it possible to make ELF binaries work without paging?

Post 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 ;)
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Is it possible to make ELF binaries work without paging?

Post 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!)
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Is it possible to make ELF binaries work without paging?

Post 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).
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: Is it possible to make ELF binaries work without paging?

Post 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.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Post Reply