direct-code-execution / ns-3-dce

Run real programs in the discrete time simulator ns3
http://www.nsnam.org/projects/direct-code-execution/
75 stars 46 forks source link

Replace vtable mangling with fopencookie #128

Open glance- opened 2 years ago

glance- commented 2 years ago

This replaces the vtable mangling with fopencookie instead. It works good enough for our use-cases, but there's still some TODO's in the code.

This is to fix https://github.com/direct-code-execution/ns-3-dce/issues/57

teto commented 2 years ago

Could you expand on your commit message what was the failure and how it solves it. Very cool PR.

ParthPratim commented 2 years ago

Thanks @glance- for the PR. I tried to implement a similar idea before and faced a few problems. Details about them can be found here : https://sourceware.org/pipermail/libc-alpha/2021-July/129432.html

I see that you fixed the dce_freopen() issue with a dce_fopen() call, and also remembering to update the cookie offset after a seek which fixed issues with ftell(). That was really great ! I was so stupid to have not notice it before. Applying those fixes made my branch pass as well. Thanks for that.

Also, I see you noticed the same issue with dce_fclose_unconditional() and dce_fclose_onexec(), which I've mentioned in the third point of the article above. Libc while flushing all streams hits a SIGSEGV due to a lack of an ns-3 simulation context in my_write.

I'm also not sure how important the stat callback is for DCE, but in the original vtable mangling implementation I could see a couple of calls to my_stat under gdb, which I did not with fopencookie, as we aren't allowed to map a callback to stat in fopencookie. Wouldn't this be a problem if host applications tried to make calls to the stat()?

Please let me know your views on these.

ParthPratim commented 2 years ago

I also tried to hack around a bit and check how would functions like execve behave when called in a simulation script. I tried to run this code, below compiled to an executable installed on a Node with the help of DceManager.

#include <stdio.h>
#include <unistd.h>

int main() {

  char* argv[] = { "iperf", "--help", NULL };
  char* envp[] = {  NULL };

  execve("/bin/iperf", argv, envp);

  return 0;
}

On the original vtable mangling implementation, I could see the iperf help output in the file-*/var/log/*/stderr logs, but with the fopencookie implementation, I could not see the iperf output in the stderr logs.

Sorry, I'm not sure how important or relevant would this test be, but I think it might show inconsistent outputs for different scripts.