I am trying to implement a container, and for that I create a process using the clone(2) system call with the appropriate flags:

  if ((child_pid = clone(child_main, process_struct.Stack + process_struct.StackPtr,
  |SIGCHLD, &process_struct, checkpoint)) == -1){
     fprintf(stderr,"Failed...%m \n");

    waitpid(child_pid, NULL, 0);

inside child_main() I Change the host name for the process's namespace, also i set the mount namespace, I installed a Linux file system hierarchy on a partition like a normal Linux installation (I did that to create a clean file system image clean of my files and binaries) and then I set the propagation type to MS_UNBINDABLE, then I pivot_root(2) to change my process's root directory.

const int child_main(struct process *process_struct, int *checkpoint){

  char c;
  fprintf(stderr,"=> IPC setup...");
  //double check the IPC

  if ( sethostname(process_struct->Hostname, 
strlen(process_struct->Hostname)) || mounting(process_struct)){
    return -1;

  // startup the IPC pipes
  read(checkpoint[0], &c, 1);

  if(execve("/bin/bash", (char*)0, NULL) == -1 ){
    fprintf(stderr,"--> Launching process Failed %m\n");
    return -1;
    return 0;


The problem is that my system goes over the execve(2) and does not launch the /bin/bash and the program flows without errors. When I add system(2) statement before the execve(2) : system("ls"); it lists the appropriate file system and current working directory. Also when I change the execve(2) paramters to either: execve("/bin/ls", (char*)0, NULL) or execve("/bin/pstree", (char*)0, NULL) or any other parameter it will return an error of: No such file or directory or A NULL argv[0] was passed through an exec system call, also when I strace my program at the execve(2) system call it gives: NULL, 0, NULL) = 17992

update: the error has nothing to do with the file system image, I have performed more tests and are as the follwoing, I used for my mount namespaces my system's filesystem not the one I installed on a partition and running /bin/bash doesn't still work, I created a simple C program and compiled it, and it ran fine so there is something wrong that prevent bin/bash from being executed, to further test these results I reused for my mount namespaces the file system from my I moved the same executable to the file system first under "/" and second under the same path my main system path to the executable= /home/omar/docs/test.out my mounted file system from the partition path to the executable= /home/omar/docs/test.out since I wanted to check if the same path might have caused a confusion while adding to each executable a statment so can tell which path did my program take, and it worked fine without any problem and correctly as expected, so the problem is just that system essential commands will not work.

  • 1
    Are you sure it doesn’t launch it, and then bash exits immediately? – Stephen Kitt May 10 '19 at 13:28
  • yes, also the parent program resumes normally. – o.awajan May 10 '19 at 13:45
  • Oh, sorry, yes, execve would replace the program if it succeeded... – Stephen Kitt May 10 '19 at 13:46
  • 1
    What happens if you pass a valid argv array to execve? – Mark Plotnick May 10 '19 at 13:50
  • execve(2) will launch /bin/bash and replace the program, then it will exit immediately, as if the /bin/bash doesn't actually launch, in the question I specified what strace shows me at execve(2) which is ``` NULL, 0, NULL) = 17992``` – o.awajan May 10 '19 at 14:01

Your Answer

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

Browse other questions tagged or ask your own question.