I was wondering if it was possible to restart a program (ignoring previously mapped files) with different argument by either calling main() or a glibc entry point function.

  • I think the problem is about initializing what is already initialized (like the stack or the heap) isn’t it? – user2284570 May 13 '17 at 20:04
  • 1
    It depends on what stage are you restarting. There would be issues with the program's internal constants, command parameters, all the threads that have been already spawn, all the allocated memory and etc... but technically you can do it, yes. – PhoeniX May 14 '17 at 4:45
  • @ph0sec my program doesn't spawn threads, however, it manage it's heap without glibc so that calling malloc can corrupt the heap. That's why I was thinking at restarting at an earlier entry point than point in order to allocate a new heap area. – user2284570 May 14 '17 at 10:17
  • are you planning to do fuzzing this way by any chance? – Igor Skochinsky May 15 '17 at 16:12
  • @IgorSkochinsky fuzz what? – user2284570 May 15 '17 at 16:13

Well, while it's definitely possible to jump to the entrypoint of the program to try restarting it, there may be various consequences preventing correct execution, e.g.:

  • library initialization has been run already, and running it a second time is not something most libraries expect
  • various resources may have been allocated and variables initialized, so doing it again may not work.

So what you can do is to cause the program to simulate termination without actually exiting and then jump to the entry point. Microsoft CRT provides functions _c_exit and _cexit for such cpurpose, but it seems glibc does not have anything similar. So you may have to simulate calling of the atexit handlers manually to perform cleanup.

| improve this answer | |
  • except in my case I can only call one function. – user2284570 May 16 '17 at 10:01
  • well, you can always just try and see if it works. If not, you'll need to figure out how to chain execution of multiple functions. – Igor Skochinsky May 16 '17 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.