Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <sched.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <linux/capability.h>
- #include <sys/mount.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- int child(void *args)
- {
- printf("pid as seen in the child: %lu\n", (unsigned long)getpid());
- pid_t p = mount("overlay", "./hatch/mnt", "overlay", 0, "lowerdir=./hatch/lower,upperdir=./hatch/upper,workdir=./hatch/work");
- if (p == -1){
- perror("mount");
- exit(1);
- }
- // Expose the mount to the parent namespace
- p = mount("none", "./hatch/mnt", NULL, MS_SHARED, NULL);
- if (p == -1){
- perror("mount");
- exit(1);
- }
- char *newargv[] = { "/bin/bash", NULL };
- execv("/bin/bash", newargv);
- perror("exec");
- exit(EXIT_FAILURE);
- return 0;
- }
- int main()
- {
- pid_t p = clone(child, malloc(4096) + 4096, CLONE_NEWNS | CLONE_NEWUSER | SIGCHLD, NULL);
- if (p == -1) {
- perror("clone");
- exit(1);
- }
- printf("child pid: %lu\n", (unsigned long)p);
- waitpid(p, NULL, 0);
- return 0;
- }
Add Comment
Please, Sign In to add comment