Guest User

Untitled

a guest
Jan 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.30 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <sched.h>
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <signal.h>
  7. #include <linux/capability.h>
  8. #include <sys/mount.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11. #include <unistd.h>
  12.  
  13. int child(void *args)
  14. {
  15. printf("pid as seen in the child: %lu\n", (unsigned long)getpid());
  16.  
  17. pid_t p = mount("overlay", "./hatch/mnt", "overlay", 0, "lowerdir=./hatch/lower,upperdir=./hatch/upper,workdir=./hatch/work");
  18. if (p == -1){
  19. perror("mount");
  20. exit(1);
  21. }
  22.  
  23. // Expose the mount to the parent namespace
  24. p = mount("none", "./hatch/mnt", NULL, MS_SHARED, NULL);
  25. if (p == -1){
  26. perror("mount");
  27. exit(1);
  28. }
  29.  
  30. char *newargv[] = { "/bin/bash", NULL };
  31.  
  32. execv("/bin/bash", newargv);
  33. perror("exec");
  34. exit(EXIT_FAILURE);
  35.  
  36. return 0;
  37. }
  38. int main()
  39. {
  40. pid_t p = clone(child, malloc(4096) + 4096, CLONE_NEWNS | CLONE_NEWUSER | SIGCHLD, NULL);
  41. if (p == -1) {
  42. perror("clone");
  43. exit(1);
  44. }
  45.  
  46. printf("child pid: %lu\n", (unsigned long)p);
  47. waitpid(p, NULL, 0);
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment